routes: spinners

This commit is contained in:
muerwre 2018-12-13 17:24:18 +07:00
parent a27db14c65
commit b28803aff3
11 changed files with 216 additions and 76 deletions

View file

@ -41,6 +41,7 @@ export const setProvider = provider => ({ type: ACTIONS.SET_PROVIDER, provider }
export const setDialog = dialog => ({ type: ACTIONS.SET_DIALOG, dialog });
export const setDialogActive = dialog_active => ({ type: ACTIONS.SET_DIALOG_ACTIVE, dialog_active });
export const openMapDialog = tab => ({ type: ACTIONS.OPEN_MAP_DIALOG, tab });
export const locationChanged = location => ({ type: ACTIONS.LOCATION_CHANGED, location });
export const setReady = ready => ({ type: ACTIONS.SET_READY, ready });

View file

@ -57,4 +57,6 @@ export const ACTIONS = ({
SEARCH_SET_TAB: 'SEARCH_SET_TAB',
SEARCH_PUT_ROUTES: 'SEARCH_PUT_ROUTES',
SEARCH_SET_LOADING: 'SEARCH_SET_LOADING',
OPEN_MAP_DIALOG: 'OPEN_MAP_DIALOG',
}: { [key: String]: String });

View file

@ -6,7 +6,7 @@ import { MODES } from '$constants/modes';
import { DEFAULT_LOGO } from '$constants/logos';
import { TIPS } from '$constants/tips';
import { DEFAULT_PROVIDER } from '$constants/providers';
import { DIALOGS } from '$constants/dialogs';
import { DIALOGS, TABS } from '$constants/dialogs';
const getEstimated = distance => {
const time = (distance && (distance / 15)) || 0;
@ -117,28 +117,17 @@ const searchSetDistance = (state, { distance = [0, 9999] }) => ({
}
});
const searchSetTab = (state, { tab = 'mine' }) => ({
const searchSetTab = (state, { tab = TABS[Object.keys(TABS)[0]] }) => ({
...state,
routes: {
...state.routes,
filter: {
...state.routes.filter,
tab: ['mine', 'all', 'star'].indexOf(tab) >= 0 ? tab : 'mine',
tab: Object.keys(TABS).indexOf(tab) >= 0 ? tab : TABS[Object.keys(TABS)[0]],
}
}
});
const newDistCalc = ({
distance, min, max, filter
}) => {
if (filter.min === filter.max) {
// slider was disabled
return [min, max];
}
// state.routes.filter.distance
};
const searchPutRoutes = (state, { list = [], min, max }) => ({
...state,
routes: {
@ -218,8 +207,8 @@ export const INITIAL_STATE = {
save_overwriting: false,
save_processing: false,
dialog: DIALOGS.MAP_LIST,
dialog_active: true,
dialog: DIALOGS.NONE,
dialog_active: false,
renderer: {
data: '',
@ -237,11 +226,11 @@ export const INITIAL_STATE = {
filter: {
title: '',
starred: false,
distance: [0, 99999],
distance: [0, 10000],
author: '',
tab: 'mine',
min: 0,
max: 0,
max: 10000,
}
},
};

View file

@ -16,7 +16,8 @@ import {
setMode, setReady, setRenderer,
setSaveError,
setSaveOverwrite, setSaveSuccess, setTitle,
setUser
searchSetTab,
setUser, setDialog,
} from '$redux/user/actions';
import { getUrlData, parseQuery, pushLoaderState, pushNetworkInitError, pushPath, replacePath } from '$utils/history';
import { editor } from '$modules/Editor';
@ -34,6 +35,7 @@ import {
} from '$utils/renderer';
import { LOGOS } from '$constants/logos';
import { DEFAULT_PROVIDER } from '$constants/providers';
import { DIALOGS } from '$constants/dialogs';
const getUser = state => (state.user.user);
const getState = state => (state.user);
@ -433,10 +435,9 @@ function* keyPressedSaga({ key }): void {
}
}
function* searchSetSaga() {
function* searchSetSagaWorker() {
const { id, token } = yield select(getUser);
yield delay(1000);
yield put(searchSetLoading(true));
const { routes: { filter, filter: { title, distance, tab } } } = yield select(getState);
const { list, min, max } = yield call(getRouteList, {
@ -468,6 +469,33 @@ function* searchSetSaga() {
return yield put(searchSetLoading(false));
}
function* searchSetSaga() {
yield put(searchSetLoading(true));
yield delay(500);
yield call(searchSetSagaWorker);
}
function* openMapDialogSaga({ tab }) {
const { dialog_active, routes: { filter: { tab: current } } } = yield select(getState);
if (dialog_active && tab === current) {
return yield put(setDialogActive(false));
}
yield put(searchSetTab(tab));
yield put(setDialog(DIALOGS.MAP_LIST));
yield put(setDialogActive(true));
return tab;
}
function* searchSetTabSaga() {
yield put(searchSetDistance([0, 10000]));
yield put(searchPutRoutes({ list: [], min: 0, max: 10000 }));
yield call(searchSetSaga);
}
export function* userSaga() {
yield takeLatest(REHYDRATE, authCheckSaga);
yield takeEvery(ACTIONS.SET_MODE, setModeSaga);
@ -505,4 +533,7 @@ export function* userSaga() {
ACTIONS.SEARCH_SET_TITLE,
ACTIONS.SEARCH_SET_DISTANCE,
], searchSetSaga);
yield takeLatest(ACTIONS.OPEN_MAP_DIALOG, openMapDialogSaga);
yield takeLatest(ACTIONS.SEARCH_SET_TAB, searchSetTabSaga);
}