dbg: Stub all 'API-Calls'

This commit is contained in:
Alexander Polynomdivision
2018-09-14 18:53:01 +02:00
parent 2dba497b19
commit ef4ae740b8
5 changed files with 75 additions and 100 deletions

View File

@@ -31,6 +31,7 @@ import ReviewPage from "../pages/review";
import SummaryPage from "../pages/summary";
import { ILevel } from "../models/level";
import { ILearner } from "../models/learner";
import { IVocab, VocabType } from "../models/vocab";
import { IReviewMetadata } from "../models/review";
@@ -40,7 +41,8 @@ interface IState {
drawerOpen: boolean;
}
// TODO: Replace the sessionStorage with localStorage
// TODO: Replace the sessionStorage with localStorage?
// TODO: Cache API-Calls
export default class Application extends React.Component<{}, IState> {
constructor(props: any) {
super(props);
@@ -60,6 +62,7 @@ export default class Application extends React.Component<{}, IState> {
}
getLevels(): ILevel[] {
console.log("STUB: Application::getLevels");
// TODO: Actually fetch them from somewhere
const levels = [{
name: "Der Bauer auf dem Feld",
@@ -77,6 +80,8 @@ export default class Application extends React.Component<{}, IState> {
}
getLastReview(): IReviewMetadata {
console.log("STUB: Application::getLastReview");
// TODO: Actually fetch this
return {
correct: 5,
@@ -86,6 +91,28 @@ export default class Application extends React.Component<{}, IState> {
}
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,
}];
}
getTopTenLearners(): ILearner[] {
console.log("STUB: Application::getTopTenLearners");
// TODO: Implement
return [{
username: "Polynomdivision",
level: 5,
@@ -102,6 +129,8 @@ export default class Application extends React.Component<{}, IState> {
}
getNextLevel(): ILevel {
console.log("STUB: Application::getNextLevel");
// TODO: Actually fetch data
return {
name: "???",
@@ -112,6 +141,8 @@ export default class Application extends React.Component<{}, IState> {
}
getLevelVocab(id: string): IVocab[] {
console.log("STUB: Application::getLevelVocab");
// TODO: Actually implement this
// TODO: Don't fetch this when it was already fetched once.
return [{
@@ -141,6 +172,8 @@ export default class Application extends React.Component<{}, IState> {
}
login(username: string, password: string): Promise<boolean> {
console.log("STUB: Application::login");
return new Promise((res, rej) => {
// TODO
this.setState({
@@ -179,7 +212,7 @@ export default class Application extends React.Component<{}, IState> {
}
<Typography className="flex" variant="title" color="inherit">
Lateinicus
</Typography>
</Typography>
</Toolbar>
</AppBar>
<SwipeableDrawer
@@ -284,7 +317,7 @@ export default class Application extends React.Component<{}, IState> {
return <Dashboard
nextLevel={this.getNextLevel}
lastReview={this.getLastReview}
learners={this.getLearners()} />
getTopTen={this.getTopTenLearners} />
}} />
<AuthRoute
isAuth={this.isAuthenticated}

View File

@@ -10,10 +10,10 @@ import Typography from "@material-ui/core/Typography";
import { ILearner } from "../models/learner";
interface IProps {
learners: ILearner[];
topTen: ILearner[];
}
export default class Scoreboard extends React.Component<{}> {
export default class Scoreboard extends React.Component<IProps> {
private unique = 0;
private nr = 1;
@@ -46,7 +46,7 @@ export default class Scoreboard extends React.Component<{}> {
}
render() {
const sortedLearners = this.props.learners.sort((a, b) => {
const sortedLearners = this.props.topTen.sort((a, b) => {
if (a.score > b.score) {
return -1;
} else if (a.score < b.score) {

View File

@@ -1,6 +1,6 @@
import * as React from "react";
import { Redirect } from "react-router";
import { Link } from "react-router-dom";
import Grid from "@material-ui/core/Grid";
import Typography from "@material-ui/core/Typography";
@@ -17,22 +17,10 @@ import { IReviewMetadata } from "../models/review";
interface IProps {
nextLevel: () => ILevel;
lastReview: () => IReviewMetadata;
learners: ILearner[];
getTopTen: () => ILearner[];
}
interface IState {
toLevel: number;
}
export default class Dashboard extends React.Component<IProps, IState> {
constructor(props: any) {
super(props);
this.state = {
toLevel: -1;
};
}
export default class Dashboard extends React.Component<IProps> {
render() {
const small = window.matchMedia("(max-width: 700px)").matches;
const direction = small ? "column" : "row";
@@ -40,11 +28,6 @@ export default class Dashboard extends React.Component<IProps, IState> {
const level = this.props.nextLevel();
return <div>
{
this.state.toLevel !== -1 ? (
<Redirect to={`/level/${this.state.toLevel}`} />
) : undefined
}
<Grid container direction={direction} spacing={16}>
<Grid item lg={4}>
<Paper className="paper">
@@ -54,12 +37,10 @@ export default class Dashboard extends React.Component<IProps, IState> {
<Typography component="p">
{level.desc}
</Typography>
<Button className="lesson-card-btn"
onClick={() => {
this.setState({
toLevel: level.level,
});
}}>
<Button
component={Link}
to={`/level/${level.level}`}
className="lesson-card-btn">
Zum Level
</Button>
</Paper>
@@ -70,7 +51,7 @@ export default class Dashboard extends React.Component<IProps, IState> {
Rangliste: Top 10
</Typography>
<Scoreboard learners={this.props.learners.slice(0, 10)} />
<Scoreboard topTen={this.props.getTopTen()} />
</Paper>
</Grid>
<Grid item lg={4}>