xref: /MusicFree/src/pages/searchPage/store/atoms.ts (revision 2aa881935ca35b8fb1abc4206e0dc35149231456)
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    // lyric: {}
29};
30
31/** key: pluginhash value: searchResult */
32const searchResultsAtom = atom(initSearchResults);
33
34export enum PageStatus {
35    /** 编辑中 */
36    EDITING = 'EDITING',
37    /** 搜索中 */
38    SEARCHING = 'SEARCHING',
39    /** 有结果 */
40    RESULT = 'RESULT',
41    /** 没有安装插件 */
42    NO_PLUGIN = 'NO_PLUGIN',
43}
44
45/** 当前正在搜索的 */
46const pageStatusAtom = atom<PageStatus>(PageStatus.EDITING);
47
48const queryAtom = atom<string>('');
49
50export {pageStatusAtom, searchResultsAtom, queryAtom};
51