diff --git a/view/App.tsx b/view/App.tsx index 2cb1878..cc7c1b4 100644 --- a/view/App.tsx +++ b/view/App.tsx @@ -12,47 +12,59 @@ class App extends React.Component { credentials = this.props.apiToken this.state = { isLoaded: false, - tasks: "" + user_data: { + profile: { + name: "", + }, + stats: { + hp: 0, + lvl: 0, + } + }, + tasks: [] //gave an error if the the tasks thing was string so better keep it an array for .map to work :) } } componentDidMount() { - getTasks(username, credentials) + // getTasks(username, credentials) + // .then(res => res.json()) + // .then( + // result => { + // this.setState({ + // isLoaded: true, + // tasks: result.data + // }) + // }, + // (error) => { + // this.setState({ + // isLoaded: true, + // error + // }) + // } + // ) + + getStats(username, credentials) .then(res => res.json()) .then( result => { + console.log(result) //yup this prints out correctly! since the promise is handled by .then this.setState({ isLoaded: true, - tasks: result.data - }) + user_data: result, + tasks: result.tasks.todos + }) }, (error) => { this.setState({ isLoaded: true, error - }) - } - ) - - getStats(username, credentials) - .then(res => res.json()) - .then( - result => { - this.setState({ - isLoaded: true, - stats: result.data - }) - }, - (error) => { - this.setState({ - isLoaded: true, - error }) } - ) + ) } render(){ - const { error, isLoaded, tasks, stats } = this.state; + const { error, isLoaded, tasks } = this.state; + const user_data = this.state.user_data if (error) { return
Error: {error.message}
; } else if (!isLoaded) { @@ -61,11 +73,13 @@ class App extends React.Component { const listItems = tasks.map((tasks: any) =>
-

{stats}

); - return ( + return (
+

{user_data.profile.name}

{"\n"} +
HP: {user_data.stats.hp}
XP: {user_data.stats.lvl}
{"\n"}
    {listItems}
+
); } } diff --git a/view/TodoItem.tsx b/view/TodoItem.tsx index 84a5415..6566dcc 100644 --- a/view/TodoItem.tsx +++ b/view/TodoItem.tsx @@ -1,8 +1,8 @@ import * as React from "react"; -function TodoItem(props: any) { +function TodoItem(props: any) { return ( -
+

{props.task.text}

diff --git a/view/habiticaAPI.ts b/view/habiticaAPI.ts index 1e80149..e0ab591 100644 --- a/view/habiticaAPI.ts +++ b/view/habiticaAPI.ts @@ -26,7 +26,6 @@ export async function getStats(username: string, credentials: string){ "x-api-key": credentials, }, }) - console.log(response) - console.log("stats above") + console.log("stats") //can't print stats from here since the response is still an unresolved promise return (response) } \ No newline at end of file