boxons/components/useCases/timer/view/TimerContent.tsx

131 lines
3.6 KiB
TypeScript
Raw Permalink Normal View History

2025-04-08 19:04:33 +00:00
import React from 'react';
2024-10-13 11:29:36 +00:00
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';
2025-04-08 19:04:33 +00:00
import { ElasticSpacer, VerticalSpacer } from '@/components/shared/Spacers';
2024-10-13 11:29:36 +00:00
import { TimerBgColor } from '@/components/useCases/timer/business/type';
import { useNavigation } from '@react-navigation/native';
import { i18n } from '@/app/i18n/i18n';
2024-10-13 11:29:36 +00:00
interface TimerContentProps {
isWorkPhase: boolean;
2025-04-08 20:53:40 +00:00
isPreparationPhase?: boolean;
2024-10-13 11:29:36 +00:00
timeLeft: number;
reps: number;
currentRep: number;
isRunning: boolean;
handleStop: () => void;
2025-04-08 21:29:14 +00:00
handleContinue: () => void;
nextRep: () => void;
previousRep: () => void;
2024-10-13 11:29:36 +00:00
bgColor: TimerBgColor;
handleReset: () => void;
2024-10-13 11:29:36 +00:00
}
const t = i18n.scoped('timer.timerContent');
2024-10-13 11:29:36 +00:00
export default function TimerContent({
isWorkPhase,
2025-04-08 20:53:40 +00:00
isPreparationPhase = false,
2024-10-13 11:29:36 +00:00
timeLeft,
reps,
currentRep,
isRunning,
handleStop,
2025-04-08 21:29:14 +00:00
handleContinue,
handleReset,
nextRep,
previousRep,
2024-10-13 11:29:36 +00:00
bgColor,
}: TimerContentProps ) {
const navigation = useNavigation();
2024-10-13 11:29:36 +00:00
const handleBackClick = () => {
navigation.goBack();
handleReset();
};
2025-04-08 20:53:40 +00:00
const getTitle = () => {
if (isPreparationPhase) return t('preparation');
if (isWorkPhase) return t('fight');
return t('rest');
};
// Handler for disabled buttons during preparation phase
const handleNoop = () => {
// Ne fait rien si on est en phase de préparation
};
2024-10-13 11:29:36 +00:00
return (
<>
2025-04-08 20:53:40 +00:00
<Title isPreparationPhase={isPreparationPhase}>{getTitle()}</Title>
2024-10-13 11:29:36 +00:00
<VerticalSpacer heightUnits={8} />
2025-04-08 20:53:40 +00:00
<Time isPreparationPhase={isPreparationPhase}>
2024-10-13 11:29:36 +00:00
{formatTime(timeLeft)}
</Time>
<VerticalSpacer heightUnits={8} />
2025-04-08 20:53:40 +00:00
{!isPreparationPhase && <Reps>{currentRep} / {reps}</Reps>}
{isPreparationPhase && <Reps isPreparationPhase={true}>{t('preparationDescription')}</Reps>}
2024-10-13 11:29:36 +00:00
<VerticalSpacer heightUnits={8} />
<ButtonContainer bgColor={bgColor}>
2025-04-08 20:53:40 +00:00
<Button
label={t('prev')}
onPress={isPreparationPhase ? handleNoop : previousRep}
status={isPreparationPhase ? 'disabled' : 'ready'}
/>
<ElasticSpacer />
2024-10-13 11:29:36 +00:00
{isRunning ? (
<Button label={t('stop')} onPress={handleStop} />
2024-10-13 11:29:36 +00:00
) : (
2025-04-08 21:29:14 +00:00
<Button label={t('start')} onPress={handleContinue} />
2024-10-13 11:29:36 +00:00
)}
<ElasticSpacer />
2024-10-13 11:29:36 +00:00
2025-04-08 20:53:40 +00:00
<Button
label={t('next')}
onPress={isPreparationPhase ? nextRep : nextRep}
status="ready"
/>
2024-10-13 11:29:36 +00:00
</ButtonContainer>
<VerticalSpacer heightUnits={4} />
<Button label={i18n.t('back')} onPress={handleBackClick} />
2024-10-13 11:29:36 +00:00
</>
);
}
const ButtonContainer = styled(View)<{ bgColor: TimerBgColor }>(({ theme, bgColor }) => ({
backgroundColor: theme.colors.fixed[bgColor],
flexDirection: 'row',
justifyContent: 'space-between',
2024-10-13 11:29:36 +00:00
}));
2025-04-08 20:53:40 +00:00
const Title = styled(Text)<{ isPreparationPhase?: boolean }>(({ theme, isPreparationPhase = false }) => ({
2024-10-13 11:29:36 +00:00
fontSize: 50,
fontWeight: 'bold',
2025-04-08 20:53:40 +00:00
color: isPreparationPhase ? theme.colors.fixed.black : theme.colors.fixed.white
2024-10-13 11:29:36 +00:00
}));
2025-04-08 20:53:40 +00:00
const Time = styled(Text)<{ isPreparationPhase?: boolean }>(({ theme, isPreparationPhase = false }) => ({
2024-10-13 11:29:36 +00:00
fontSize: 100,
fontWeight: 'bold',
2025-04-08 20:53:40 +00:00
color: isPreparationPhase ? theme.colors.fixed.black : theme.colors.fixed.white
2024-10-13 11:29:36 +00:00
}));
2025-04-08 20:53:40 +00:00
const Reps = styled(Text)<{ isPreparationPhase?: boolean }>(({ theme, isPreparationPhase = false }) => ({
2024-10-13 11:29:36 +00:00
fontSize: 30,
fontWeight: 'bold',
2025-04-08 20:53:40 +00:00
color: isPreparationPhase ? theme.colors.fixed.black : theme.colors.fixed.white
2024-10-13 11:29:36 +00:00
}));