diff --git a/frontend/src/components/app.tsx b/frontend/src/components/app.tsx index b4b6e84..c328e9e 100644 --- a/frontend/src/components/app.tsx +++ b/frontend/src/components/app.tsx @@ -27,6 +27,7 @@ import { IResponse } from "../models/server"; interface IProps { authenticated: boolean; + user: IUser; setAuthenticated: (status: boolean) => void; setUser: (user: IUser) => void; }; @@ -162,37 +163,22 @@ export default class Application extends React.Component { }; } - getLevelVocab(id: number): Promise { - console.log("STUB: Application::getLevelVocab"); - - // TODO: Actually implement this + getLevelVocab = (id: number): Promise => { 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}/auth/level/${id}/vocab`, { + method: "GET", + headers: new Headers({ + "Content-Type": "application/json", + "Token": this.props.user.sessionToken, + }), + }).then(data => data.json()) + .then((resp: IResponse) => { + if (resp.error === "0") { + res(resp.data.vocab); + } else { + rej(resp); + } + }); }); } diff --git a/frontend/src/containers/Application.ts b/frontend/src/containers/Application.ts index 27e60b7..f0485da 100644 --- a/frontend/src/containers/Application.ts +++ b/frontend/src/containers/Application.ts @@ -9,6 +9,7 @@ import { setAuthenticated, setUser } from "../actions"; const mapStateToProps = state => { return { authenticated: state.authenticated, + user: state.user, }; }; const mapDispatchToProps = dispatch => {