From 31b2642853f11773433a5219608af6baed038f18 Mon Sep 17 00:00:00 2001 From: Torpenn Date: Tue, 15 Oct 2024 00:06:39 +0200 Subject: [PATCH] feat: add prev and next buttons to Timer --- app/i18n/translations/en.ts | 2 ++ app/i18n/translations/fr.ts | 2 ++ app/timer.tsx | 31 +++++++++++++++++++ components/shared/Spacers.tsx | 4 +++ .../useCases/timer/view/TimerContent.tsx | 22 ++++++++++--- 5 files changed, 57 insertions(+), 4 deletions(-) diff --git a/app/i18n/translations/en.ts b/app/i18n/translations/en.ts index 084d25a..cddce96 100644 --- a/app/i18n/translations/en.ts +++ b/app/i18n/translations/en.ts @@ -24,6 +24,8 @@ export const en = { rest: 'Rest', stop: 'Stop', start: 'Start', + prev: 'Previous', + next: 'Next', }, finishContent: { finish: 'Finished', diff --git a/app/i18n/translations/fr.ts b/app/i18n/translations/fr.ts index b1df115..56de27d 100644 --- a/app/i18n/translations/fr.ts +++ b/app/i18n/translations/fr.ts @@ -24,6 +24,8 @@ export const fr = { rest: 'Repos', stop: 'Arrêter', start: 'Commencer', + prev: 'Précédent', + next: 'Suivant', }, finishContent: { finish: 'Terminé', diff --git a/app/timer.tsx b/app/timer.tsx index 26744c2..2edf87a 100644 --- a/app/timer.tsx +++ b/app/timer.tsx @@ -123,6 +123,35 @@ export default function Timer() { : undefined; }, [sound]); + const nextRep = () => { + if (currentRep < reps) { + if (isWorkPhase) { + setIsWorkPhase(false); + setTimeLeft(restTime); + } else { + setIsWorkPhase(true); + setTimeLeft(workTime); + setCurrentRep((prevRep) => prevRep + 1); + } + } else { + setIsFinish(true); + setIsRunning(false); + } + }; + + const previousRep = () => { + if (isWorkPhase) { + if (currentRep > 1) { + setIsWorkPhase(false); + setTimeLeft(restTime); + setCurrentRep((prevRep) => prevRep - 1); + } + } else { + setIsWorkPhase(true); + setTimeLeft(workTime); + } + }; + const handleContine = () => { setIsRunning(true); }; @@ -152,6 +181,8 @@ export default function Timer() { bgColor={renderBgColor()} currentRep={currentRep} isRunning={isRunning} + nextRep={nextRep} + previousRep={previousRep} handleStop={handleStop} handleContine={handleContine} /> diff --git a/components/shared/Spacers.tsx b/components/shared/Spacers.tsx index fcd9ad5..b569dab 100644 --- a/components/shared/Spacers.tsx +++ b/components/shared/Spacers.tsx @@ -14,3 +14,7 @@ export const VerticalSpacer = styled(Spacer)<{ heightUnits: number }>(({ theme, export const HorizontalSpacer = styled(Spacer)<{ widthUnits: number }>(({ theme, widthUnits }) => ({ width: theme.layout.gridUnit * widthUnits, })); + +export const ElasticSpacer = styled(Spacer)({ + flexGrow: 1, +}); diff --git a/components/useCases/timer/view/TimerContent.tsx b/components/useCases/timer/view/TimerContent.tsx index b397e48..8117a73 100644 --- a/components/useCases/timer/view/TimerContent.tsx +++ b/components/useCases/timer/view/TimerContent.tsx @@ -2,7 +2,7 @@ import { Text, View } from '@/components/shared/Themed'; import styled from '@emotion/native'; import { formatTime } from '@/components/shared/business/timeHelpers'; import Button from '@/components/shared/Button'; -import { VerticalSpacer } from '@/components/shared/Spacers'; +import { ElasticSpacer, HorizontalSpacer, VerticalSpacer } from '@/components/shared/Spacers'; import { TimerBgColor } from '@/components/useCases/timer/business/type'; import { useNavigation } from 'expo-router'; import { NativeStackNavigationProp } from 'react-native-screens/lib/typescript/native-stack/types'; @@ -17,6 +17,8 @@ interface TimerContentProps { isRunning: boolean; handleStop: () => void; handleContine: () => void; + nextRep: () => void; + previousRep: () => void; bgColor: TimerBgColor; } @@ -32,6 +34,8 @@ export default function TimerContent({ isRunning, handleStop, handleContine, + nextRep, + previousRep, bgColor, }: TimerContentProps ) { const navigation = useNavigation(); @@ -53,22 +57,32 @@ export default function TimerContent({ +