diff --git a/EditPlan.tsx b/EditPlan.tsx index 7270e3f..55321d9 100644 --- a/EditPlan.tsx +++ b/EditPlan.tsx @@ -6,12 +6,7 @@ import { } from "@react-navigation/native"; import { useCallback, useEffect, useState } from "react"; import { Pressable, StyleSheet, View } from "react-native"; -import { - ActivityIndicator, - IconButton, - Switch as PaperSwitch, - Text, -} from "react-native-paper"; +import { IconButton, Switch as PaperSwitch, Text } from "react-native-paper"; import ReorderableList, { ReorderableListRenderItemInfo, } from "react-native-reorderable-list"; @@ -171,9 +166,7 @@ export default function EditPlan() { {DAYS.map((day) => renderDay(day))} Exercises - {names === undefined ? ( - - ) : ( + {names !== undefined && ( No exercises yet} diff --git a/InsightsPage.tsx b/InsightsPage.tsx index 2c87bbc..10832e0 100644 --- a/InsightsPage.tsx +++ b/InsightsPage.tsx @@ -25,6 +25,8 @@ interface HourCount { export default function InsightsPage() { const [weekCounts, setWeekCounts] = useState(); const [hourCounts, setHourCounts] = useState(); + const [loadingWeeks, setLoadingWeeks] = useState(true); + const [loadingHours, setLoadingHours] = useState(true); const [period, setPeriod] = useState(Periods.Monthly); const [showWeek, setShowWeek] = useState(false); const [showHour, setShowHour] = useState(false); @@ -53,14 +55,22 @@ export default function InsightsPage() { ORDER BY hour `; + setLoadingWeeks(true); + setLoadingHours(true); setTimeout( () => AppDataSource.manager .query(selectWeeks) .then(setWeekCounts) + .then(() => setLoadingWeeks(false)) .then(() => AppDataSource.manager.query(selectHours).then(setHourCounts) - ), + ) + .then(() => setLoadingHours(false)) + .finally(() => { + setLoadingWeeks(false); + setLoadingHours(false); + }), 400 ); }, [period]) @@ -126,9 +136,9 @@ export default function InsightsPage() { /> - {weekCounts === undefined && } - - {weekCounts?.length > 0 && ( + {loadingWeeks ? ( + + ) : ( ({ label: DAYS[weekCount.week], @@ -136,6 +146,7 @@ export default function InsightsPage() { }))} /> )} + {weekCounts?.length === 0 && ( No entries yet! Start recording sets to see your most active days of @@ -166,14 +177,15 @@ export default function InsightsPage() { /> - {hourCounts === undefined && } - - {hourCounts?.length > 0 && ( + {loadingHours ? ( + + ) : ( hc.count)} labels={hourCounts.map((hc) => hourLabel(hc.hour))} /> )} + {hourCounts?.length === 0 && ( No entries yet! Start recording sets to see your most active hours diff --git a/SetList.tsx b/SetList.tsx index f94a339..19e8946 100644 --- a/SetList.tsx +++ b/SetList.tsx @@ -5,16 +5,16 @@ import { } from "@react-navigation/native"; import { useCallback, useState } from "react"; import { FlatList } from "react-native"; -import { ActivityIndicator, List } from "react-native-paper"; +import { List } from "react-native-paper"; import { Like } from "typeorm"; import { StackParams } from "./AppStack"; -import { LIMIT } from "./constants"; -import { getNow, setRepo, settingsRepo } from "./db"; import DrawerHeader from "./DrawerHeader"; -import GymSet, { defaultSet } from "./gym-set"; import ListMenu from "./ListMenu"; import Page from "./Page"; import SetItem from "./SetItem"; +import { LIMIT } from "./constants"; +import { getNow, setRepo, settingsRepo } from "./db"; +import GymSet, { defaultSet } from "./gym-set"; import Settings from "./settings"; export default function SetList() { @@ -134,7 +134,7 @@ export default function SetList() { }, [sets, ids]); const getContent = () => { - if (!settings || sets === undefined) return ; + if (!settings || sets === undefined) return null; if (sets.length === 0) return ( >(); @@ -40,7 +34,6 @@ export default function StartPlan() { const [selected, setSelected] = useState(0); const [settings, setSettings] = useState(); const [counts, setCounts] = useState(); - const { colors } = useTheme(); const weightRef = useRef(null); const repsRef = useRef(null); const exercises = useMemo(() => params.plan.exercises.split(","), [params]); @@ -222,9 +215,7 @@ export default function StartPlan() { label="Unit" /> )} - {counts === undefined ? ( - - ) : ( + {counts !== undefined && ( count.name} diff --git a/ViewGraph.tsx b/ViewGraph.tsx index 5a7e2a3..9a9f7e4 100644 --- a/ViewGraph.tsx +++ b/ViewGraph.tsx @@ -3,18 +3,18 @@ import { format } from "date-fns"; import { useEffect, useMemo, useState } from "react"; import { View } from "react-native"; import { FileSystem } from "react-native-file-access"; -import { ActivityIndicator, IconButton, List } from "react-native-paper"; +import { IconButton, List } from "react-native-paper"; import Share from "react-native-share"; import { captureScreen } from "react-native-view-shot"; import { StackParams } from "./AppStack"; import Chart from "./Chart"; +import Select from "./Select"; +import StackHeader from "./StackHeader"; import { PADDING } from "./constants"; import { setRepo } from "./db"; import GymSet from "./gym-set"; import { Metrics } from "./metrics"; import { Periods } from "./periods"; -import Select from "./Select"; -import StackHeader from "./StackHeader"; import Volume from "./volume"; export default function ViewGraph() { @@ -76,7 +76,7 @@ export default function ViewGraph() { }, [params.name, metric, period]); const weightChart = useMemo(() => { - if (weights === undefined) return ; + if (weights === undefined) return null; let periodFormat = "do"; if (period === Periods.Weekly) periodFormat = "iii"; @@ -95,7 +95,7 @@ export default function ViewGraph() { }, [weights, period]); const volumeChart = useMemo(() => { - if (volumes === undefined) return ; + if (volumes === undefined) return null; let periodFormat = "do"; if (period === Periods.Weekly) periodFormat = "iii";