reducers typescripting

This commit is contained in:
muerwre 2019-02-12 12:26:04 +07:00
parent 4c6526efc9
commit 85b8860862
15 changed files with 496 additions and 316 deletions

View file

@ -1,21 +0,0 @@
export const ROLES = {
guest: 'guest',
vk: 'vk',
};
export const DEFAULT_USER = {
new_messages: 0,
place_types: {},
random_url: '',
role: ROLES.guest,
routes: {},
success: false,
id: null,
token: null,
userdata: {
name: '',
agent: '',
ip: '',
photo: '',
}
};

45
src/constants/auth.ts Normal file
View file

@ -0,0 +1,45 @@
type valueof<T> = T[keyof T]
export interface IRoles {
guest: string,
vk: string,
}
export interface IUser {
new_messages: number,
place_types: {},
random_url: string,
role: IRoles[keyof IRoles],
routes: {},
success: boolean,
id?: string,
token?: string,
userdata: {
name: string,
agent: string,
ip: string,
photo: string,
}
}
export const ROLES: IRoles = {
guest: 'guest',
vk: 'vk',
};
export const DEFAULT_USER: IUser = {
new_messages: 0,
place_types: {},
random_url: '',
role: ROLES.guest,
routes: {},
success: false,
id: null,
token: null,
userdata: {
name: '',
agent: '',
ip: '',
photo: '',
}
};

View file

@ -1,12 +0,0 @@
// @flow
export const DIALOGS = ({
NONE: 'NONE',
MAP_LIST: 'MAP_LIST',
APP_INFO: 'APP_INFO',
}: { [key: String]: String });
export const TABS = ({
mine: 'Мои',
all: 'Общие',
// starred: 'Выбранные',
}: { [key: String]: String });

21
src/constants/dialogs.ts Normal file
View file

@ -0,0 +1,21 @@
export interface IDialogs {
NONE: string,
MAP_LIST: string,
APP_INFO: string,
}
export interface IMapTabs {
mine: string,
all: string,
}
export const DIALOGS: IDialogs = ({
NONE: 'NONE',
MAP_LIST: 'MAP_LIST',
APP_INFO: 'APP_INFO',
});
export const TABS: IMapTabs = ({
mine: 'Мои',
all: 'Общие',
});

View file

@ -1,3 +1,7 @@
export interface ILogos {
[x: string]: [string, string, string],
}
export const LOGOS = {
default: ['Без лого', null, 'bottom-right'],
nvs: ['НВС', require('../sprites/logos/lgo.png'), 'bottom-right'],

View file

@ -1,6 +1,8 @@
// @flow
export interface IModes {
[x: string]: string,
}
export const MODES = ({
export const MODES: IModes = {
POLY: 'POLY',
STICKERS: 'STICKERS',
STICKERS_SELECT: 'STICKERS_SELECT',
@ -12,6 +14,5 @@ export const MODES = ({
SAVE: 'SAVE',
CONFIRM_CANCEL: 'CONFIRM_CANCEL',
PROVIDER: 'PROVIDER',
SHOT_PREFETCH: 'SHOT_PREFETCH',
}: { [key: String]: String });
};

View file

@ -1,5 +1,24 @@
export interface IPRovider {
name: string,
url: string,
range: Array<string | number>,
}
export interface ITileMaps {
WATERCOLOR: IPRovider,
DGIS: IPRovider,
DEFAULT: IPRovider,
DARQ: IPRovider,
BLANK: IPRovider,
HOT: IPRovider,
YSAT: IPRovider,
YMAP: IPRovider,
SAT: IPRovider,
}
// Стили карт
const TILEMAPS = {
const TILEMAPS: ITileMaps = {
WATERCOLOR: {
name: 'Watercolor',
url: 'https://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.jpg',
@ -47,17 +66,19 @@ const TILEMAPS = {
},
};
const ENABLED = ['BLANK', 'DEFAULT', 'DGIS', 'HOT'];
const ENABLED: Array<keyof ITileMaps> = ['BLANK', 'DEFAULT', 'DGIS', 'HOT'];
export const DEFAULT_PROVIDER = ENABLED[0];
export const PROVIDERS = ENABLED.reduce((obj, provider) => ({
export const DEFAULT_PROVIDER: keyof ITileMaps = ENABLED[0];
export const PROVIDERS: Partial<ITileMaps> = ENABLED.reduce((obj, provider) => ({
...obj,
[provider]: TILEMAPS[provider],
}), {});
export const replaceProviderUrl = (provider, { x, y, zoom }) => {
const { url, range } = (PROVIDERS[provider] || PROVIDERS[DEFAULT_PROVIDER]);
const random = (range && range.length >= 2) ? range[Math.round((Math.random() * (range.length - 1)))] : 1;
const random: (number | string) = (range && range.length >= 2)
? range[Math.round((Math.random() * (range.length - 1)))]
: 1;
return url.replace('{x}', x).replace('{y}', y).replace('{z}', zoom).replace('{s}', random);
return url.replace('{x}', x).replace('{y}', y).replace('{z}', zoom).replace('{s}', String(random));
};

View file

@ -1,8 +1,28 @@
// Стикеры
// import L from "leaflet";
export interface ISticker {
off: number,
title: string,
title_long: string,
}
export interface IStickerPack {
title: string,
url: string,
size: number,
layers: {
[x: string]: ISticker,
}
}
export interface IStickers {
base: IStickerPack,
real: IStickerPack,
pin: IStickerPack,
}
// export const stickers = ['green', 'basic', 'green-small'];
export const STICKERS = {
export const STICKERS: IStickers = {
base: {
title: 'Простые',
url: require('$sprites/stickers/stickers-base.svg'),