feat(frontend): API clients for search + stats extensions + due session
This commit is contained in:
28
packages/frontend/src/api/search.ts
Normal file
28
packages/frontend/src/api/search.ts
Normal 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}`),
|
||||
};
|
||||
@@ -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`),
|
||||
|
||||
@@ -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`),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user