Fix for Random Story Function

This commit is contained in:
Stefan Hardegger
2025-08-14 13:14:46 +02:00
parent 4357351ec8
commit 1d14d3d7aa
5 changed files with 128 additions and 5 deletions

View File

@@ -198,7 +198,17 @@ export const storyApi = {
tags?: string[];
}): Promise<Story | null> => {
try {
const response = await api.get('/stories/random', { params: filters });
// Create URLSearchParams to properly handle array parameters like tags
const searchParams = new URLSearchParams();
if (filters?.searchQuery) {
searchParams.append('searchQuery', filters.searchQuery);
}
if (filters?.tags && filters.tags.length > 0) {
filters.tags.forEach(tag => searchParams.append('tags', tag));
}
const response = await api.get(`/stories/random?${searchParams.toString()}`);
return response.data;
} catch (error: any) {
if (error.response?.status === 204) {