diff --git a/components/ScoreCard.js b/components/ScoreCard.js index efbbc7b..d75b35a 100644 --- a/components/ScoreCard.js +++ b/components/ScoreCard.js @@ -4,7 +4,7 @@ import { getUserId } from '../lib/userAuth' const CONFIRM_MESSAGE = 'Are you sure you want to delete the score?' -const ScoreCard = ({ id, playedAt, totalScore, userId, userName }) => { +const ScoreCard = ({ id, playedAt, totalScore, userId, userName, number_of_holes }) => { const { deleteScore } = useScoreDelete(id) return ( @@ -14,7 +14,7 @@ const ScoreCard = ({ id, playedAt, totalScore, userId, userName }) => { {playedAt}
- {`${userName} posted a score of ${totalScore}`} + {`${userName} posted a score of ${totalScore} (${number_of_holes} - holes)`}
diff --git a/lib/useScorePost.js b/lib/useScorePost.js index 3405f76..cc7e033 100644 --- a/lib/useScorePost.js +++ b/lib/useScorePost.js @@ -5,7 +5,7 @@ import { FEED_URL } from './useScores' const url = `${process.env.NEXT_PUBLIC_API_URL}/scores` const useScorePost = () => { - const postScore = async (totalScore, playedAt) => { + const postScore = async (totalScore, playedAt, number_of_holes) => { fetch(url, { method: 'POST', headers: { @@ -16,6 +16,7 @@ const useScorePost = () => { score: { total_score: totalScore, played_at: playedAt, + number_of_holes: number_of_holes, }, }), }).then(res => res.json()) diff --git a/pages/index.js b/pages/index.js index 0fc0a60..431fd98 100644 --- a/pages/index.js +++ b/pages/index.js @@ -22,6 +22,7 @@ const Home = () => { playedAt={score.played_at} userId={score.user_id} userName={score.user_name} + number_of_holes={score.number_of_holes} /> ))} diff --git a/pages/user/[id].js b/pages/user/[id].js new file mode 100644 index 0000000..3e6e80f --- /dev/null +++ b/pages/user/[id].js @@ -0,0 +1,41 @@ +import { useState, useEffect } from 'react' +import { useRouter } from 'next/router' +import Layout from '../../components/Layout' +import { getToken } from '../../lib/userAuth' + +const UserPage = () =>{ + const router=useRouter() + const {id} = router.query + const [user,setUser]=useState(null) + + useEffect( + () => { + if(!id)return + fetch(`${process.env.NEXT_PUBLIC_API_URL}/users/${id}`, { + headers: { Authorization: `Bearer ${getToken()}` },}) + .then(res => res.json()) + .then (data=> setUser(data.user)) + .catch(e=> {alert(e)}) + + }, + [ id ] + ) + + if(!user)return User not found + + return ( + +

{user.name}

+

Email: {user.email}

+ {user.scores.map(score => ( +
+
{score.played_at}
+
{`${user.name} posted ${score.total_score} (${score.number_of_holes}-holes)`}
+
+ )) + } +
+ ) +} + +export default UserPage \ No newline at end of file