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