xref: /MusicFree/src/pages/searchPage/index.tsx (revision bf6e62f27bf21a011995d7561e0093fae1a2d72e)
1import React, {useEffect} from 'react';
2import {StyleSheet, Text, View} from 'react-native';
3import rpx from '@/utils/rpx';
4import NavBar from './components/navBar';
5import {useAtom, useAtomValue, useSetAtom} from 'jotai';
6import {PageStatus, pageStatusAtom, queryAtom, searchResultsAtom} from './store/atoms';
7import HistoryPanel from './components/historyPanel';
8import ResultPanel from './components/resultPanel';
9import MusicBar from '@/components/musicBar';
10import Loading from '@/components/loading';
11
12interface IProps {}
13export default function (props: IProps) {
14  const [pageStatus, setPageStatus] = useAtom(pageStatusAtom);
15  const setQuery = useSetAtom(queryAtom);
16  const setSearchResultsState = useSetAtom(searchResultsAtom);
17  useEffect(() => {
18    setSearchResultsState({});
19    return () => {
20      setPageStatus(PageStatus.EDITING);
21      setQuery('');
22    };
23  }, []);
24
25  useEffect(() => {
26    console.log(pageStatus);
27  }, [pageStatus]);
28
29  return (
30    <View style={style.wrapper}>
31      <NavBar></NavBar>
32      <View style={{flex: 1}}>
33        {pageStatus === PageStatus.EDITING && <HistoryPanel></HistoryPanel>}
34        {pageStatus === PageStatus.SEARCHING && <Loading></Loading>}
35        {pageStatus === PageStatus.RESULT && <ResultPanel></ResultPanel>}
36      </View>
37      <MusicBar></MusicBar>
38    </View>
39  );
40}
41
42const style = StyleSheet.create({
43  wrapper: {
44    width: rpx(750),
45    flex: 1,
46  },
47});
48