Skip to content

Commit 267e245

Browse files
authored
Merge pull request #1004 from GroophyLifefor/main
feat(tags): support multiple comma-separated tags in prompts filtering
2 parents f4547e1 + 4b326cf commit 267e245

File tree

6 files changed

+59
-34
lines changed

6 files changed

+59
-34
lines changed

src/app/api/prompts/route.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,17 @@ export async function GET(request: Request) {
335335
}
336336

337337
if (tag) {
338-
where.tags = {
339-
some: {
340-
tag: { slug: tag },
341-
},
342-
};
338+
// Handle multiple tags (comma-separated)
339+
const tagSlugs = tag.split(",").map(t => t.trim()).filter(Boolean);
340+
if (tagSlugs.length > 0) {
341+
where.AND = tagSlugs.map(slug => ({
342+
tags: {
343+
some: {
344+
tag: { slug },
345+
},
346+
},
347+
}));
348+
}
343349
}
344350

345351
if (q) {

src/app/prompts/page.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,21 @@ export default async function PromptsPage({ searchParams }: PromptsPageProps) {
242242
where.categoryId = params.category;
243243
}
244244

245+
// Handle tag parameter (can be comma-separated for multiple tags)
245246
if (params.tag) {
246-
where.tags = {
247-
some: {
248-
tag: {
249-
slug: params.tag,
247+
// Handle multiple tags (comma-separated)
248+
const tagSlugs = params.tag.split(",").map(t => t.trim()).filter(Boolean);
249+
if (tagSlugs.length > 0) {
250+
where.AND = tagSlugs.map(slug => ({
251+
tags: {
252+
some: {
253+
tag: {
254+
slug,
255+
},
256+
},
250257
},
251-
},
252-
};
258+
}));
259+
}
253260
}
254261

255262
// Build order by clause

src/components/prompts/infinite-prompt-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface InfinitePromptListProps {
2020
type?: string;
2121
category?: string;
2222
categorySlug?: string;
23-
tag?: string;
23+
tag?: string;
2424
sort?: string;
2525
};
2626
}

src/components/prompts/prompt-filters.tsx

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export function PromptFilters({ categories, tags, currentFilters, aiSearchEnable
8181
router.push("/prompts");
8282
};
8383

84+
const selectedTags = currentFilters.tag ? currentFilters.tag.split(",").filter(Boolean) : [];
85+
8486
const hasFilters = currentFilters.q || currentFilters.type || currentFilters.category || currentFilters.tag || currentFilters.sort;
8587

8688
const activeFilterCount = [currentFilters.type, currentFilters.category, currentFilters.tag, currentFilters.sort && currentFilters.sort !== "newest"].filter(Boolean).length;
@@ -318,25 +320,34 @@ export function PromptFilters({ categories, tags, currentFilters, aiSearchEnable
318320
/>
319321
</div>
320322
<div className="flex flex-wrap gap-1 max-h-48 overflow-y-auto">
321-
{filteredTags.filter((tag) => tag.id && tag.slug).map((tag) => (
322-
<button
323-
key={tag.id}
324-
className="px-2 py-0.5 text-[11px] rounded border transition-colors"
325-
style={
326-
currentFilters.tag === tag.slug
327-
? { backgroundColor: tag.color, color: "white", borderColor: tag.color }
328-
: { borderColor: tag.color + "40", color: tag.color }
329-
}
330-
onClick={() => {
331-
if (currentFilters.tag !== tag.slug) {
332-
analyticsSearch.filter("tag", tag.slug);
323+
{filteredTags.filter((tag) => tag.id && tag.slug).map((tag) => {
324+
const isSelected = selectedTags.includes(tag.slug);
325+
return (
326+
<button
327+
key={tag.id}
328+
className="px-2 py-0.5 text-[11px] rounded border transition-colors"
329+
style={
330+
isSelected
331+
? { backgroundColor: tag.color, color: "white", borderColor: tag.color }
332+
: { borderColor: tag.color + "40", color: tag.color }
333333
}
334-
updateFilter("tag", currentFilters.tag === tag.slug ? null : tag.slug);
335-
}}
336-
>
337-
{tag.name}
338-
</button>
339-
))}
334+
onClick={() => {
335+
let newTags: string[];
336+
if (isSelected) {
337+
// Remove tag
338+
newTags = selectedTags.filter(t => t !== tag.slug);
339+
} else {
340+
// Add tag
341+
newTags = [...selectedTags, tag.slug];
342+
analyticsSearch.filter("tag", tag.slug);
343+
}
344+
updateFilter("tag", newTags.length > 0 ? newTags.join(",") : null);
345+
}}
346+
>
347+
{tag.name}
348+
</button>
349+
);
350+
})}
340351
{filteredTags.length === 0 && tagSearch && (
341352
<span className="text-xs text-muted-foreground">{t("search.noResults")}</span>
342353
)}

src/lib/plugins/widgets/coderabbit.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ Provide your review in a clear, actionable format with specific line references
7676
}
7777

7878
// Inject when tag includes "code", "debug", "git"
79-
if (filters?.tag) {
80-
const tag = filters.tag.toLowerCase();
81-
if (tag.includes("code") || tag.includes("debug") || tag.includes("git")) {
79+
const tagParam = filters?.tag;
80+
if (tagParam) {
81+
const tagList = tagParam.toLowerCase();
82+
if (tagList.includes("code") || tagList.includes("debug") || tagList.includes("git")) {
8283
return true;
8384
}
8485
}

src/lib/plugins/widgets/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface WidgetContext {
1010
type?: string;
1111
category?: string;
1212
categorySlug?: string;
13-
tag?: string;
13+
tag?: string;
1414
sort?: string;
1515
};
1616
page?: number;

0 commit comments

Comments
 (0)