xref: /MusicFree/src/pages/searchPage/store/atoms.ts (revision 6704747af84cebd842b258efac7143542722fac5)
1import { RequestStateCode } from '@/constants/commonConst';
2import {atom} from 'jotai';
3
4/** 搜索状态 */
5
6
7export interface ISearchResult<T extends ICommon.SupportMediaType> {
8  /** 当前页码 */
9  page?: number;
10  /** 搜索词 */
11  query?: string;
12  /** 搜索状态 */
13  state: RequestStateCode;
14  /** 数据 */
15  data: ICommon.SupportMediaItemBase[T][];
16}
17
18type ISearchResults<
19  T extends keyof ICommon.SupportMediaItemBase = ICommon.SupportMediaType,
20> = {
21  [K in T]: Record<string, ISearchResult<K>>;
22};
23
24/** 初始值 */
25export const initSearchResults: ISearchResults = {
26  music: {},
27  album: {},
28  artist: {},
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
44/** 当前正在搜索的 */
45const pageStatusAtom = atom<PageStatus>(PageStatus.EDITING);
46
47const queryAtom = atom<string>('');
48
49export {pageStatusAtom, searchResultsAtom, queryAtom};
50