mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 11:06:40 +07:00
starred content
This commit is contained in:
parent
a920217959
commit
baa41f707d
19 changed files with 159 additions and 22 deletions
|
@ -76,3 +76,5 @@ export const dropRoute = (_id: string) => ({ type: ACTIONS.DROP_ROUTE, _id });
|
|||
export const modifyRoute = (_id: string, { title, is_public }: { title: string, is_public: boolean }) => ({
|
||||
type: ACTIONS.MODIFY_ROUTE, _id, title, is_public
|
||||
});
|
||||
export const toggleRouteStarred = (_id: string) => ({ type: ACTIONS.TOGGLE_ROUTE_STARRED, _id });
|
||||
export const setRouteStarred = (_id: string, is_starred: boolean) => ({ type: ACTIONS.SET_ROUTE_STARRED, _id, is_starred });
|
||||
|
|
|
@ -81,4 +81,6 @@ export const ACTIONS: IActions = {
|
|||
|
||||
DROP_ROUTE: 'DROP_ROUTE',
|
||||
MODIFY_ROUTE: 'MODIFY_ROUTE',
|
||||
SET_ROUTE_STARRED: 'SET_ROUTE_STARRED',
|
||||
TOGGLE_ROUTE_STARRED: 'TOGGLE_ROUTE_STARRED',
|
||||
};
|
||||
|
|
|
@ -14,6 +14,7 @@ export interface IRouteListItem {
|
|||
title: string,
|
||||
distance: number,
|
||||
is_public: boolean,
|
||||
is_starred: boolean,
|
||||
updated_at: string,
|
||||
}
|
||||
|
||||
|
@ -304,6 +305,18 @@ const setIsRouting: ActionHandler<typeof ActionCreators.setIsRouting> = (state,
|
|||
is_routing,
|
||||
});
|
||||
|
||||
const setRouteStarred: ActionHandler<typeof ActionCreators.setRouteStarred> = (state, { _id, is_starred }) => ({
|
||||
...state,
|
||||
routes: {
|
||||
...state.routes,
|
||||
list: (
|
||||
state.routes.list
|
||||
.map(el => el._id === _id ? { ...el, is_starred } : el)
|
||||
.filter(el => state.routes.filter.tab !== 'starred' || el.is_starred)
|
||||
)
|
||||
}
|
||||
});
|
||||
|
||||
const HANDLERS = ({
|
||||
[ACTIONS.SET_USER]: setUser,
|
||||
[ACTIONS.SET_EDITING]: setEditing,
|
||||
|
@ -348,6 +361,8 @@ const HANDLERS = ({
|
|||
|
||||
[ACTIONS.SET_FEATURE]: setFeature,
|
||||
[ACTIONS.SET_IS_ROUTING]: setIsRouting,
|
||||
|
||||
[ACTIONS.SET_ROUTE_STARRED]: setRouteStarred,
|
||||
});
|
||||
|
||||
export const INITIAL_STATE: IRootReducer = {
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
checkUserToken, dropRoute,
|
||||
getGuestToken, getRouteList,
|
||||
getStoredMap, modifyRoute,
|
||||
postMap
|
||||
postMap, sendRouteStarred
|
||||
} from '$utils/api';
|
||||
import {
|
||||
hideRenderer,
|
||||
|
@ -32,7 +32,7 @@ import {
|
|||
setProvider,
|
||||
changeProvider,
|
||||
setSaveLoading,
|
||||
mapsSetShift, searchChangeDistance, clearAll, setFeature, searchSetTitle,
|
||||
mapsSetShift, searchChangeDistance, clearAll, setFeature, searchSetTitle, setRouteStarred,
|
||||
} from '$redux/user/actions';
|
||||
import { getUrlData, parseQuery, pushLoaderState, pushNetworkInitError, pushPath, replacePath } from '$utils/history';
|
||||
import { editor } from '$modules/Editor';
|
||||
|
@ -51,7 +51,7 @@ import {
|
|||
} from '$utils/renderer';
|
||||
import { ILogos, LOGOS } from '$constants/logos';
|
||||
import { DEFAULT_PROVIDER } from '$constants/providers';
|
||||
import { DIALOGS } from '$constants/dialogs';
|
||||
import { DIALOGS, TABS } from '$constants/dialogs';
|
||||
|
||||
import * as ActionCreators from '$redux/user/actions';
|
||||
import { IRootState } from "$redux/user/reducer";
|
||||
|
@ -501,7 +501,7 @@ function* searchGetRoutes() {
|
|||
|
||||
const { routes: { step, shift, filter: { title, distance, tab } } } = yield select(getState);
|
||||
|
||||
const result = yield call(getRouteList, {
|
||||
return yield call(getRouteList, {
|
||||
id,
|
||||
token,
|
||||
title,
|
||||
|
@ -509,10 +509,8 @@ function* searchGetRoutes() {
|
|||
step,
|
||||
shift,
|
||||
author: tab === 'mine' ? id : '',
|
||||
starred: tab === 'starred',
|
||||
starred: tab === 'starred' ? 1 : 0,
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function* searchSetSagaWorker() {
|
||||
|
@ -697,6 +695,17 @@ function* modifyRouteSaga({ _id, title, is_public }: ReturnType<typeof ActionCre
|
|||
return yield call(modifyRoute, { address: _id, id, token, title, is_public });
|
||||
}
|
||||
|
||||
function* toggleRouteStarredSaga({ _id }: ReturnType<typeof ActionCreators.toggleRouteStarred>) {
|
||||
const { routes: { list } } = yield select(getState);
|
||||
const route = list.find(el => el._id === _id);
|
||||
const { id, token } = yield select(getUser);
|
||||
|
||||
yield put(setRouteStarred(_id, !route.is_starred));
|
||||
const result = yield sendRouteStarred({ id, token, _id, is_starred: !route.is_starred });
|
||||
|
||||
if (!result) return yield put(setRouteStarred(_id, route.is_starred));
|
||||
}
|
||||
|
||||
export function* userSaga() {
|
||||
yield takeLatest(REHYDRATE, authCheckSaga);
|
||||
yield takeEvery(ACTIONS.SET_MODE, setModeSaga);
|
||||
|
@ -744,4 +753,5 @@ export function* userSaga() {
|
|||
|
||||
yield takeLatest(ACTIONS.DROP_ROUTE, dropRouteSaga);
|
||||
yield takeLatest(ACTIONS.MODIFY_ROUTE, modifyRouteSaga);
|
||||
yield takeLatest(ACTIONS.TOGGLE_ROUTE_STARRED, toggleRouteStarredSaga);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue