-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSystem.ts
More file actions
58 lines (46 loc) · 1.67 KB
/
System.ts
File metadata and controls
58 lines (46 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { observable } from 'mobx';
import { BiSearchModelClass } from 'mobx-lark';
import { BaseModel, DataObject, Filter, ListModel, toggle } from 'mobx-restful';
import { Constructor } from 'web-utility';
import { SearchActivityModel } from './Activity';
import { SearchAwardModel } from './Award';
import { ownClient } from './Base';
import { OrganizationModel } from './Organization';
import { SearchProjectModel } from './Project';
export type SearchableFilter<D extends DataObject> = Filter<D> & {
keywords?: string;
};
export type SearchModel<T extends DataObject = any> = ListModel<T, SearchableFilter<T>>;
export type SearchPageMeta = Pick<
InstanceType<BiSearchModelClass>,
'pageIndex' | 'currentPage' | 'pageCount'
>;
export type CityCoordinateMap = Record<string, [number, number]>;
export class SystemModel extends BaseModel {
searchMap = {
activity: SearchActivityModel,
project: SearchProjectModel,
award: SearchAwardModel,
NGO: OrganizationModel,
} as Record<string, Constructor<SearchModel<DataObject>>>;
@observable
accessor screenNarrow = false;
@observable
accessor cityCoordinate: CityCoordinateMap = {};
constructor() {
super();
this.updateScreen();
globalThis.addEventListener?.('resize', this.updateScreen);
}
updateScreen = () =>
(this.screenNarrow =
globalThis.innerWidth < globalThis.innerHeight || globalThis.innerWidth < 992);
@toggle('downloading')
async getCityCoordinate() {
const { body } = await ownClient.get<CityCoordinateMap>(
'https://idea2app.github.io/public-meta-data/china-city-coordinate.json',
);
return (this.cityCoordinate = body!);
}
}
export default new SystemModel();