feat(frontend): API clients for search + stats extensions + due session

This commit is contained in:
2026-05-21 07:02:57 +02:00
parent 65dcd185b8
commit ab382a2c62
3 changed files with 34 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
import { api } from './client.js';
export interface SearchLessonResult {
id: number;
name: string;
ownerDisplayName: string;
location: 'library' | 'marketplace';
totalCards: number;
isCurated: boolean;
}
export interface SearchCardResult {
id: number;
lessonId: number;
lessonName: string;
question: string;
snippet: string;
}
export interface SearchResult {
lessons: SearchLessonResult[];
cards: SearchCardResult[];
}
export const searchApi = {
search: (q: string, limit = 30) =>
api.get<SearchResult>(`/search?q=${encodeURIComponent(q)}&limit=${limit}`),
};

View File

@@ -6,6 +6,7 @@ export interface SessionState { session: SessionRow; queue: QueueItem[]; index:
export const sessionsApi = {
start: (input: SessionStartInput) => api.post<StartedSession>('/sessions', input),
startDue: () => api.post<StartedSession>(`/sessions/due`),
active: () => api.get<SessionRow | null>('/sessions/active'),
state: (id: number) => api.get<SessionState>(`/sessions/${id}`),
next: (id: number) => api.get<{ done: true } | { done: false; item: QueueItem }>(`/sessions/${id}/next`),

View File

@@ -20,4 +20,9 @@ export const statsApi = {
lesson: (id: number) => api.get<LessonStats>(`/stats/lessons/${id}`),
card: (id: number) => api.get<CardStats>(`/stats/cards/${id}`),
heatmap: (weeks = 12) => api.get<{ day: string; sessions: number; attempts: number }[]>(`/stats/heatmap?weeks=${weeks}`),
lessonsProgress: () => api.get<{ rows: Array<{
lessonId: number; name: string; totalCards: number; masteredCards: number;
scorePct: number; lastSessionAt: number | null;
}> }>(`/stats/lessons-progress`),
due: () => api.get<{ overdue: number; today: number; tomorrow: number; thisWeek: number }>(`/stats/due`),
};