1bf6e62f2S猫头猫import React, {useEffect, useState} from 'react'; 24060c00aS猫头猫import {ScrollView, StyleSheet, View} from 'react-native'; 3bf6e62f2S猫头猫import rpx from '@/utils/rpx'; 419dc08ecS猫头猫import Loading from '@/components/base/loading'; 54060c00aS猫头猫import {Chip} from 'react-native-paper'; 6bf6e62f2S猫头猫import useSearch from '../hooks/useSearch'; 7*4f168b1fS猫头猫import { 8*4f168b1fS猫头猫 addHistory, 9*4f168b1fS猫头猫 getHistory, 10*4f168b1fS猫头猫 removeAllHistory, 11*4f168b1fS猫头猫 removeHistory, 12*4f168b1fS猫头猫} from '../common/historySearch'; 13bf6e62f2S猫头猫import {useSetAtom} from 'jotai'; 14bf6e62f2S猫头猫import { 15a4ae8da5S猫头猫 initSearchResults, 16bf6e62f2S猫头猫 PageStatus, 17bf6e62f2S猫头猫 pageStatusAtom, 18bf6e62f2S猫头猫 queryAtom, 19bf6e62f2S猫头猫 searchResultsAtom, 20bf6e62f2S猫头猫} from '../store/atoms'; 2119dc08ecS猫头猫import ThemeText from '@/components/base/themeText'; 22*4f168b1fS猫头猫import Button from '@/components/base/button'; 23bf6e62f2S猫头猫 244060c00aS猫头猫export default function () { 25bf6e62f2S猫头猫 const [history, setHistory] = useState<string[] | null>(null); 26bf6e62f2S猫头猫 const search = useSearch(); 27bf6e62f2S猫头猫 28bf6e62f2S猫头猫 const setQuery = useSetAtom(queryAtom); 29bf6e62f2S猫头猫 const setPageStatus = useSetAtom(pageStatusAtom); 30bf6e62f2S猫头猫 const setSearchResultsState = useSetAtom(searchResultsAtom); 31bf6e62f2S猫头猫 32bf6e62f2S猫头猫 useEffect(() => { 3319c8eb6fS猫头猫 getHistory().then(setHistory); 34bf6e62f2S猫头猫 }, []); 35bf6e62f2S猫头猫 36bf6e62f2S猫头猫 return ( 37bf6e62f2S猫头猫 <View style={style.wrapper}> 38bf6e62f2S猫头猫 {history === null ? ( 394060c00aS猫头猫 <Loading /> 40bf6e62f2S猫头猫 ) : ( 41bf6e62f2S猫头猫 <> 42*4f168b1fS猫头猫 <View style={style.header}> 43*4f168b1fS猫头猫 <ThemeText fontSize="title" fontWeight="semibold"> 442fac4245S猫头猫 历史记录 452fac4245S猫头猫 </ThemeText> 46*4f168b1fS猫头猫 <Button 47*4f168b1fS猫头猫 fontColor="secondary" 48*4f168b1fS猫头猫 onPress={async () => { 49*4f168b1fS猫头猫 await removeAllHistory(); 50*4f168b1fS猫头猫 getHistory().then(setHistory); 51*4f168b1fS猫头猫 }}> 52*4f168b1fS猫头猫 清空 53*4f168b1fS猫头猫 </Button> 54*4f168b1fS猫头猫 </View> 552fac4245S猫头猫 <ScrollView 562fac4245S猫头猫 style={style.historyContent} 572fac4245S猫头猫 contentContainerStyle={style.historyContentConainer}> 58bf6e62f2S猫头猫 {history.map(_ => ( 59bf6e62f2S猫头猫 <Chip 60bf6e62f2S猫头猫 key={`search-history-${_}`} 61bf6e62f2S猫头猫 style={style.chip} 62bf6e62f2S猫头猫 onClose={async () => { 63bf6e62f2S猫头猫 await removeHistory(_); 64bf6e62f2S猫头猫 getHistory().then(setHistory); 65bf6e62f2S猫头猫 }} 66bf6e62f2S猫头猫 onPress={() => { 67a4ae8da5S猫头猫 setSearchResultsState(initSearchResults); 68c30d30e1S猫头猫 setPageStatus(PageStatus.SEARCHING); 690b940038S猫头猫 search(_, 1); 70bf6e62f2S猫头猫 addHistory(_); 71bf6e62f2S猫头猫 setQuery(_); 72bf6e62f2S猫头猫 }}> 73bf6e62f2S猫头猫 {_} 74bf6e62f2S猫头猫 </Chip> 75bf6e62f2S猫头猫 ))} 762fac4245S猫头猫 </ScrollView> 77bf6e62f2S猫头猫 </> 78bf6e62f2S猫头猫 )} 79bf6e62f2S猫头猫 </View> 80bf6e62f2S猫头猫 ); 81bf6e62f2S猫头猫} 82bf6e62f2S猫头猫 83bf6e62f2S猫头猫const style = StyleSheet.create({ 84bf6e62f2S猫头猫 wrapper: { 85bf6e62f2S猫头猫 width: rpx(750), 86bf6e62f2S猫头猫 maxWidth: rpx(750), 872fac4245S猫头猫 flexDirection: 'column', 88bf6e62f2S猫头猫 padding: rpx(24), 892fac4245S猫头猫 flex: 1, 90bf6e62f2S猫头猫 }, 91*4f168b1fS猫头猫 header: { 92bf6e62f2S猫头猫 width: '100%', 93*4f168b1fS猫头猫 flexDirection: 'row', 94*4f168b1fS猫头猫 paddingVertical: rpx(28), 95*4f168b1fS猫头猫 justifyContent: 'space-between', 96*4f168b1fS猫头猫 alignItems: 'center', 97bf6e62f2S猫头猫 }, 982fac4245S猫头猫 historyContent: { 992fac4245S猫头猫 width: rpx(750), 1002fac4245S猫头猫 flex: 1, 1012fac4245S猫头猫 }, 1022fac4245S猫头猫 historyContentConainer: { 1032fac4245S猫头猫 flexDirection: 'row', 1042fac4245S猫头猫 flexWrap: 'wrap', 1052fac4245S猫头猫 }, 106bf6e62f2S猫头猫 chip: { 107bf6e62f2S猫头猫 flexGrow: 0, 108bf6e62f2S猫头猫 marginRight: rpx(24), 109bf6e62f2S猫头猫 marginBottom: rpx(24), 110bf6e62f2S猫头猫 }, 111bf6e62f2S猫头猫}); 112