routes: backend endpoint

This commit is contained in:
muerwre 2018-12-12 17:32:08 +07:00
parent d11dd9043c
commit c69da00b2a
10 changed files with 106 additions and 15 deletions

View file

@ -51,3 +51,4 @@ export const keyPressed = ({ key }) => ({ type: ACTIONS.KEY_PRESSED, key });
export const searchSetTitle = title => ({ type: ACTIONS.SEARCH_SET_TITLE, title });
export const searchSetDistance = distance => ({ type: ACTIONS.SEARCH_SET_DISTANCE, distance });
export const searchSetTab = tab => ({ type: ACTIONS.SEARCH_SET_TAB, tab });
export const searchPutRoutes = list => ({ type: ACTIONS.SEARCH_PUT_ROUTES, list })

View file

@ -55,4 +55,5 @@ export const ACTIONS = ({
SEARCH_SET_DISTANCE: 'SEARCH_SET_DISTANCE',
SEARCH_SET_TAB: 'SEARCH_SET_TAB',
SEARCH_PUT_ROUTES: 'SEARCH_PUT_ROUTES',
}: { [key: String]: String });

View file

@ -128,6 +128,14 @@ const searchSetTab = (state, { tab = 'mine' }) => ({
}
});
const searchPutRoutes = (state, { list = [] }) => ({
...state,
routes: {
...state.routes,
list,
}
});
const HANDLERS = ({
[ACTIONS.SET_USER]: setUser,
[ACTIONS.SET_EDITING]: setEditing,
@ -159,13 +167,13 @@ const HANDLERS = ({
[ACTIONS.SEARCH_SET_TITLE]: searchSetTitle,
[ACTIONS.SEARCH_SET_DISTANCE]: searchSetDistance,
[ACTIONS.SEARCH_SET_TAB]: searchSetTab,
[ACTIONS.SEARCH_PUT_ROUTES]: searchPutRoutes,
}: { [key: String]: Function });
export const INITIAL_STATE = {
ready: false,
user: { ...DEFAULT_USER },
editing: false,
// mode: MODES.NONE,
mode: MODES.NONE,
logo: DEFAULT_LOGO,
routerPoints: 0,

View file

@ -4,12 +4,12 @@ import { takeLatest, select, call, put, takeEvery, race, take } from 'redux-saga
import {
checkIframeToken,
checkUserToken,
getGuestToken,
getGuestToken, getRouteList,
getStoredMap,
postMap
} from '$utils/api';
import {
hideRenderer,
hideRenderer, searchPutRoutes,
setActiveSticker, setAddress,
setChanged, setDialogActive,
setEditing,
@ -431,15 +431,24 @@ function* keyPressedSaga({ key }): void {
if (dialog_active) return yield put(setDialogActive(false));
if (mode !== MODES.NONE) return yield put(setMode(MODES.NONE));
}
return;
}
function* searchSetSaga() {
yield delay(500);
const { routes: { filter: { title, distance, tab }}} = yield select(getState);
const { id, token } = yield select(getUser);
console.log({ title, distance, tab });
yield delay(500);
const { routes: { filter: { title, distance, tab } } } = yield select(getState);
const list = yield call(getRouteList, {
id,
token,
title,
distance,
author: tab === 'mine' ? id : '',
starred: tab === 'starred',
});
yield put(searchPutRoutes(list));
}
export function* userSaga() {
@ -478,5 +487,5 @@ export function* userSaga() {
yield takeLatest([
ACTIONS.SEARCH_SET_TITLE,
ACTIONS.SEARCH_SET_DISTANCE,
], searchSetSaga)
], searchSetSaga);
}