|
4 | 4 | SearchOutlined,
|
5 | 5 | NumberOutlined,
|
6 | 6 | ProfileOutlined,
|
| 7 | + ClearOutlined, |
7 | 8 | } from '@ant-design/icons'
|
8 | 9 | import { useNavigate } from 'react-router-dom'
|
9 | 10 | import { useAllPagesOutlines } from 'vite-plugin-react-pages/client'
|
@@ -69,8 +70,20 @@ const renderSearchResultItem = (
|
69 | 70 | throw new Error('unexpected SearchResultItem: type ' + type)
|
70 | 71 | }
|
71 | 72 |
|
72 |
| -const calcRecentSearchesOptions = (recentSearches: SearchResultItem[]) => { |
73 |
| - const label = <p>Recent</p> |
| 73 | +const calcRecentSearchesOptions = ( |
| 74 | + recentSearches: SearchResultItem[], |
| 75 | + clearAllHistory: () => void |
| 76 | +) => { |
| 77 | + const len = recentSearches.length |
| 78 | + |
| 79 | + const label = ( |
| 80 | + <p className={s.recentSearchesLabel}> |
| 81 | + <div className={s.recentSearchesLabelText}> |
| 82 | + {len ? 'Recent' : 'No recent searches'} |
| 83 | + </div> |
| 84 | + {len ? <ClearOutlined onClick={clearAllHistory} /> : null} |
| 85 | + </p> |
| 86 | + ) |
74 | 87 |
|
75 | 88 | const options = recentSearches.map((item) => {
|
76 | 89 | const { type, page, matechedString } = item
|
@@ -110,8 +123,13 @@ const Search: React.FC<React.PropsWithChildren<Props>> = (props) => {
|
110 | 123 |
|
111 | 124 | const allPagesOutlines = useAllPagesOutlines(2000)?.allPagesOutlines
|
112 | 125 |
|
| 126 | + const clearAllHistory = () => { |
| 127 | + setRecentSearches([]) |
| 128 | + localStorage.setItem(recentSearchesKey, JSON.stringify([])) |
| 129 | + } |
| 130 | + |
113 | 131 | const recentSearchesOptions = useMemo(
|
114 |
| - () => calcRecentSearchesOptions(recentSearches), |
| 132 | + () => calcRecentSearchesOptions(recentSearches, clearAllHistory), |
115 | 133 | [recentSearches]
|
116 | 134 | )
|
117 | 135 |
|
|
0 commit comments