diff --git a/backend/src/api/user.ts b/backend/src/api/user.ts index 47723f7..2219ca1 100644 --- a/backend/src/api/user.ts +++ b/backend/src/api/user.ts @@ -31,6 +31,14 @@ userRouter.get("/logout", async (req, res) => { }); }); +// TODO: This should be shared with the frontend, to remove code duplication +export enum VocabType { + NOMEN = 0, + VERB = 1, + ADJEKTIV = 2, + ADVERB = 3, +}; + // Gets the user's review queue userRouter.get("/queue", async (req, res) => { console.log("STUB: /user/queue"); @@ -38,7 +46,19 @@ userRouter.get("/queue", async (req, res) => { // TODO: Stub res.send({ error: "0", - data: {}, + data: { + queue: [{ + german: ["Wein"], + hint: "Worte auf '-um' sind meistens NeutrUM", + type: VocabType.NOMEN, + latin: { + grundform: "Vinum", + genitiv: "Vini", + genus: "Neutrum" + }, + id: 0 + }] + }, }); }); diff --git a/frontend/src/components/app.tsx b/frontend/src/components/app.tsx index 53937c4..3ea6277 100644 --- a/frontend/src/components/app.tsx +++ b/frontend/src/components/app.tsx @@ -82,67 +82,36 @@ export default class Application extends React.Component { } setLastReview = (meta: IReviewMetadata) => { - console.log("STUB: Application::setLastReview"); - - // TODO: Send this to the server - /* this.setState({ - * lastReview: meta, - * }); */ - } - - getReviewQueue = (): Promise => { - console.log("STUB: Application::getReviewQueue"); - - // TODO: Implement - return new Promise((res, rej) => { - setTimeout(() => { - res([ - { - german: ["Wein"], - hint: "Worte auf '-um' sind meistens NeutrUM", - type: VocabType.NOMEN, - latin: { - grundform: "Vinum", - genitiv: "Vini", - genus: "Neutrum" - }, - id: 0 - }/* , { - * latin: "Vici", - * german: "", - * hint: "Wird \"Viki\" und nicht \"Vichi\" ausgesprochen", - * mnemonic: "Merk dir das Wort mit Caesars berühmten Worten: \"Veni Vidi Vici\"; Er kam, sah und siegte", - * type: VocabType.NOMEN, - * id: 2 - }, { - * latin: "fuga", - * german: "Flucht", - * hint: "Worte auf \"-a\" sind FeminA", - * type: VocabType.NOMEN, - * id: 3 - } */ - ]); - }, 2000); + fetch(`${BACKEND_URL}/api/user/lastReview`, { + headers: new Headers({ + "Content-Type": "application/json", + "Token": this.props.user.sessionToken, + }), + method: "POST", + body: JSON.stringify({ + meta, + }), + }).then(resp => resp.json(), err => { + console.log("Application::setLastReview: POSTing last results failed"); }); } - getLearners(): ILearner[] { - console.log("STUB: Application::getLearners"); - - // TODO: Implement - return [{ - username: "Polynomdivision", - level: 5, - score: 400, - }, { - username: "Polynomdivision2", - level: 3, - score: 500, - }, { - username: "Der eine Typ", - level: 7, - score: 100, - }]; + getReviewQueue = (): Promise => { + return new Promise((res, rej) => { + fetch(`${BACKEND_URL}/api/user/queue`, { + headers: new Headers({ + "Content-Type": "application/json", + "Token": this.props.user.sessionToken, + }), + }).then(resp => resp.json(), err => rej(err)) + .then(data => { + if (data.error === "0") { + res(data.data.queue); + } else { + rej(data); + } + }); + }); } getTopTenLearners = (): Promise => { diff --git a/frontend/src/models/vocab.ts b/frontend/src/models/vocab.ts index 1975b29..3e12e85 100644 --- a/frontend/src/models/vocab.ts +++ b/frontend/src/models/vocab.ts @@ -4,10 +4,10 @@ export enum ReviewMode { }; export enum VocabType { - NOMEN, - VERB, - ADJEKTIV, - ADVERB + NOMEN = 0, + VERB = 1, + ADJEKTIV = 2, + ADVERB = 3, }; export interface INomenData {