Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | 1x 1x 1x 1x 1x 1x 1x 3x 3x 2x 2x 1x 2x 2x 1x 2x 2x 1x | // Backend access for LegacyHomePage.tsx and its private components ONLY.
// Every endpoint here lives under /api/legacy/, a frozen copy of the backend
// contract, so the non-legacy endpoints can evolve without touching the legacy
// page. Do not consolidate this with the useBackend-based data access used by
// ConceptGraphPage, and do not import this module outside the LegacyHomePage tree.
const API_BASE = "/api/legacy";
export interface Assessment {
id: string;
pl_assessment_id: string;
name: string;
}
export interface Question {
id: string;
assessment_id: string;
pl_question_uuid: string;
title: string;
}
export interface QuestionConcept {
id: string;
question_id: string;
concept_id: string;
subconcept_label: string | null;
}
export async function fetchAssessments(): Promise<Assessment[]> {
const res = await fetch(`${API_BASE}/assessments`);
return res.json();
}
export async function fetchQuestions(
assessmentId: string,
): Promise<Question[]> {
const res = await fetch(`${API_BASE}/assessments/${assessmentId}/questions`);
return res.json();
}
export async function fetchQuestionConcepts(
questionId: string,
): Promise<QuestionConcept[]> {
const res = await fetch(`${API_BASE}/questions/${questionId}/concepts`);
return res.json();
}
export interface LegacyUserStateResponse {
starred_ids: string[];
detail_cards: unknown[];
mastered_subconcepts: string[];
}
export async function fetchLegacyUserState(
userid: number,
): Promise<LegacyUserStateResponse | null> {
const res = await fetch(`${API_BASE}/user-state/${userid}`);
if (res.status === 404) return null;
if (!res.ok)
throw new Error(`Failed to fetch user state for userid ${userid}`);
return res.json();
}
export async function saveLegacyUserState(body: {
userid: number;
starred_ids: string[];
detail_cards: unknown[];
mastered_subconcepts: string[];
}): Promise<void> {
const res = await fetch(`${API_BASE}/user-state`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
if (!res.ok)
throw new Error(`Failed to save user state for userid ${body.userid}`);
}
export async function logLegacyUserActivity(body: {
userid: number;
event_type: string;
payload: object;
}): Promise<void> {
const res = await fetch(`${API_BASE}/user-activity`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
if (!res.ok)
throw new Error(`Failed to log user activity for userid ${body.userid}`);
}
|