-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from moonshotcollective/39/fresh_user_data
39/fresh_user_data
- Loading branch information
Showing
7 changed files
with
73 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,41 @@ | ||
import React from "react"; | ||
import React, { useState, useEffect } from "react"; | ||
import { useHistory } from "react-router-dom"; | ||
import axios from "axios"; | ||
import ChallengeList from "../components/ChallengeList"; | ||
|
||
export default function BuilderHomeView({ userObject, userName }) { | ||
export default function BuilderHomeView({ serverUrl, jwt, address }) { | ||
const [userData, setUserData] = useState(); | ||
|
||
const history = useHistory(); | ||
if (userObject == null || Object.keys(userObject).length === 0) { | ||
if (jwt == null || jwt === "") { | ||
history.push("/"); | ||
} | ||
|
||
useEffect(() => { | ||
async function fetchUserData() { | ||
console.log("getting user data"); | ||
const fetchedUserObject = await axios.get(serverUrl + `user`, { | ||
headers: { | ||
authorization: `token ${jwt}`, | ||
address, | ||
}, | ||
}); | ||
setUserData(fetchedUserObject.data); | ||
console.log(fetchedUserObject.data); | ||
} | ||
if (jwt != null && jwt !== "") { | ||
fetchUserData(); | ||
} | ||
}, [jwt, address]); | ||
|
||
return ( | ||
<div className="container"> | ||
<h1>Welcome {userName}!</h1> | ||
<div style={{ textAlign: "start" }}> | ||
<ChallengeList userChallenges={userObject.challenges} /> | ||
</div> | ||
<h1>Welcome {address}!</h1> | ||
{userData ? ( | ||
<div style={{ textAlign: "start" }}> | ||
<ChallengeList userChallenges={userData.challenges} /> | ||
</div> | ||
) : null} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters