mirror of
https://github.com/farcasclaudiu/learn-build-apps-copilot-agent.git
synced 2026-06-28 19:01:34 +03:00
feat: update API endpoint handling in frontend components for activities, leaderboard, teams, users, and workouts
This commit is contained in:
@@ -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 <p>Loading teams…</p>
|
||||
if (error) return <p className="text-danger">Error: {error}</p>
|
||||
|
||||
Reference in New Issue
Block a user