feat: Implement the new /dashboard API

This commit is contained in:
Alexander Polynomdivision
2018-09-24 18:29:29 +02:00
parent 7339e1ccac
commit 24f35be058
7 changed files with 127 additions and 143 deletions

View File

@@ -173,6 +173,27 @@ export default class Application extends React.Component<IProps> {
});
}
// TODO: Type?
getDashboard = (): Promise<any> => {
return new Promise((res, rej) => {
fetch(`${BACKEND_URL}/api/user/dashboard`, {
headers: new Headers({
"Content-Type": "application/json",
"Token": this.props.user.sessionToken,
}),
})
.then(resp => resp.json(), err => rej(err))
.then(data => {
if (data.error === "200") {
res(data.data);
} else {
console.log("Application::getDashboard: Failed to get dashboard");
rej(data);
}
});
});
}
login = (username: string, password: string): Promise<IUser | IResponse> => {
return new Promise((res, rej) => {
fetch(`${BACKEND_URL}/api/login`, {
@@ -233,9 +254,7 @@ export default class Application extends React.Component<IProps> {
path="/dashboard"
component={() => {
return <Dashboard
getNextLevel={this.getNextLevel}
getLastReview={this.getLastReview}
getTopTen={this.getTopTenLearners} />
getDashboard={this.getDashboard} />
}} />
<AuthRoute
isAuth={this.isAuthenticated}