-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathArtistSongsStore.ts
74 lines (65 loc) · 2.25 KB
/
ArtistSongsStore.ts
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import SongRepository from '@Repositories/SongRepository';
import UserRepository from '@Repositories/UserRepository';
import GlobalValues from '@Shared/GlobalValues';
import UrlMapper from '@Shared/UrlMapper';
import PVPlayersFactory from '@Stores/PVs/PVPlayersFactory';
import CommonSearchStore from '@Stores/Search/CommonSearchStore';
import SongSearchStore, { SongSortRule } from '@Stores/Search/SongSearchStore';
import { StoreWithPagination } from '@vocadb/route-sphere';
import Ajv, { JSONSchemaType } from 'ajv';
export interface ArtistSongsRouteParams {
page?: number;
pageSize?: number;
sort?: SongSortRule;
viewMode?: 'Details' | 'PlayList' /* TODO: enum */;
}
// TODO: Use single Ajv instance. See https://ajv.js.org/guide/managing-schemas.html.
const ajv = new Ajv({ coerceTypes: true });
// TODO: Make sure that we compile schemas only once and re-use compiled validation functions. See https://ajv.js.org/guide/getting-started.html.
const schema: JSONSchemaType<ArtistSongsRouteParams> = require('./ArtistSongsRouteParams.schema');
const validate = ajv.compile(schema);
export default class ArtistSongsStore
extends SongSearchStore
implements StoreWithPagination<ArtistSongsRouteParams> {
public constructor(
values: GlobalValues,
urlMapper: UrlMapper,
songRepo: SongRepository,
userRepo: UserRepository,
pvPlayersFactory: PVPlayersFactory,
) {
super(
new CommonSearchStore(values, undefined!),
values,
urlMapper,
songRepo,
userRepo,
undefined!,
undefined!,
pvPlayersFactory,
);
}
public popState = false;
public readonly clearResultsByQueryKeys: (keyof ArtistSongsRouteParams)[] = [
'pageSize',
'sort',
'viewMode',
];
public get routeParams(): ArtistSongsRouteParams {
return {
page: this.paging.page,
pageSize: this.paging.pageSize,
sort: this.sort,
viewMode: this.viewMode,
};
}
public set routeParams(value: ArtistSongsRouteParams) {
this.paging.page = value.page ?? 1;
this.paging.pageSize = value.pageSize ?? 10;
this.sort = value.sort ?? SongSortRule.Name;
this.viewMode = value.viewMode ?? 'Details';
}
public validateRouteParams = (data: any): data is ArtistSongsRouteParams => {
return validate(data);
};
}