@@ -73,7 +73,7 @@ export const useSearchStore = defineStore(SearchStoreConstants.Store, () => {
73
73
const history = ref < Set < string > > ( new Set ( ) ) ;
74
74
75
75
const saveHistory = debounce ( ( ) => storage . local . set ( SearchStoreConstants . LocalHistory , [ ...history . value ] ) , 1000 ) ;
76
- const saveSearch = debounce ( ( ) => storage . local . set ( SearchStoreConstants . LocalLast , { value : search . value , date : Date . now ( ) } ) , 1000 ) ;
76
+ const saveSearch = debounce ( ( ) => storage . local . set ( SearchStoreConstants . LocalLast , { value : search . value , date : Date . now ( ) } ) , 200 ) ;
77
77
78
78
const addToHistory = debounce ( ( value : string = search . value ) => {
79
79
if ( ! value || value . trim ( ) . length < minSearchLength ) return ;
@@ -136,12 +136,12 @@ export const useSearchStore = defineStore(SearchStoreConstants.Store, () => {
136
136
const loadingPlaceholder = useLoadingPlaceholder < SearchResult > ( pageSize ) ;
137
137
138
138
const { isAuthenticated } = useAuthSettingsStoreRefs ( ) ;
139
- const fetchSearchResults = async ( { page, limit = pageSize . value } : { page ?: number ; limit ?: number } = { } ) => {
139
+ const fetchSearchResults = async ( { page, limit = pageSize . value } : { page ?: number ; limit ?: number } = { } , _search = search . value ?. trim ( ) ) => {
140
140
if ( ! isAuthenticated . value ) {
141
141
Logger . error ( 'Cannot fetch search results, user is not authenticated' ) ;
142
142
return ;
143
143
}
144
- if ( ! search . value ?. trim ( ) ) {
144
+ if ( ! _search ) {
145
145
pagination . value = { } ;
146
146
searchResults . value = [ ] ;
147
147
return ;
@@ -152,14 +152,14 @@ export const useSearchStore = defineStore(SearchStoreConstants.Store, () => {
152
152
}
153
153
if ( firstLoad . value ) firstLoad . value = false ;
154
154
155
- Logger . debug ( 'Fetching search results' , { types : types . value , query : query . value , search : search . value } ) ;
155
+ Logger . debug ( 'Fetching search results' , { types : types . value , query : query . value , search : _search } ) ;
156
156
157
157
loading . value = true ;
158
158
const { clearLoading } = debounceLoading ( searchResults , loadingPlaceholder , { clear : ! page } ) ;
159
159
const request : TraktSearch = {
160
160
type : types . value ,
161
161
escape : ! query . value ,
162
- query : search . value ,
162
+ query : _search ,
163
163
pagination : { page, limit } ,
164
164
} ;
165
165
try {
@@ -191,7 +191,7 @@ export const useSearchStore = defineStore(SearchStoreConstants.Store, () => {
191
191
watch ( search , async ( ) => {
192
192
if ( ! search . value || search . value . length < minSearchLength ) return ;
193
193
await fetchSearchResults ( ) ;
194
- addToHistory ( ) . catch ( e => Logger . error ( 'Failed to save search history ' , e ) ) ;
194
+ saveSearch ( ) . catch ( e => Logger . error ( 'Failed to save search' , e ) ) ;
195
195
} ) ;
196
196
197
197
watch ( [ pageSize , types ] , async ( ) => {
0 commit comments