frontend is_starred and description support

This commit is contained in:
muerwre 2019-03-29 10:54:20 +07:00
parent a4b620471a
commit c040e33a8a
11 changed files with 103 additions and 26 deletions

View file

@ -1,5 +1,6 @@
import { ACTIONS } from '$redux/user/constants';
import { IUser } from "$constants/auth";
import { IRootState } from "$redux/user/reducer";
export const setUser = (user: IUser) => ({ type: ACTIONS.SET_USER, user });
export const userLogout = () => ({ type: ACTIONS.USER_LOGOUT });
@ -12,9 +13,11 @@ export const setRouterPoints = routerPoints => ({ type: ACTIONS.SET_ROUTER_POINT
export const setActiveSticker = activeSticker => ({ type: ACTIONS.SET_ACTIVE_STICKER, activeSticker });
export const setLogo = logo => ({ type: ACTIONS.SET_LOGO, logo });
export const setTitle = title => ({ type: ACTIONS.SET_TITLE, title });
export const setDescription = description => ({ type: ACTIONS.SET_DESCRIPTION, description });
export const setAddress = address => ({ type: ACTIONS.SET_ADDRESS, address });
export const setAddressOrigin = address_origin => ({ type: ACTIONS.SET_ADDRESS_ORIGIN, address_origin });
export const setPublic = is_public => ({ type: ACTIONS.SET_PUBLIC, is_public });
export const setStarred = is_starred => ({ type: ACTIONS.SET_STARRED, is_starred });
export const setSpeed = speed => ({ type: ACTIONS.SET_SPEED, speed });
export const startEditing = () => ({ type: ACTIONS.START_EDITING });
@ -28,7 +31,17 @@ export const clearStickers = () => ({ type: ACTIONS.CLEAR_STICKERS });
export const clearAll = () => ({ type: ACTIONS.CLEAR_ALL });
export const clearCancel = () => ({ type: ACTIONS.CLEAR_CANCEL });
export const sendSaveRequest = payload => ({ type: ACTIONS.SEND_SAVE_REQUEST, ...payload });
export const sendSaveRequest = (payload: {
title: IRootState['title'],
address: IRootState['address'],
is_public: IRootState['is_public'],
description: IRootState['description'],
force: boolean,
}) => ({
type: ACTIONS.SEND_SAVE_REQUEST,
...payload,
});
export const resetSaveDialog = () => ({ type: ACTIONS.RESET_SAVE_DIALOG });
export const setSaveLoading = save_loading => ({ type: ACTIONS.SET_SAVE_LOADING, save_loading });

View file

@ -17,6 +17,8 @@ export const ACTIONS: IActions = {
SET_ADDRESS: 'SET_ADDRESS',
SET_ADDRESS_ORIGIN: 'SET_ADDRESS_ORIGIN',
SET_PUBLIC: 'SET_PUBLIC',
SET_STARRED: 'SET_STARRED',
SET_DESCRIPTION: 'SET_DESCRIPTION',
START_EDITING: 'START_EDITING',
STOP_EDITING: 'STOP_EDITING',

View file

@ -26,6 +26,7 @@ export interface IRootReducer {
logo: keyof typeof LOGOS,
routerPoints: number,
distance: number,
description: string,
estimated: number,
speed: number,
activeSticker: { set?: keyof IStickers, sticker?: string },
@ -36,6 +37,7 @@ export interface IRootReducer {
provider: keyof typeof PROVIDERS,
markers_shown: boolean,
is_starred: boolean,
is_public: boolean,
is_empty: boolean,
is_routing: boolean,
@ -140,6 +142,11 @@ const setTitle: ActionHandler<typeof ActionCreators.setTitle> = (state, { title
title
});
const setDescription: ActionHandler<typeof ActionCreators.setDescription> = (state, { description }) => ({
...state,
description
});
const setAddress: ActionHandler<typeof ActionCreators.setAddress> = (state, { address }) => ({
...state,
address
@ -276,6 +283,8 @@ const searchSetLoading: ActionHandler<typeof ActionCreators.searchSetLoading> =
});
const setPublic: ActionHandler<typeof ActionCreators.setPublic> = (state, { is_public = false }) => ({ ...state, is_public });
const setStarred: ActionHandler<typeof ActionCreators.setStarred> = (state, { is_starred = false }) => ({ ...state, is_starred });
const setSpeed: ActionHandler<typeof ActionCreators.setSpeed> = (state, { speed = 15 }) => ({
...state,
speed,
@ -330,6 +339,7 @@ const HANDLERS = ({
[ACTIONS.SET_ACTIVE_STICKER]: setActiveSticker,
[ACTIONS.SET_LOGO]: setLogo,
[ACTIONS.SET_TITLE]: setTitle,
[ACTIONS.SET_DESCRIPTION]: setDescription,
[ACTIONS.SET_ADDRESS]: setAddress,
[ACTIONS.SET_ADDRESS_ORIGIN]: setAddressOrigin,
@ -356,6 +366,7 @@ const HANDLERS = ({
[ACTIONS.SEARCH_PUT_ROUTES]: searchPutRoutes,
[ACTIONS.SEARCH_SET_LOADING]: searchSetLoading,
[ACTIONS.SET_PUBLIC]: setPublic,
[ACTIONS.SET_STARRED]: setStarred,
[ACTIONS.SET_SPEED]: setSpeed,
[ACTIONS.SET_MARKERS_SHOWN]: setMarkersShown,
@ -376,6 +387,7 @@ export const INITIAL_STATE: IRootReducer = {
logo: DEFAULT_LOGO,
routerPoints: 0,
distance: 0,
description: '',
estimated: 0,
speed: 15,
activeSticker: { set: null, sticker: null },
@ -387,6 +399,8 @@ export const INITIAL_STATE: IRootReducer = {
markers_shown: true,
changed: false,
editing: false,
is_starred: false,
is_public: false,
is_empty: true,
is_routing: false,

View file

@ -307,7 +307,7 @@ function* clearSaga({ type }) {
}
function* sendSaveRequestSaga({
title, address, force, is_public
title, address, force, is_public, description,
}: ReturnType<typeof ActionCreators.sendSaveRequest>) {
if (editor.isEmpty) return yield put(setSaveError(TIPS.SAVE_EMPTY));
@ -319,7 +319,7 @@ function* sendSaveRequestSaga({
const { result, timeout, cancel } = yield race({
result: postMap({
id, token, route, stickers, title, force, address, logo, distance, provider, is_public
id, token, route, stickers, title, force, address, logo, distance, provider, is_public, description,
}),
timeout: delay(10000),
cancel: take(ACTIONS.RESET_SAVE_DIALOG),