11import { watchDebounced } from '@vueuse/core'
22import type { Hit } from 'algoliasearch/dist/lite/browser'
33import { memoize , orderBy } from 'lodash'
4- import { computed , onUnmounted , ref , watch } from 'vue'
4+ import { computed , ref , watch } from 'vue'
55
66import { useAlgoliaSearchService } from '@/services/algoliaSearchService'
77import type {
@@ -14,7 +14,6 @@ import { SortableAlgoliaField } from '@/types/comfyManagerTypes'
1414const SEARCH_DEBOUNCE_TIME = 320
1515const DEFAULT_PAGE_SIZE = 64
1616const DEFAULT_SORT_FIELD = SortableAlgoliaField . Downloads // Set in the index configuration
17- const DEFAULT_MAX_CACHE_SIZE = 64
1817const SORT_DIRECTIONS : Record < SortableAlgoliaField , 'asc' | 'desc' > = {
1918 [ SortableAlgoliaField . Downloads ] : 'desc' ,
2019 [ SortableAlgoliaField . Created ] : 'desc' ,
@@ -30,18 +29,25 @@ const isDateField = (field: SortableAlgoliaField): boolean =>
3029/**
3130 * Composable for managing UI state of Comfy Node Registry search.
3231 */
33- export function useRegistrySearch (
34- options : {
35- maxCacheSize ?: number
36- } = { }
37- ) {
38- const { maxCacheSize = DEFAULT_MAX_CACHE_SIZE } = options
32+ export function useRegistrySearch ( options : {
33+ initialSortField ?: SortableAlgoliaField
34+ initialSearchMode ?: 'nodes' | 'packs'
35+ initialSearchQuery ?: string
36+ initialPageNumber ?: number
37+ } ) {
38+ const {
39+ initialSortField = SortableAlgoliaField . Downloads ,
40+ initialSearchMode = 'packs' ,
41+ initialSearchQuery = '' ,
42+ initialPageNumber = 0
43+ } = options
44+
3945 const isLoading = ref ( false )
40- const sortField = ref < SortableAlgoliaField > ( SortableAlgoliaField . Downloads )
41- const searchMode = ref < 'nodes' | 'packs' > ( 'packs' )
46+ const sortField = ref < SortableAlgoliaField > ( initialSortField )
47+ const searchMode = ref < 'nodes' | 'packs' > ( initialSearchMode )
4248 const pageSize = ref ( DEFAULT_PAGE_SIZE )
43- const pageNumber = ref ( 0 )
44- const searchQuery = ref ( '' )
49+ const pageNumber = ref ( initialPageNumber )
50+ const searchQuery = ref ( initialSearchQuery )
4551 const results = ref < AlgoliaNodePack [ ] > ( [ ] )
4652 const suggestions = ref < NodesIndexSuggestion [ ] > ( [ ] )
4753
@@ -62,9 +68,7 @@ export function useRegistrySearch(
6268 )
6369
6470 const { searchPacksCached, toRegistryPack, clearSearchPacksCache } =
65- useAlgoliaSearchService ( {
66- maxCacheSize
67- } )
71+ useAlgoliaSearchService ( )
6872
6973 const algoliaToRegistry = memoize (
7074 toRegistryPack ,
@@ -124,8 +128,6 @@ export function useRegistrySearch(
124128 immediate : true
125129 } )
126130
127- onUnmounted ( clearSearchPacksCache )
128-
129131 return {
130132 isLoading,
131133 pageNumber,
@@ -135,6 +137,7 @@ export function useRegistrySearch(
135137 searchQuery,
136138 suggestions,
137139 searchResults : resultsAsRegistryPacks ,
138- nodeSearchResults : resultsAsNodes
140+ nodeSearchResults : resultsAsNodes ,
141+ clearCache : clearSearchPacksCache
139142 }
140143}
0 commit comments