From dec27a442e3d3a601365d8be911bf6db5f53ef3b Mon Sep 17 00:00:00 2001 From: Claudiu Farcas Date: Sat, 20 Jun 2026 02:30:34 +0000 Subject: [PATCH] feat: update API endpoint handling in frontend components for activities, leaderboard, teams, users, and workouts --- octofit-tracker/frontend/src/components/Activities.jsx | 7 +++++-- octofit-tracker/frontend/src/components/Leaderboard.jsx | 7 +++++-- octofit-tracker/frontend/src/components/Teams.jsx | 7 +++++-- octofit-tracker/frontend/src/components/Users.jsx | 7 +++++-- octofit-tracker/frontend/src/components/Workouts.jsx | 7 +++++-- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/octofit-tracker/frontend/src/components/Activities.jsx b/octofit-tracker/frontend/src/components/Activities.jsx index 94907e7..266c548 100644 --- a/octofit-tracker/frontend/src/components/Activities.jsx +++ b/octofit-tracker/frontend/src/components/Activities.jsx @@ -4,9 +4,12 @@ function Activities() { const [activities, setActivities] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) + const endpoint = import.meta.env.VITE_CODESPACE_NAME + ? `https://${import.meta.env.VITE_CODESPACE_NAME}-8000.app.github.dev/api/activities/` + : '/api/activities/' useEffect(() => { - fetch('/api/activities/') + fetch(endpoint) .then((res) => { if (!res.ok) throw new Error(`HTTP ${res.status}`) return res.json() @@ -19,7 +22,7 @@ function Activities() { setError(err.message) setLoading(false) }) - }, []) + }, [endpoint]) if (loading) return

Loading activities…

if (error) return

Error: {error}

diff --git a/octofit-tracker/frontend/src/components/Leaderboard.jsx b/octofit-tracker/frontend/src/components/Leaderboard.jsx index 89ef414..2fde1e8 100644 --- a/octofit-tracker/frontend/src/components/Leaderboard.jsx +++ b/octofit-tracker/frontend/src/components/Leaderboard.jsx @@ -4,9 +4,12 @@ function Leaderboard() { const [leaderboards, setLeaderboards] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) + const endpoint = import.meta.env.VITE_CODESPACE_NAME + ? `https://${import.meta.env.VITE_CODESPACE_NAME}-8000.app.github.dev/api/leaderboard/` + : '/api/leaderboard/' useEffect(() => { - fetch('/api/leaderboard/') + fetch(endpoint) .then((res) => { if (!res.ok) throw new Error(`HTTP ${res.status}`) return res.json() @@ -19,7 +22,7 @@ function Leaderboard() { setError(err.message) setLoading(false) }) - }, []) + }, [endpoint]) if (loading) return

Loading leaderboard…

if (error) return

Error: {error}

diff --git a/octofit-tracker/frontend/src/components/Teams.jsx b/octofit-tracker/frontend/src/components/Teams.jsx index e491b65..4c59532 100644 --- a/octofit-tracker/frontend/src/components/Teams.jsx +++ b/octofit-tracker/frontend/src/components/Teams.jsx @@ -4,9 +4,12 @@ function Teams() { const [teams, setTeams] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) + const endpoint = import.meta.env.VITE_CODESPACE_NAME + ? `https://${import.meta.env.VITE_CODESPACE_NAME}-8000.app.github.dev/api/teams/` + : '/api/teams/' useEffect(() => { - fetch('/api/teams/') + fetch(endpoint) .then((res) => { if (!res.ok) throw new Error(`HTTP ${res.status}`) return res.json() @@ -19,7 +22,7 @@ function Teams() { setError(err.message) setLoading(false) }) - }, []) + }, [endpoint]) if (loading) return

Loading teams…

if (error) return

Error: {error}

diff --git a/octofit-tracker/frontend/src/components/Users.jsx b/octofit-tracker/frontend/src/components/Users.jsx index 8304023..7ae3134 100644 --- a/octofit-tracker/frontend/src/components/Users.jsx +++ b/octofit-tracker/frontend/src/components/Users.jsx @@ -4,9 +4,12 @@ function Users() { const [users, setUsers] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) + const endpoint = import.meta.env.VITE_CODESPACE_NAME + ? `https://${import.meta.env.VITE_CODESPACE_NAME}-8000.app.github.dev/api/users/` + : '/api/users/' useEffect(() => { - fetch('/api/users/') + fetch(endpoint) .then((res) => { if (!res.ok) throw new Error(`HTTP ${res.status}`) return res.json() @@ -19,7 +22,7 @@ function Users() { setError(err.message) setLoading(false) }) - }, []) + }, [endpoint]) if (loading) return

Loading users…

if (error) return

Error: {error}

diff --git a/octofit-tracker/frontend/src/components/Workouts.jsx b/octofit-tracker/frontend/src/components/Workouts.jsx index b5fd603..bbe3cd4 100644 --- a/octofit-tracker/frontend/src/components/Workouts.jsx +++ b/octofit-tracker/frontend/src/components/Workouts.jsx @@ -4,9 +4,12 @@ function Workouts() { const [workouts, setWorkouts] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) + const endpoint = import.meta.env.VITE_CODESPACE_NAME + ? `https://${import.meta.env.VITE_CODESPACE_NAME}-8000.app.github.dev/api/workouts/` + : '/api/workouts/' useEffect(() => { - fetch('/api/workouts/') + fetch(endpoint) .then((res) => { if (!res.ok) throw new Error(`HTTP ${res.status}`) return res.json() @@ -19,7 +22,7 @@ function Workouts() { setError(err.message) setLoading(false) }) - }, []) + }, [endpoint]) if (loading) return

Loading workouts…

if (error) return

Error: {error}