Implement Task 16: Murphy Grammar Engine & Handwritten Journaling

This commit is contained in:
Antigravity committed 2026-10-06 15:42:10 +03:00
1 parent 3fae321322
commit 4d58002b48
11 files changed
+3267 -10

No files matched your search

+52
View File
@@ -248,5 +248,57 @@ export const api = {
if (resp.ok) return await resp.json();
throw new Error(`Failed to reset level: ${resp.status}`);
}
},
// Murphy Grammar Engine & Handwritten Journaling (Task 16)
grammar: {
async getUnits() {
const resp = await fetch('/api/grammar/units');
if (resp.ok) return await resp.json();
throw new Error(`Failed to load grammar units: ${resp.status}`);
},
async getUnit(id) {
const resp = await fetch(`/api/grammar/units/${id}`);
if (resp.ok) return await resp.json();
throw new Error(`Failed to load grammar unit ${id}: ${resp.status}`);
},
async submitAnswer(unitId, exerciseIdx, selectedOption) {
const resp = await fetch('/api/grammar/answer', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
unit_id: unitId,
exercise_idx: exerciseIdx,
selected_option: selectedOption
})
});
if (resp.ok) return await resp.json();
throw new Error(`Failed to submit grammar answer: ${resp.status}`);
},
async completeUnit(unitId, score, handwrittenLogged = false) {
const resp = await fetch('/api/grammar/complete', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
unit_id: unitId,
score: score,
handwritten_logged: handwrittenLogged
})
});
if (resp.ok) return await resp.json();
throw new Error(`Failed to complete unit: ${resp.status}`);
},
async toggleHandwritten(unitId, handwritten) {
const resp = await fetch('/api/grammar/handwritten', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
unit_id: unitId,
handwritten: handwritten
})
});
if (resp.ok) return await resp.json();
throw new Error(`Failed to update handwritten status: ${resp.status}`);
}
}
};