feat(frontend): API client modules + backend GET /api/cards/:id
This commit is contained in:
15
packages/frontend/src/api/sessions.ts
Normal file
15
packages/frontend/src/api/sessions.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import type { QueueItem, SessionRow, SessionStartInput, AttemptCreateInput } from '@flashcard/shared';
|
||||
import { api } from './client.js';
|
||||
|
||||
export interface StartedSession { session: SessionRow; queue: QueueItem[]; }
|
||||
export interface SessionState { session: SessionRow; queue: QueueItem[]; index: number; }
|
||||
|
||||
export const sessionsApi = {
|
||||
start: (input: SessionStartInput) => api.post<StartedSession>('/sessions', input),
|
||||
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`),
|
||||
attempt: (id: number, input: AttemptCreateInput) => api.post<void>(`/sessions/${id}/attempts`, input),
|
||||
end: (id: number) => api.post<SessionRow>(`/sessions/${id}/end`),
|
||||
abandon: (id: number) => api.post<SessionRow>(`/sessions/${id}/abandon`),
|
||||
};
|
||||
Reference in New Issue
Block a user