cleaned out user reducer

This commit is contained in:
Fedor Katurov 2020-01-08 14:25:46 +07:00
parent 103097edbd
commit af8d270460
13 changed files with 462 additions and 282 deletions

View file

@ -1,17 +1,32 @@
import { LatLng } from "leaflet";
import { LatLng } from 'leaflet';
import { IRoutePoint } from '$utils/gpx';
export type ILatLng = {
lat: number,
lng: number,
}
lat: number;
lng: number;
};
export type IMapRoute = ILatLng[];
export interface IStickerDump {
latlng: ILatLng,
set: string,
sticker: string,
angle?: number,
text?: string,
latlng: ILatLng;
set: string;
sticker: string;
angle?: number;
text?: string;
}
export interface IRoute {
version: number;
title: string;
owner: number;
address: string;
route: IRoutePoint[];
stickers: IStickerDump[];
provider: string;
is_public: boolean;
is_published: boolean;
description: string;
logo: string;
distance: number;
}

View file

@ -1,6 +1,7 @@
import { USER_ACTIONS } from '$redux/user/constants';
import { IUser } from "$constants/auth";
import { IRootState } from "$redux/user";
import { IRoute } from '$redux/map/types';
export const setUser = (user: IUser) => ({ type: USER_ACTIONS.SET_USER, user });
export const userLogout = () => ({ type: USER_ACTIONS.USER_LOGOUT });
@ -32,10 +33,10 @@ export const clearAll = () => ({ type: USER_ACTIONS.CLEAR_ALL });
export const clearCancel = () => ({ type: USER_ACTIONS.CLEAR_CANCEL });
export const sendSaveRequest = (payload: {
title: IRootState['title'],
address: IRootState['address'],
is_public: IRootState['is_public'],
description: IRootState['description'],
title: IRoute['title'],
address: IRoute['address'],
is_public: IRoute['is_public'],
description: IRoute['description'],
force: boolean,
}) => ({
type: USER_ACTIONS.SEND_SAVE_REQUEST,
@ -47,10 +48,10 @@ export const resetSaveDialog = () => ({ type: USER_ACTIONS.RESET_SAVE_DIALOG });
export const setSaveLoading = (save_loading: IRootState['save_loading']) => ({ type: USER_ACTIONS.SET_SAVE_LOADING, save_loading });
export const setSaveSuccess = (payload: {
address: IRootState['address'],
title: IRootState['address'],
is_public: IRootState['is_public'],
description: IRootState['description'],
address: IRoute['address'],
title: IRoute['address'],
is_public: IRoute['is_public'],
description: IRoute['description'],
save_error: string,
}) => ({ type: USER_ACTIONS.SET_SAVE_SUCCESS, ...payload });

View file

@ -1,29 +1,10 @@
import { createReducer } from 'reduxsauce';
import { DEFAULT_USER, IUser } from '$constants/auth';
import { MODES } from '$constants/modes';
import { DEFAULT_LOGO, LOGOS } from '$constants/logos';
import { DEFAULT_PROVIDER, PROVIDERS } from '$constants/providers';
import { DIALOGS, IDialogs, TABS } from '$constants/dialogs';
import { DIALOGS, IDialogs } from '$constants/dialogs';
import { IStickers } from "$constants/stickers";
import { IRoutePoint } from '$utils/gpx';
import { IStickerDump } from '$redux/map/types';
import { USER_HANDLERS } from './handlers';
export interface IRoute {
version: number,
title: IRootState['title'],
owner: number,
address: IRootState['address'],
route: IRoutePoint[],
stickers: IStickerDump[],
provider: IRootState['provider'],
is_public: IRootState['is_public'],
is_published: IRootState['is_published'],
description: IRootState['description'],
logo: IRootState['logo'],
distance: IRootState['distance']
}
export interface IRouteListItem {
address: string,
title: string,
@ -38,22 +19,22 @@ export interface IRootReducer {
user: IUser,
editing: boolean,
mode: typeof MODES[keyof typeof MODES],
logo: keyof typeof LOGOS,
// logo: keyof typeof LOGOS,
routerPoints: number,
distance: number,
description: string,
// description: string,
estimated: number,
speed: number,
activeSticker: { set?: keyof IStickers, sticker?: string },
title: string,
address: string,
address_origin: string,
// title: string,
// address: string,
// address_origin: string,
changed: boolean,
provider: keyof typeof PROVIDERS,
// provider: keyof typeof PROVIDERS,
markers_shown: boolean,
is_published: boolean,
is_public: boolean,
// is_public: boolean,
is_empty: boolean,
is_routing: boolean,
@ -104,24 +85,24 @@ export const INITIAL_STATE: IRootReducer = {
user: { ...DEFAULT_USER },
mode: MODES.NONE,
logo: DEFAULT_LOGO,
// logo: DEFAULT_LOGO,
routerPoints: 0,
distance: 0,
description: '',
// description: '',
estimated: 0,
speed: 15,
activeSticker: { set: null, sticker: null },
title: '',
address: '',
address_origin: '',
provider: DEFAULT_PROVIDER,
// title: '',
// address: '',
// address_origin: '',
// provider: DEFAULT_PROVIDER,
markers_shown: true,
changed: false,
editing: false,
is_published: false,
is_public: false,
// is_public: false,
is_empty: true,
is_routing: false,