xref: /MusicFree/src/pages/searchPage/store/atoms.ts (revision 410a159129b1f6a7a1f44fde7bfad9a46f91e161)
1import {RequestStateCode} from '@/constants/commonConst';
2import {atom} from 'jotai';
3
4/** 搜索状态 */
5
6export interface ISearchResult<T extends ICommon.SupportMediaType> {
7    /** 当前页码 */
8    page?: number;
9    /** 搜索词 */
10    query?: string;
11    /** 搜索状态 */
12    state: RequestStateCode;
13    /** 数据 */
14    data: ICommon.SupportMediaItemBase[T][];
15}
16
17type ISearchResults<
18    T extends keyof ICommon.SupportMediaItemBase = ICommon.SupportMediaType,
19> = {
20    [K in T]: Record<string, ISearchResult<K>>;
21};
22
23/** 初始值 */
24export const initSearchResults: ISearchResults = {
25    music: {},
26    album: {},
27    artist: {},
28    sheet: {},
29    lyric: {},
30};
31
32/** key: pluginhash value: searchResult */
33const searchResultsAtom = atom(initSearchResults);
34
35export enum PageStatus {
36    /** 编辑中 */
37    EDITING = 'EDITING',
38    /** 搜索中 */
39    SEARCHING = 'SEARCHING',
40    /** 有结果 */
41    RESULT = 'RESULT',
42    /** 没有安装插件 */
43    NO_PLUGIN = 'NO_PLUGIN',
44}
45
46/** 当前正在搜索的 */
47const pageStatusAtom = atom<PageStatus>(PageStatus.EDITING);
48
49const queryAtom = atom<string>('');
50
51export {pageStatusAtom, searchResultsAtom, queryAtom};
52