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

151 lines
4.3 KiB
TypeScript
Raw 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-10 08:01:27 +00:00
<View>
<Column bgColor={bgColor}>
<PartContainer>
<Text>3:23</Text>
{!isPreparationPhase && <Reps>{currentRep} / {reps}</Reps>}
{isPreparationPhase && <Reps isPreparationPhase={true}>{t('preparationDescription')}</Reps>}
</PartContainer>
<PartContainer>
<Title isPreparationPhase={isPreparationPhase}>{getTitle()}</Title>
<VerticalSpacer heightUnits={2} />
<Time isPreparationPhase={isPreparationPhase}>
{formatTime(timeLeft)}
</Time>
</PartContainer>
<PartContainer>
<ButtonContainer bgColor={bgColor}>
<Button
secondary={true}
label={t('prev')}
color={'black'}
labelColor={'white'}
onPress={isPreparationPhase ? handleNoop : previousRep}
status={isPreparationPhase ? 'disabled' : 'ready'}
/>
<ElasticSpacer />
{isRunning ? (
<Button secondary={true} color={'black'} label={t('stop')} onPress={handleStop} />
) : (
<Button secondary={true} color={'black'} label={t('start')} onPress={handleContinue} />
)}
<ElasticSpacer />
<Button
secondary={true}
label={t('next')}
color={'black'}
onPress={isPreparationPhase ? nextRep : nextRep}
status="ready"
/>
</ButtonContainer>
<VerticalSpacer heightUnits={4} />
<Button label={i18n.t('back')} onPress={handleBackClick} />
</PartContainer>
</Column>
</View>
2024-10-13 11:29:36 +00:00
);
}
2025-04-10 08:01:27 +00:00
const PartContainer = styled(View)({
backgroundColor: 'transparent',
});
2024-10-13 11:29:36 +00:00
const ButtonContainer = styled(View)<{ bgColor: TimerBgColor }>(({ theme, bgColor }) => ({
backgroundColor: theme.colors.fixed[bgColor],
flexDirection: 'row',
2025-04-10 08:01:27 +00:00
gap: 10,
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-10 08:01:27 +00:00
const Column = styled(View)<{ bgColor: TimerBgColor }>(({ theme, bgColor }) => ({
flexDirection: 'column',
justifyContent: 'space-around',
height: '100%',
backgroundColor: theme.colors.fixed[bgColor],
}));
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
}));