Implement Task 16: Murphy Grammar Engine & Handwritten Journaling
This commit is contained in:
@@ -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}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user