refactor: improve error handling and response structure for getThreads API function

This commit is contained in:
Thibault Pouch
2026-03-18 10:59:01 +01:00
parent e7d1cda356
commit bc9d93fe90
2 changed files with 17 additions and 5 deletions

View File

@@ -217,7 +217,7 @@ export default function ForumPage() {
{!loading && !error && ( {!loading && !error && (
filteredCategories.length === 0 ? ( filteredCategories.length === 0 ? (
<div className="crt-box" style={{ padding: '2rem', textAlign: 'center', color: 'var(--color-text-muted)', fontFamily: 'var(--font-mono)' }}> <div className="crt-box" style={{ padding: '2rem', textAlign: 'center', color: 'var(--color-text-muted)', fontFamily: 'var(--font-mono)' }}>
No results found for "{search}" {search.trim() ? `No results found for "${search}"` : 'No forum categories available yet.'}
</div> </div>
) : ( ) : (
filteredCategories.map((cat) => ( filteredCategories.map((cat) => (

View File

@@ -114,14 +114,26 @@ export const forumApi = {
getCategories: () => getCategories: () =>
apiFetch<ForumCategory[]>('/forum/categories'), apiFetch<ForumCategory[]>('/forum/categories'),
getThreads: (params?: { categoryId?: string; page?: number; limit?: number }) => { getThreads: async (params?: { categoryId?: string; page?: number; limit?: number }) => {
const q = new URLSearchParams(); const q = new URLSearchParams();
if (params?.categoryId) q.set('categoryId', params.categoryId); if (params?.categoryId) q.set('categoryId', params.categoryId);
q.set('page', String(params?.page ?? 1)); q.set('page', String(params?.page ?? 1));
q.set('limit', String(params?.limit ?? 100)); q.set('limit', String(params?.limit ?? 100));
return apiFetch<{ data: ForumThread[]; total: number; page: number; pages: number }>(
`/forum/threads?${q}` const result = await apiFetch<{
); data?: ForumThread[];
threads?: ForumThread[];
total: number;
page: number;
pages: number;
}>(`/forum/threads?${q}`);
return {
data: result.data ?? result.threads ?? [],
total: result.total,
page: result.page,
pages: result.pages,
};
}, },
getThread: (id: string) => getThread: (id: string) =>