refactor: Lesson -> Level

This commit is contained in:
Alexander Polynomdivision 2018-09-06 20:13:29 +02:00
parent f4f686073f
commit 423e2263dc
4 changed files with 23 additions and 23 deletions

View File

@ -22,10 +22,10 @@ import AuthRoute from "../security/AuthRoute";
import Dashboard from "../pages/dashboard"; import Dashboard from "../pages/dashboard";
import LoginPage from "../pages/login"; import LoginPage from "../pages/login";
import LessonsPage from "../pages/lessons"; import LevelListPage from "../pages/levelList";
import LevelPage from "../pages/level"; import LevelPage from "../pages/level";
import { ILesson } from "../models/lesson"; import { ILevel } from "../models/level";
import { IVocab } from "../models/vocab"; import { IVocab } from "../models/vocab";
interface IState { interface IState {
@ -47,9 +47,9 @@ export default class Application extends React.Component<{}, IState> {
this.isAuthenticated = this.isAuthenticated.bind(this); this.isAuthenticated = this.isAuthenticated.bind(this);
} }
getLessons(): ILesson[] { getLevels(): ILevel[] {
// TODO: Actually fetch them from somewhere // TODO: Actually fetch them from somewhere
const lessons = [{ const levels = [{
name: "Der Bauer auf dem Feld", name: "Der Bauer auf dem Feld",
desc: "So fängt alles an: Du bist ein einfacher Bauer und musst dich die Karriereleiter mit deinen freshen Latein-Skills hinaufarbeiten", desc: "So fängt alles an: Du bist ein einfacher Bauer und musst dich die Karriereleiter mit deinen freshen Latein-Skills hinaufarbeiten",
level: 1, level: 1,
@ -61,7 +61,7 @@ export default class Application extends React.Component<{}, IState> {
done: false, done: false,
}]; }];
return lessons; return levels;
} }
getLearners(): ILearner[] { getLearners(): ILearner[] {
@ -80,7 +80,7 @@ export default class Application extends React.Component<{}, IState> {
}]; }];
} }
getNextLesson(): ILesson { getNextLevel(): ILevel {
// TODO: Actually fetch data // TODO: Actually fetch data
return { return {
name: "???", name: "???",
@ -203,11 +203,11 @@ export default class Application extends React.Component<{}, IState> {
<AuthRoute <AuthRoute
isAuth={this.isAuthenticated} isAuth={this.isAuthenticated}
path="/dashboard" path="/dashboard"
component={() => <Dashboard nextLesson={this.getNextLesson} learners={this.getLearners()} />} /> component={() => <Dashboard nextLevel={this.getNextLevel} learners={this.getLearners()} />} />
<AuthRoute <AuthRoute
isAuth={this.isAuthenticated} isAuth={this.isAuthenticated}
path="/levelList" path="/levelList"
component={() => <LessonsPage lessons={this.getLessons()} />} /> component={() => <LevelListPage levels={this.getLevels()} />} />
{/*We cannot use AuthRoute here, because match is undefined otherwise*/} {/*We cannot use AuthRoute here, because match is undefined otherwise*/}
<Route <Route
path="/level/:id" path="/level/:id"

View File

@ -1,4 +1,4 @@
export interface ILesson { export interface ILevel {
name: string; name: string;
desc: string; desc: string;
level: number; level: number;

View File

@ -9,11 +9,11 @@ import Paper from "@material-ui/core/Paper";
import Scoreboard from "../components/scoreboard"; import Scoreboard from "../components/scoreboard";
import { ILesson } from "../models/lesson"; import { ILevel } from "../models/level";
import { ILearner } from "../models/learner"; import { ILearner } from "../models/learner";
interface IProps { interface IProps {
nextLesson: () => ILesson; nextLevel: () => ILevel;
learners: ILearner[]; learners: ILearner[];
} }
@ -34,7 +34,7 @@ export default class Dashboard extends React.Component<IProps, IState> {
const small = window.matchMedia("(max-width: 700px)").matches; const small = window.matchMedia("(max-width: 700px)").matches;
const direction = small ? "column" : "row"; const direction = small ? "column" : "row";
const lesson = this.props.nextLesson(); const level = this.props.nextLevel();
return <div> return <div>
{ {
@ -45,16 +45,16 @@ export default class Dashboard extends React.Component<IProps, IState> {
<Grid container direction={direction} spacing={16}> <Grid container direction={direction} spacing={16}>
<Grid item lg={4}> <Grid item lg={4}>
<Paper className="paper"> <Paper className="paper">
<Typography variant="title">{`Level ${lesson.level}`}</Typography> <Typography variant="title">{`Level ${level.level}`}</Typography>
<Typography variant="title" component="p">{lesson.name}</Typography> <Typography variant="title" component="p">{level.name}</Typography>
<br /> <br />
<Typography component="p"> <Typography component="p">
{lesson.desc} {level.desc}
</Typography> </Typography>
<Button className="lesson-card-btn" <Button className="lesson-card-btn"
onClick={() => { onClick={() => {
this.setState({ this.setState({
toLevel: lesson.level, toLevel: level.level,
}); });
}}> }}>
Zum Level Zum Level

View File

@ -7,10 +7,10 @@ import Card from '@material-ui/core/Card';
import CardActions from '@material-ui/core/CardActions'; import CardActions from '@material-ui/core/CardActions';
import CardContent from '@material-ui/core/CardContent'; import CardContent from '@material-ui/core/CardContent';
import { ILesson } from "../models/lesson"; import { ILevel } from "../models/lesson";
interface IProps { interface IProps {
lessons: ILesson[]; levels: ILevel[];
} }
export default class Dashboard extends React.Component<{}> { export default class Dashboard extends React.Component<{}> {
@ -23,17 +23,17 @@ export default class Dashboard extends React.Component<{}> {
const cName = small ? "lesson-card-xs" : "lesson-card-lg"; const cName = small ? "lesson-card-xs" : "lesson-card-lg";
let key = 0; let key = 0;
const lessonToCard = (lesson: ILesson) => { const levelToCard = (level: ILevel) => {
return <Grid item key={key++}> return <Grid item key={key++}>
<Card style={{ <Card style={{
width: small ? window.width - 32 : "300px" width: small ? window.width - 32 : "300px"
}}> }}>
<CardContent className={cName}> <CardContent className={cName}>
<Typography variant="title">{`Level ${lesson.level}`}</Typography> <Typography variant="title">{`Level ${level.level}`}</Typography>
<Typography variant="title" component="p">{lesson.name}</Typography> <Typography variant="title" component="p">{level.name}</Typography>
<br /> <br />
<Typography component="p"> <Typography component="p">
{lesson.desc} {level.desc}
</Typography> </Typography>
</CardContent> </CardContent>
<CardActions> <CardActions>
@ -46,7 +46,7 @@ export default class Dashboard extends React.Component<{}> {
}; };
return <Grid container spacing={16} direction="row"> return <Grid container spacing={16} direction="row">
{this.props.lessons.map(lessonToCard)} {this.props.levels.map(levelToCard)}
</Grid> </Grid>
} }
}; };