From 160349642495e5bb9b76903424a9858e069a377a Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Tue, 4 Jul 2023 11:35:52 +1200 Subject: [PATCH] Rework Best -> Graphs I was considering adding weight tracking, so then this graph page would include body weight graphs. Meaning it's not really recording the "best" of anything. It currently only shows the best on the list page anyway. --- BestPage.tsx | 23 ------------------- BestList.tsx => GraphsList.tsx | 12 +++++----- GraphsPage.tsx | 23 +++++++++++++++++++ Routes.tsx | 6 ++--- ViewBest.tsx => ViewGraph.tsx | 6 ++--- drawer-param-list.ts | 2 +- ...{BestPage.test.tsx => GraphsPage.test.tsx} | 8 +++---- .../{ViewBest.test.tsx => ViewGraph.test.tsx} | 12 +++++----- 8 files changed, 46 insertions(+), 46 deletions(-) delete mode 100644 BestPage.tsx rename BestList.tsx => GraphsList.tsx (88%) create mode 100644 GraphsPage.tsx rename ViewBest.tsx => ViewGraph.tsx (96%) rename tests/{BestPage.test.tsx => GraphsPage.test.tsx} (92%) rename tests/{ViewBest.test.tsx => ViewGraph.test.tsx} (96%) diff --git a/BestPage.tsx b/BestPage.tsx deleted file mode 100644 index e862560..0000000 --- a/BestPage.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import { createStackNavigator } from '@react-navigation/stack' -import BestList from './BestList' -import GymSet from './gym-set' -import ViewBest from './ViewBest' - -const Stack = createStackNavigator() -export type BestPageParams = { - BestList: {} - ViewBest: { - best: GymSet - } -} - -export default function BestPage() { - return ( - - - - - ) -} diff --git a/BestList.tsx b/GraphsList.tsx similarity index 88% rename from BestList.tsx rename to GraphsList.tsx index 02e14ea..873231d 100644 --- a/BestList.tsx +++ b/GraphsList.tsx @@ -6,17 +6,17 @@ import { import { useCallback, useState } from 'react' import { FlatList, Image } from 'react-native' import { List } from 'react-native-paper' -import { BestPageParams } from './BestPage' +import { GraphsPageParams } from './GraphsPage' import { setRepo, settingsRepo } from './db' import DrawerHeader from './DrawerHeader' import GymSet from './gym-set' import Page from './Page' import Settings from './settings' -export default function BestList() { +export default function GraphsList() { const [bests, setBests] = useState() const [term, setTerm] = useState('') - const navigation = useNavigation>() + const navigation = useNavigation>() const [settings, setSettings] = useState() useFocusEffect( @@ -34,7 +34,7 @@ export default function BestList() { .andWhere('NOT hidden') .groupBy('name') .getMany() - console.log(`${BestList.name}.refresh:`, { length: weights.length }) + console.log(`${GraphsList.name}.refresh:`, { length: weights.length }) let newBest: GymSet[] = [] for (const set of weights) { const reps = await setRepo @@ -70,7 +70,7 @@ export default function BestList() { key={item.name} title={item.name} description={`${item.reps} x ${item.weight}${item.unit || 'kg'}`} - onPress={() => navigation.navigate('ViewBest', { best: item })} + onPress={() => navigation.navigate('ViewGraph', { best: item })} left={() => (settings.images && item.image && ( - + {bests?.length === 0 ? ( diff --git a/GraphsPage.tsx b/GraphsPage.tsx new file mode 100644 index 0000000..4f5af6f --- /dev/null +++ b/GraphsPage.tsx @@ -0,0 +1,23 @@ +import { createStackNavigator } from '@react-navigation/stack' +import GraphsList from './GraphsList' +import GymSet from './gym-set' +import ViewGraph from './ViewGraph' + +const Stack = createStackNavigator() +export type GraphsPageParams = { + GraphsList: {} + ViewGraph: { + best: GymSet + } +} + +export default function GraphsPage() { + return ( + + + + + ) +} diff --git a/Routes.tsx b/Routes.tsx index 898cf89..1498496 100644 --- a/Routes.tsx +++ b/Routes.tsx @@ -1,6 +1,6 @@ import { createDrawerNavigator } from '@react-navigation/drawer' import { IconButton } from 'react-native-paper' -import BestPage from './BestPage' +import GraphsPage from './GraphsPage' import { DrawerParamList } from './drawer-param-list' import HomePage from './HomePage' import PlanPage from './PlanPage' @@ -33,8 +33,8 @@ export default function Routes() { options={{ drawerIcon: () => }} /> }} /> >() +export default function ViewGraph() { + const { params } = useRoute>() const [weights, setWeights] = useState() const [volumes, setVolumes] = useState() const [metric, setMetric] = useState(Metrics.Weight) diff --git a/drawer-param-list.ts b/drawer-param-list.ts index 68cae78..4247f54 100644 --- a/drawer-param-list.ts +++ b/drawer-param-list.ts @@ -1,7 +1,7 @@ export type DrawerParamList = { Home: {} Settings: {} - Best: {} + Graphs: {} Plans: {} Workouts: {} Timer: {} diff --git a/tests/BestPage.test.tsx b/tests/GraphsPage.test.tsx similarity index 92% rename from tests/BestPage.test.tsx rename to tests/GraphsPage.test.tsx index fd90c35..a6c02bf 100644 --- a/tests/BestPage.test.tsx +++ b/tests/GraphsPage.test.tsx @@ -1,7 +1,7 @@ import React from 'react' import 'react-native' import { fireEvent, render, waitFor } from 'react-native-testing-library' -import BestPage from '../BestPage' +import GraphsPage from '../GraphsPage' import { MockProviders } from '../mock-providers' import Settings from '../settings' @@ -46,17 +46,17 @@ jest.mock('../db.ts', () => ({ test('renders correctly', async () => { const { getByText } = render( - + , ) - const title = await waitFor(() => getByText('Best')) + const title = await waitFor(() => getByText('Graphs')) expect(title).toBeDefined() }) test('searches', async () => { const { getByDisplayValue, getByPlaceholder } = render( - + , ) const search = await waitFor(() => getByPlaceholder('Search')) diff --git a/tests/ViewBest.test.tsx b/tests/ViewGraph.test.tsx similarity index 96% rename from tests/ViewBest.test.tsx rename to tests/ViewGraph.test.tsx index 7c9ad3b..908874a 100644 --- a/tests/ViewBest.test.tsx +++ b/tests/ViewGraph.test.tsx @@ -1,7 +1,7 @@ import React from 'react' import 'react-native' import { fireEvent, render, waitFor } from 'react-native-testing-library' -import BestPage from '../BestPage' +import GraphsPage from '../GraphsPage' import { MockProviders } from '../mock-providers' import Settings from '../settings' @@ -69,7 +69,7 @@ jest.mock('../db.ts', () => ({ test('renders correctly', async () => { const { getAllByText, getByText } = render( - + , ) const benches = await waitFor(() => getAllByText('Bench press')) @@ -83,7 +83,7 @@ test('renders correctly', async () => { test('volume', async () => { const { getAllByText, getByText } = render( - + , ) const benches = await waitFor(() => getAllByText('Bench press')) @@ -99,7 +99,7 @@ test('volume', async () => { test('one rep max', async () => { const { getAllByText, getByText } = render( - + , ) const benches = await waitFor(() => getAllByText(/Bench press/i)) @@ -115,7 +115,7 @@ test('one rep max', async () => { test('this week', async () => { const { getAllByText, getByText } = render( - + , ) const benches = await waitFor(() => getAllByText(/Bench press/i)) @@ -129,7 +129,7 @@ test('this week', async () => { test('this year', async () => { const { getAllByText, getByText } = render( - + , ) const benches = await waitFor(() => getAllByText(/Bench press/i))