feat: Implement updating the done levels

This commit is contained in:
Alexander Polynomdivision
2018-09-29 22:00:15 +02:00
parent e6e7505383
commit ab0c75331d
9 changed files with 146 additions and 18 deletions

View File

@@ -195,6 +195,22 @@ export default class Application extends React.Component<IProps> {
});
}
introDontShowAgain = (): void => {
// NOTE: This is not a promise, as we do not care about any response
// being sent, since we don't need to update any client-side
// state.
fetch(`${BACKEND_URL}/api/user/showWelcome`, {
headers: new Headers({
"Content-Type": "application/json",
"Token": this.props.user.sessionToken,
}),
method: "POST",
body: JSON.stringify({
state: false,
}),
});
}
// TODO: Type?
getDashboard = (): Promise<any> => {
return new Promise((res, rej) => {
@@ -216,6 +232,16 @@ export default class Application extends React.Component<IProps> {
});
}
updateDoneLevels = (id: string): void => {
fetch(`${BACKEND_URL}/api/user/level/${id}`, {
headers: new Headers({
"Content-Type": "application/json",
"Token": this.props.user.sessionToken,
}),
method: "POST",
});
}
login = (username: string, password: string): Promise<IUser | IResponse> => {
return new Promise((res, rej) => {
fetch(`${BACKEND_URL}/api/login`, {
@@ -282,7 +308,8 @@ export default class Application extends React.Component<IProps> {
isAuth={this.isAuthenticated}
path="/welcome"
component={() => {
return <WelcomePage />
return <WelcomePage
dontShowAgain={this.introDontShowAgain} />
}} />
<AuthRoute
isAuth={this.isAuthenticated}
@@ -297,7 +324,7 @@ export default class Application extends React.Component<IProps> {
return <LevelPage
id={match.params.id}
levelVocab={this.getLevelVocab}
drawerButtonState={this.drawerButtonState}
updateDoneLevels={this.updateDoneLevels}
setLastReview={this.setLastReview} />;
} else {
return <Redirect to="/login" />;

View File

@@ -9,7 +9,11 @@ import CardContent from "@material-ui/core/CardContent";
import CardActions from "@material-ui/core/CardActions";
import Button from "@material-ui/core/Button";
export default class IntroPage extends React.Component<{}> {
interface IProps {
dontShowAgain: () => void;
};
export default class IntroPage extends React.Component<IProps> {
render() {
const small = window.matchMedia("(max-width: 700px)").matches;
const cName = small ? "intro-card-xs" : "intro-card-lg";
@@ -68,11 +72,11 @@ export default class IntroPage extends React.Component<{}> {
</Typography>
</CardContent>
<CardActions>
{/*TODO: Tell the server to not show this page again*/}
<Button
fullWidth={true}
component={Link}
to="/dashboard">
to="/dashboard"
onClick={this.props.dontShowAgain}>
Lass uns loslegen
</Button>
</CardActions>

View File

@@ -17,6 +17,7 @@ import { IVocab } from "../models/vocab";
interface IProps {
id: string;
levelVocab: (id: string) => Promise<IVocab[]>;
updateDoneLevels: (id: string) => void;
history: any;
@@ -88,6 +89,7 @@ const LevelPageWithRouter = withRouter(
const { vocab, lookedAt, id } = this.props;
// Only go to the review if all vocabulary item have been looked at
if (vocab.length === lookedAt.length) {
this.props.updateDoneLevels(id);
this.props.setLoading(true);
this.props.history.push(`/review/level/${id}`);
}