refactor(components): Move setFilterPending call to handleCategoryClick and handleClearFilter in PinnedCategories
This commit is contained in:
@@ -261,16 +261,15 @@ export default async function PromptsPage({ searchParams }: PromptsPageProps) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Suspense fallback={null}>
|
||||
<div className="mb-4">
|
||||
<PinnedCategories
|
||||
categories={pinnedCategories}
|
||||
currentCategoryId={params.category}
|
||||
/>
|
||||
</div>
|
||||
</Suspense>
|
||||
|
||||
<FilterProvider>
|
||||
<Suspense fallback={null}>
|
||||
<div className="mb-4">
|
||||
<PinnedCategories
|
||||
categories={pinnedCategories}
|
||||
currentCategoryId={params.category}
|
||||
/>
|
||||
</div>
|
||||
</Suspense>
|
||||
<div className="flex flex-col lg:flex-row gap-6">
|
||||
<aside className="w-full lg:w-56 shrink-0 lg:sticky lg:top-16 lg:self-start lg:max-h-[calc(100vh-5rem)] lg:overflow-y-auto">
|
||||
<PromptFilters
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useFilterContext } from "@/components/prompts/filter-context";
|
||||
|
||||
interface PinnedCategory {
|
||||
id: string;
|
||||
@@ -20,12 +21,14 @@ export function PinnedCategories({ categories, currentCategoryId }: PinnedCatego
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const t = useTranslations("categories");
|
||||
const { setFilterPending } = useFilterContext();
|
||||
|
||||
if (categories.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const handleCategoryClick = (categoryId: string) => {
|
||||
setFilterPending(true);
|
||||
const params = new URLSearchParams(searchParams?.toString() ?? "");
|
||||
|
||||
if (currentCategoryId === categoryId) {
|
||||
@@ -40,6 +43,7 @@ export function PinnedCategories({ categories, currentCategoryId }: PinnedCatego
|
||||
};
|
||||
|
||||
const handleClearFilter = () => {
|
||||
setFilterPending(true);
|
||||
const params = new URLSearchParams(searchParams?.toString() ?? "");
|
||||
params.delete("category");
|
||||
params.delete("page");
|
||||
|
||||
Reference in New Issue
Block a user