mirror of
https://github.com/farcasclaudiu/learn-build-apps-copilot-agent.git
synced 2026-06-22 07:01:37 +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 Activities() {
|
|||||||
const [activities, setActivities] = useState([])
|
const [activities, setActivities] = useState([])
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [error, setError] = useState(null)
|
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(() => {
|
useEffect(() => {
|
||||||
fetch('/api/activities/')
|
fetch(endpoint)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||||
return res.json()
|
return res.json()
|
||||||
@@ -19,7 +22,7 @@ function Activities() {
|
|||||||
setError(err.message)
|
setError(err.message)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
})
|
})
|
||||||
}, [])
|
}, [endpoint])
|
||||||
|
|
||||||
if (loading) return <p>Loading activities…</p>
|
if (loading) return <p>Loading activities…</p>
|
||||||
if (error) return <p className="text-danger">Error: {error}</p>
|
if (error) return <p className="text-danger">Error: {error}</p>
|
||||||
|
|||||||
@@ -4,9 +4,12 @@ function Leaderboard() {
|
|||||||
const [leaderboards, setLeaderboards] = useState([])
|
const [leaderboards, setLeaderboards] = useState([])
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [error, setError] = useState(null)
|
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(() => {
|
useEffect(() => {
|
||||||
fetch('/api/leaderboard/')
|
fetch(endpoint)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||||
return res.json()
|
return res.json()
|
||||||
@@ -19,7 +22,7 @@ function Leaderboard() {
|
|||||||
setError(err.message)
|
setError(err.message)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
})
|
})
|
||||||
}, [])
|
}, [endpoint])
|
||||||
|
|
||||||
if (loading) return <p>Loading leaderboard…</p>
|
if (loading) return <p>Loading leaderboard…</p>
|
||||||
if (error) return <p className="text-danger">Error: {error}</p>
|
if (error) return <p className="text-danger">Error: {error}</p>
|
||||||
|
|||||||
@@ -4,9 +4,12 @@ function Teams() {
|
|||||||
const [teams, setTeams] = useState([])
|
const [teams, setTeams] = useState([])
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [error, setError] = useState(null)
|
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(() => {
|
useEffect(() => {
|
||||||
fetch('/api/teams/')
|
fetch(endpoint)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||||
return res.json()
|
return res.json()
|
||||||
@@ -19,7 +22,7 @@ function Teams() {
|
|||||||
setError(err.message)
|
setError(err.message)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
})
|
})
|
||||||
}, [])
|
}, [endpoint])
|
||||||
|
|
||||||
if (loading) return <p>Loading teams…</p>
|
if (loading) return <p>Loading teams…</p>
|
||||||
if (error) return <p className="text-danger">Error: {error}</p>
|
if (error) return <p className="text-danger">Error: {error}</p>
|
||||||
|
|||||||
@@ -4,9 +4,12 @@ function Users() {
|
|||||||
const [users, setUsers] = useState([])
|
const [users, setUsers] = useState([])
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [error, setError] = useState(null)
|
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(() => {
|
useEffect(() => {
|
||||||
fetch('/api/users/')
|
fetch(endpoint)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||||
return res.json()
|
return res.json()
|
||||||
@@ -19,7 +22,7 @@ function Users() {
|
|||||||
setError(err.message)
|
setError(err.message)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
})
|
})
|
||||||
}, [])
|
}, [endpoint])
|
||||||
|
|
||||||
if (loading) return <p>Loading users…</p>
|
if (loading) return <p>Loading users…</p>
|
||||||
if (error) return <p className="text-danger">Error: {error}</p>
|
if (error) return <p className="text-danger">Error: {error}</p>
|
||||||
|
|||||||
@@ -4,9 +4,12 @@ function Workouts() {
|
|||||||
const [workouts, setWorkouts] = useState([])
|
const [workouts, setWorkouts] = useState([])
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [error, setError] = useState(null)
|
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(() => {
|
useEffect(() => {
|
||||||
fetch('/api/workouts/')
|
fetch(endpoint)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||||
return res.json()
|
return res.json()
|
||||||
@@ -19,7 +22,7 @@ function Workouts() {
|
|||||||
setError(err.message)
|
setError(err.message)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
})
|
})
|
||||||
}, [])
|
}, [endpoint])
|
||||||
|
|
||||||
if (loading) return <p>Loading workouts…</p>
|
if (loading) return <p>Loading workouts…</p>
|
||||||
if (error) return <p className="text-danger">Error: {error}</p>
|
if (error) return <p className="text-danger">Error: {error}</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user