feat: Implement all Frontend stubs

This commit is contained in:
Alexander Polynomdivision 2018-09-24 13:53:20 +02:00
parent 8b6bfb681b
commit 28160e329b
3 changed files with 52 additions and 63 deletions

View File

@ -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 // Gets the user's review queue
userRouter.get("/queue", async (req, res) => { userRouter.get("/queue", async (req, res) => {
console.log("STUB: /user/queue"); console.log("STUB: /user/queue");
@ -38,7 +46,19 @@ userRouter.get("/queue", async (req, res) => {
// TODO: Stub // TODO: Stub
res.send({ res.send({
error: "0", 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
}]
},
}); });
}); });

View File

@ -82,67 +82,36 @@ export default class Application extends React.Component<IProps> {
} }
setLastReview = (meta: IReviewMetadata) => { setLastReview = (meta: IReviewMetadata) => {
console.log("STUB: Application::setLastReview"); fetch(`${BACKEND_URL}/api/user/lastReview`, {
headers: new Headers({
// TODO: Send this to the server "Content-Type": "application/json",
/* this.setState({ "Token": this.props.user.sessionToken,
* lastReview: meta, }),
* }); */ method: "POST",
} body: JSON.stringify({
meta,
getReviewQueue = (): Promise<IVocab[]> => { }),
console.log("STUB: Application::getReviewQueue"); }).then(resp => resp.json(), err => {
console.log("Application::setLastReview: POSTing last results failed");
// 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: "<Wortbedeutung>",
* 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);
}); });
} }
getLearners(): ILearner[] { getReviewQueue = (): Promise<IVocab[]> => {
console.log("STUB: Application::getLearners"); return new Promise((res, rej) => {
fetch(`${BACKEND_URL}/api/user/queue`, {
// TODO: Implement headers: new Headers({
return [{ "Content-Type": "application/json",
username: "Polynomdivision", "Token": this.props.user.sessionToken,
level: 5, }),
score: 400, }).then(resp => resp.json(), err => rej(err))
}, { .then(data => {
username: "Polynomdivision2", if (data.error === "0") {
level: 3, res(data.data.queue);
score: 500, } else {
}, { rej(data);
username: "Der eine Typ", }
level: 7, });
score: 100, });
}];
} }
getTopTenLearners = (): Promise<TopTen[]> => { getTopTenLearners = (): Promise<TopTen[]> => {

View File

@ -4,10 +4,10 @@ export enum ReviewMode {
}; };
export enum VocabType { export enum VocabType {
NOMEN, NOMEN = 0,
VERB, VERB = 1,
ADJEKTIV, ADJEKTIV = 2,
ADVERB ADVERB = 3,
}; };
export interface INomenData { export interface INomenData {