@@ -62,18 +62,50 @@ type Props = {
62
62
autoFocus ?: boolean ;
63
63
path ?: string ;
64
64
searchPlatforms ?: string [ ] ;
65
+ showChatBot ?: boolean ;
66
+ useStoredSearchPlatforms ?: boolean ;
65
67
} ;
66
68
67
- export function Search ( { path, autoFocus, searchPlatforms = [ ] } : Props ) {
69
+ const STORAGE_KEY = 'sentry-docs-search-platforms' ;
70
+
71
+ export function Search ( {
72
+ path,
73
+ autoFocus,
74
+ searchPlatforms = [ ] ,
75
+ useStoredSearchPlatforms = true ,
76
+ } : Props ) {
68
77
const ref = useRef < HTMLDivElement > ( null ) ;
69
78
const [ query , setQuery ] = useState ( `` ) ;
70
79
const [ results , setResults ] = useState ( [ ] as Result [ ] ) ;
71
80
const [ inputFocus , setInputFocus ] = useState ( false ) ;
72
81
const [ showOffsiteResults , setShowOffsiteResults ] = useState ( false ) ;
73
82
const [ loading , setLoading ] = useState ( true ) ;
74
-
83
+ const [ currentSearchPlatforms , setCurrentSearchPlatforms ] = useState ( searchPlatforms ) ;
75
84
const pathname = usePathname ( ) ;
76
85
86
+ // Load stored platforms on mount
87
+ useEffect ( ( ) => {
88
+ const storedPlatforms = localStorage . getItem ( STORAGE_KEY ) ?? '[]' ;
89
+ if ( ! storedPlatforms ) {
90
+ localStorage . setItem ( STORAGE_KEY , JSON . stringify ( searchPlatforms ) ) ;
91
+ } else if (
92
+ storedPlatforms &&
93
+ searchPlatforms . length === 0 &&
94
+ useStoredSearchPlatforms
95
+ ) {
96
+ const platforms = JSON . parse ( storedPlatforms ) ;
97
+ setCurrentSearchPlatforms ( platforms ) ;
98
+ }
99
+ } , [ useStoredSearchPlatforms , searchPlatforms ] ) ;
100
+
101
+ // Update stored platforms when they change
102
+ useEffect ( ( ) => {
103
+ if ( searchPlatforms . length > 0 ) {
104
+ localStorage . setItem ( STORAGE_KEY , JSON . stringify ( searchPlatforms ) ) ;
105
+ setCurrentSearchPlatforms ( searchPlatforms ) ;
106
+ }
107
+ } , [ searchPlatforms ] ) ;
108
+
77
109
const handleClickOutside = useCallback ( ( ev : MouseEvent ) => {
78
110
// don't close the search results if the user is clicking the expand button
79
111
if (
@@ -143,7 +175,7 @@ export function Search({path, autoFocus, searchPlatforms = []}: Props) {
143
175
inputQuery ,
144
176
{
145
177
path,
146
- platforms : searchPlatforms . map (
178
+ platforms : currentSearchPlatforms . map (
147
179
platform => standardSDKSlug ( platform ) ?. slug ?? ''
148
180
) ,
149
181
searchAllIndexes : showOffsiteResults ,
@@ -163,7 +195,7 @@ export function Search({path, autoFocus, searchPlatforms = []}: Props) {
163
195
setResults ( queryResults ) ;
164
196
}
165
197
} ,
166
- [ path , searchPlatforms , showOffsiteResults , loading ]
198
+ [ path , currentSearchPlatforms , showOffsiteResults , loading ]
167
199
) ;
168
200
169
201
const totalHits = results . reduce ( ( a , x ) => a + x . hits . length , 0 ) ;
0 commit comments