Merge branch 'add-previous-and-next-button' into 'main'

feat: add prev and next buttons to Timer

See merge request torpenn/boxons!6
merge-requests/10/head
Torpenn 2024-10-15 15:07:30 +00:00
commit 6ded8bf4d5
5 changed files with 57 additions and 4 deletions

View File

@ -24,6 +24,8 @@ export const en = {
rest: 'Rest', rest: 'Rest',
stop: 'Stop', stop: 'Stop',
start: 'Start', start: 'Start',
prev: 'Previous',
next: 'Next',
}, },
finishContent: { finishContent: {
finish: 'Finished', finish: 'Finished',

View File

@ -24,6 +24,8 @@ export const fr = {
rest: 'Repos', rest: 'Repos',
stop: 'Arrêter', stop: 'Arrêter',
start: 'Commencer', start: 'Commencer',
prev: 'Précédent',
next: 'Suivant',
}, },
finishContent: { finishContent: {
finish: 'Terminé', finish: 'Terminé',

View File

@ -123,6 +123,35 @@ export default function Timer() {
: undefined; : undefined;
}, [sound]); }, [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 = () => { const handleContine = () => {
setIsRunning(true); setIsRunning(true);
}; };
@ -152,6 +181,8 @@ export default function Timer() {
bgColor={renderBgColor()} bgColor={renderBgColor()}
currentRep={currentRep} currentRep={currentRep}
isRunning={isRunning} isRunning={isRunning}
nextRep={nextRep}
previousRep={previousRep}
handleStop={handleStop} handleStop={handleStop}
handleContine={handleContine} handleContine={handleContine}
/> />

View File

@ -14,3 +14,7 @@ export const VerticalSpacer = styled(Spacer)<{ heightUnits: number }>(({ theme,
export const HorizontalSpacer = styled(Spacer)<{ widthUnits: number }>(({ theme, widthUnits }) => ({ export const HorizontalSpacer = styled(Spacer)<{ widthUnits: number }>(({ theme, widthUnits }) => ({
width: theme.layout.gridUnit * widthUnits, width: theme.layout.gridUnit * widthUnits,
})); }));
export const ElasticSpacer = styled(Spacer)({
flexGrow: 1,
});

View File

@ -2,7 +2,7 @@ import { Text, View } from '@/components/shared/Themed';
import styled from '@emotion/native'; import styled from '@emotion/native';
import { formatTime } from '@/components/shared/business/timeHelpers'; import { formatTime } from '@/components/shared/business/timeHelpers';
import Button from '@/components/shared/Button'; 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 { TimerBgColor } from '@/components/useCases/timer/business/type';
import { useNavigation } from 'expo-router'; import { useNavigation } from 'expo-router';
import { NativeStackNavigationProp } from 'react-native-screens/lib/typescript/native-stack/types'; import { NativeStackNavigationProp } from 'react-native-screens/lib/typescript/native-stack/types';
@ -17,6 +17,8 @@ interface TimerContentProps {
isRunning: boolean; isRunning: boolean;
handleStop: () => void; handleStop: () => void;
handleContine: () => void; handleContine: () => void;
nextRep: () => void;
previousRep: () => void;
bgColor: TimerBgColor; bgColor: TimerBgColor;
} }
@ -32,6 +34,8 @@ export default function TimerContent({
isRunning, isRunning,
handleStop, handleStop,
handleContine, handleContine,
nextRep,
previousRep,
bgColor, bgColor,
}: TimerContentProps ) { }: TimerContentProps ) {
const navigation = useNavigation<NavigationProp>(); const navigation = useNavigation<NavigationProp>();
@ -53,22 +57,32 @@ export default function TimerContent({
<VerticalSpacer heightUnits={8} /> <VerticalSpacer heightUnits={8} />
<ButtonContainer bgColor={bgColor}> <ButtonContainer bgColor={bgColor}>
<Button label={t('prev')} onPress={previousRep} />
<ElasticSpacer />
{isRunning ? ( {isRunning ? (
<Button label={t('stop')} onPress={handleStop} /> <Button label={t('stop')} onPress={handleStop} />
) : ( ) : (
<Button label={t('start')} onPress={handleContine} /> <Button label={t('start')} onPress={handleContine} />
)} )}
<VerticalSpacer heightUnits={3} /> <ElasticSpacer />
<Button label={t('next')} onPress={nextRep} />
</ButtonContainer>
<VerticalSpacer heightUnits={4} />
<Button label={i18n.t('back')} onPress={() => navigation.navigate('Dashboard')} /> <Button label={i18n.t('back')} onPress={() => navigation.navigate('Dashboard')} />
</ButtonContainer>
</> </>
); );
} }
const ButtonContainer = styled(View)<{ bgColor: TimerBgColor }>(({ theme, bgColor }) => ({ const ButtonContainer = styled(View)<{ bgColor: TimerBgColor }>(({ theme, bgColor }) => ({
backgroundColor: theme.colors[bgColor] backgroundColor: theme.colors[bgColor],
flexDirection: 'row',
justifyContent: 'space-between',
})); }));
const Title = styled(Text)(({ theme }) => ({ const Title = styled(Text)(({ theme }) => ({