mirror of
https://github.com/langgenius/dify.git
synced 2026-04-15 01:38:19 +08:00
fix app template list filtering
This commit is contained in:
parent
8e8c39a88c
commit
9d8f9f6f63
@ -42,7 +42,9 @@ const Apps = ({
|
||||
|
||||
const [currCategory, setCurrCategory] = useTabSearchParams({
|
||||
defaultTab: allCategoriesEn,
|
||||
disableSearchParams: pageType !== PageType.EXPLORE,
|
||||
})
|
||||
|
||||
const {
|
||||
data: { categories, allList },
|
||||
} = useSWR(
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import { usePathname, useRouter, useSearchParams } from 'next/navigation'
|
||||
import { useState } from 'react'
|
||||
|
||||
type UseTabSearchParamsOptions = {
|
||||
defaultTab: string
|
||||
routingBehavior?: 'push' | 'replace'
|
||||
searchParamName?: string
|
||||
disableSearchParams?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
@ -20,13 +22,20 @@ export const useTabSearchParams = ({
|
||||
defaultTab,
|
||||
routingBehavior = 'push',
|
||||
searchParamName = 'category',
|
||||
disableSearchParams = false,
|
||||
}: UseTabSearchParamsOptions) => {
|
||||
const router = useRouter()
|
||||
const pathName = usePathname()
|
||||
const searchParams = useSearchParams()
|
||||
const activeTab = searchParams.get(searchParamName) || defaultTab
|
||||
const [activeTab, setTab] = useState<string>(
|
||||
!disableSearchParams
|
||||
? (searchParams.get(searchParamName) || defaultTab)
|
||||
: defaultTab,
|
||||
)
|
||||
|
||||
const setActiveTab = (newActiveTab: string) => {
|
||||
if (disableSearchParams)
|
||||
return setTab(newActiveTab)
|
||||
router[routingBehavior](`${pathName}?${searchParamName}=${newActiveTab}`)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user