Fix Tag Filtering
This commit is contained in:
@@ -11,15 +11,17 @@ interface TagFilterProps {
|
||||
export default function TagFilter({ tags, selectedTags, onTagToggle }: TagFilterProps) {
|
||||
if (!Array.isArray(tags) || tags.length === 0) return null;
|
||||
|
||||
// Sort tags by usage count (descending) and then alphabetically
|
||||
const sortedTags = [...tags].sort((a, b) => {
|
||||
const aCount = a.storyCount || 0;
|
||||
const bCount = b.storyCount || 0;
|
||||
if (bCount !== aCount) {
|
||||
return bCount - aCount;
|
||||
}
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
// Filter out tags with no stories, then sort by usage count (descending) and then alphabetically
|
||||
const sortedTags = [...tags]
|
||||
.filter(tag => (tag.storyCount || 0) > 0)
|
||||
.sort((a, b) => {
|
||||
const aCount = a.storyCount || 0;
|
||||
const bCount = b.storyCount || 0;
|
||||
if (bCount !== aCount) {
|
||||
return bCount - aCount;
|
||||
}
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
|
||||
@@ -268,7 +268,27 @@ export const searchApi = {
|
||||
sortBy?: string;
|
||||
sortDir?: string;
|
||||
}): Promise<SearchResult> => {
|
||||
const response = await api.get('/stories/search', { params });
|
||||
// Create URLSearchParams to properly handle array parameters
|
||||
const searchParams = new URLSearchParams();
|
||||
|
||||
// Add basic parameters
|
||||
searchParams.append('query', params.query);
|
||||
if (params.page !== undefined) searchParams.append('page', params.page.toString());
|
||||
if (params.size !== undefined) searchParams.append('size', params.size.toString());
|
||||
if (params.minRating !== undefined) searchParams.append('minRating', params.minRating.toString());
|
||||
if (params.maxRating !== undefined) searchParams.append('maxRating', params.maxRating.toString());
|
||||
if (params.sortBy) searchParams.append('sortBy', params.sortBy);
|
||||
if (params.sortDir) searchParams.append('sortDir', params.sortDir);
|
||||
|
||||
// Add array parameters - each element gets its own parameter
|
||||
if (params.authors && params.authors.length > 0) {
|
||||
params.authors.forEach(author => searchParams.append('authors', author));
|
||||
}
|
||||
if (params.tags && params.tags.length > 0) {
|
||||
params.tags.forEach(tag => searchParams.append('tags', tag));
|
||||
}
|
||||
|
||||
const response = await api.get(`/stories/search?${searchParams.toString()}`);
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user