refactor(frontend): migrate Analysis.tsx to the banner system
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api } from "../api/client";
|
||||
import { showError } from "../banner";
|
||||
import { ProgressionChart } from "../components/charts/ProgressionChart";
|
||||
import type { ProgressionMetric, ProgressionPoint, WorkoutKind } from "../types/api";
|
||||
|
||||
@@ -18,7 +19,6 @@ export function Analysis() {
|
||||
const [metric, setMetric] = useState<ProgressionMetric>("pace");
|
||||
const [points, setPoints] = useState<ProgressionPoint[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
api
|
||||
@@ -27,17 +27,16 @@ export function Analysis() {
|
||||
setKinds(k);
|
||||
if (k.length > 0) setSelectedKindId(k[0].ID);
|
||||
})
|
||||
.catch((e) => setError(String(e)));
|
||||
.catch((e) => showError(String(e)));
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedKindId == null) return;
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
api
|
||||
.progression(selectedKindId, metric)
|
||||
.then(setPoints)
|
||||
.catch((e) => setError(String(e)))
|
||||
.catch((e) => showError(String(e)))
|
||||
.finally(() => setLoading(false));
|
||||
}, [selectedKindId, metric]);
|
||||
|
||||
@@ -77,7 +76,6 @@ export function Analysis() {
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{error && <p className="error">{error}</p>}
|
||||
{loading ? <p>Loading...</p> : <ProgressionChart points={points} metric={metric} />}
|
||||
</>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user