mirror of
https://github.com/modrinth/code.git
synced 2026-08-25 09:04:55 +00:00
feat: project page header when visiting from browse (#6630)
* feat: project page header when visiting from browse * fix: lint
This commit is contained in:
@@ -25,6 +25,7 @@ export interface UseBrowseSearchOptions {
|
||||
}>
|
||||
providedFilters?: ComputedRef<FilterValue[]>
|
||||
environmentOverride?: ComputedRef<EnvironmentSearchOverride | undefined>
|
||||
active?: ComputedRef<boolean>
|
||||
search: (params: string) => Promise<BrowseSearchResponse>
|
||||
persistentQueryParams: string[]
|
||||
getExtraQueryParams?: () => Record<string, string | undefined>
|
||||
@@ -74,6 +75,7 @@ export function useBrowseSearch(options: UseBrowseSearchOptions): BrowseSearchSt
|
||||
|
||||
debug('init, projectType:', options.projectType.value)
|
||||
|
||||
const active = computed(() => options.active?.value ?? true)
|
||||
const projectTypes = computed(() => [options.projectType.value] as ProjectType[])
|
||||
const isServerType = computed(() => options.projectType.value === 'server')
|
||||
|
||||
@@ -184,6 +186,13 @@ export function useBrowseSearch(options: UseBrowseSearchOptions): BrowseSearchSt
|
||||
let searchVersion = 0
|
||||
let searchDebounceTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
function clearSearchDebounce() {
|
||||
if (searchDebounceTimer) {
|
||||
clearTimeout(searchDebounceTimer)
|
||||
searchDebounceTimer = null
|
||||
}
|
||||
}
|
||||
|
||||
const providedFiltersOrEmpty = computed(() => options.providedFilters?.value ?? [])
|
||||
|
||||
watch(
|
||||
@@ -209,13 +218,27 @@ export function useBrowseSearch(options: UseBrowseSearchOptions): BrowseSearchSt
|
||||
from: oldVal?.substring(0, 80),
|
||||
to: newVal?.substring(0, 80),
|
||||
})
|
||||
if (searchDebounceTimer) clearTimeout(searchDebounceTimer)
|
||||
clearSearchDebounce()
|
||||
if (!active.value) {
|
||||
return
|
||||
}
|
||||
searchDebounceTimer = setTimeout(() => {
|
||||
refreshSearch()
|
||||
}, 200)
|
||||
})
|
||||
|
||||
watch(active, (isActive, wasActive) => {
|
||||
clearSearchDebounce()
|
||||
if (isActive && wasActive === false) {
|
||||
void refreshSearch()
|
||||
}
|
||||
})
|
||||
|
||||
async function refreshSearch() {
|
||||
if (!active.value) {
|
||||
return
|
||||
}
|
||||
|
||||
const version = ++searchVersion
|
||||
debug('refreshSearch start', {
|
||||
version,
|
||||
@@ -233,6 +256,10 @@ export function useBrowseSearch(options: UseBrowseSearchOptions): BrowseSearchSt
|
||||
try {
|
||||
const response = await options.search(effectiveRequestParams.value)
|
||||
|
||||
if (!active.value) {
|
||||
return
|
||||
}
|
||||
|
||||
if (version !== searchVersion) {
|
||||
debug('refreshSearch stale, discarding', { version, current: searchVersion })
|
||||
return
|
||||
@@ -263,6 +290,10 @@ export function useBrowseSearch(options: UseBrowseSearchOptions): BrowseSearchSt
|
||||
}
|
||||
|
||||
function updateUrlParams() {
|
||||
if (!active.value) {
|
||||
return
|
||||
}
|
||||
|
||||
debug('updateUrlParams', { path: route.path })
|
||||
const persistentParams: Record<string, string | (string | null)[] | null | undefined> = {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user