diff --git a/ViewGraph.tsx b/ViewGraph.tsx
index f3e2ec9..0c69e37 100644
--- a/ViewGraph.tsx
+++ b/ViewGraph.tsx
@@ -3,7 +3,7 @@ import { format } from "date-fns";
import { useEffect, useMemo, useState } from "react";
import { View } from "react-native";
import { FileSystem } from "react-native-file-access";
-import { IconButton, List } from "react-native-paper";
+import { IconButton, List, ActivityIndicator } from "react-native-paper";
import Share from "react-native-share";
import { captureScreen } from "react-native-view-shot";
import Chart from "./Chart";
@@ -75,35 +75,42 @@ export default function ViewGraph() {
}
}, [params.name, metric, period]);
- const charts = useMemo(() => {
+ const weightChart = useMemo(() => {
+ if (weights === undefined) return ;
+
let periodFormat = "do";
if (period === Periods.Weekly) periodFormat = "iii";
else if (period === Periods.Yearly) periodFormat = "P";
- if (metric === Metrics.Volume && Number(volumes?.length) > 0)
- return (
- volume.value)}
- labels={volumes.map((volume) =>
- format(new Date(volume.created), periodFormat)
- )}
- />
- );
- if (
- (metric === Metrics.Best || metric === Metrics.OneRepMax) &&
- Number(weights?.length) > 0
- )
- return (
- set.weight)}
- labels={weights.map((set) =>
- format(new Date(set.created), periodFormat)
- )}
- />
- );
+ if (weights.length === 0) return ;
- return ;
- }, [volumes, weights, metric, period]);
+ return (
+ set.weight)}
+ labels={weights.map((set) =>
+ format(new Date(set.created), periodFormat)
+ )}
+ />
+ );
+ }, [weights, period]);
+
+ const volumeChart = useMemo(() => {
+ if (volumes === undefined) return ;
+
+ let periodFormat = "do";
+ if (period === Periods.Weekly) periodFormat = "iii";
+ else if (period === Periods.Yearly) periodFormat = "P";
+
+ if (volumes.length === 0) return ;
+ return (
+ volume.value)}
+ labels={volumes.map((volume) =>
+ format(new Date(volume.created), periodFormat)
+ )}
+ />
+ );
+ }, [volumes, period]);
return (
<>
@@ -147,7 +154,7 @@ export default function ViewGraph() {
value={period}
/>
- {(weights || volumes) && charts}
+ {metric === Metrics.Volume ? volumeChart : weightChart}
>