xref: /MusicFree/src/pages/searchPage/store/atoms.ts (revision b882a19d884fffa32f7c8cef31652b909dceaa0f)
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
43/** 当前正在搜索的 */
44const pageStatusAtom = atom<PageStatus>(PageStatus.EDITING);
45
46const queryAtom = atom<string>('');
47
48export {pageStatusAtom, searchResultsAtom, queryAtom};
49