Fix for Random Story Function
This commit is contained in:
@@ -169,8 +169,8 @@ export default function LibraryPage() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Navigate to the random story's reading page
|
||||
router.push(`/stories/${randomStory.id}/read`);
|
||||
// Navigate to the random story's detail page
|
||||
router.push(`/stories/${randomStory.id}`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to get random story:', error);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user