- Phase 0: Rename all Kine references to Tabata (types, files, imports, i18n, analytics events) - Phase 1: Add test coverage for tabataProgramStore, workoutProgramStore, and color utils (47 tests) - Phase 2: Remove all `any` types from production code with proper typed replacements - Phase 3: Replace ~60 raw console.* calls with __DEV__-gated logger utility - Phase 4: Verify .DS_Store housekeeping (already clean) 0 TypeScript errors, 583/583 tests passing.
246 lines
7.8 KiB
TypeScript
246 lines
7.8 KiB
TypeScript
/**
|
|
* TabataFit Collection Detail Screen
|
|
* Shows collection info + list of workouts in that collection
|
|
*/
|
|
|
|
import { useMemo } from 'react'
|
|
import { View, StyleSheet, ScrollView, Pressable } from 'react-native'
|
|
import { useRouter, useLocalSearchParams } from 'expo-router'
|
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
import { Icon } from '@/src/shared/components/Icon'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { useHaptics } from '@/src/shared/hooks'
|
|
import { useCollection } from '@/src/shared/hooks/useSupabaseData'
|
|
import { getWorkoutById } from '@/src/shared/data'
|
|
import { useTranslatedWorkouts } from '@/src/shared/data/useTranslatedData'
|
|
import { StyledText } from '@/src/shared/components/StyledText'
|
|
import { track } from '@/src/shared/services/analytics'
|
|
|
|
import { useThemeColors, BRAND } from '@/src/shared/theme'
|
|
import type { ThemeColors } from '@/src/shared/theme/types'
|
|
import { SPACING, LAYOUT } from '@/src/shared/constants/spacing'
|
|
import { RADIUS } from '@/src/shared/constants/borderRadius'
|
|
import { TEXT, NAVY } from '@/src/shared/constants/colors'
|
|
|
|
export default function CollectionDetailScreen() {
|
|
const insets = useSafeAreaInsets()
|
|
const router = useRouter()
|
|
const haptics = useHaptics()
|
|
const { t } = useTranslation()
|
|
const { id } = useLocalSearchParams<{ id: string }>()
|
|
|
|
const colors = useThemeColors()
|
|
const styles = useMemo(() => createStyles(colors), [colors])
|
|
|
|
const { data: collection, isLoading } = useCollection(id)
|
|
|
|
// Resolve workouts from collection's workoutIds
|
|
const rawWorkouts = useMemo(() => {
|
|
if (!collection) return []
|
|
return collection.workoutIds
|
|
.map((wId) => getWorkoutById(wId))
|
|
.filter(Boolean) as NonNullable<ReturnType<typeof getWorkoutById>>[]
|
|
}, [collection])
|
|
|
|
const workouts = useTranslatedWorkouts(rawWorkouts)
|
|
|
|
const handleBack = () => {
|
|
haptics.selection()
|
|
router.back()
|
|
}
|
|
|
|
const handleWorkoutPress = (workoutId: string) => {
|
|
haptics.buttonTap()
|
|
track('collection_workout_tapped', {
|
|
collection_id: id,
|
|
workout_id: workoutId,
|
|
})
|
|
router.push(`/workout/${workoutId}`)
|
|
}
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<View style={[styles.container, styles.centered, { paddingTop: insets.top }]}>
|
|
<StyledText size={17} color={colors.text.tertiary}>Loading...</StyledText>
|
|
</View>
|
|
)
|
|
}
|
|
|
|
if (!collection) {
|
|
return (
|
|
<View style={[styles.container, styles.centered, { paddingTop: insets.top }]}>
|
|
<Icon name="folder" size={48} color={colors.text.tertiary} />
|
|
<StyledText size={17} color={colors.text.tertiary} style={{ marginTop: SPACING[3] }}>
|
|
Collection not found
|
|
</StyledText>
|
|
</View>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<View testID="collection-detail-screen" style={[styles.container, { paddingTop: insets.top }]}>
|
|
{/* Header */}
|
|
<View style={styles.header}>
|
|
<Pressable testID="collection-back-button" onPress={handleBack} style={styles.backButton}>
|
|
<Icon name="chevron.left" size={24} color={colors.text.primary} />
|
|
</Pressable>
|
|
<StyledText size={22} weight="bold" color={colors.text.primary} numberOfLines={1} style={{ flex: 1, textAlign: 'center' }}>
|
|
{collection.title}
|
|
</StyledText>
|
|
<View style={styles.backButton} />
|
|
</View>
|
|
|
|
<ScrollView
|
|
style={styles.scrollView}
|
|
contentContainerStyle={[styles.scrollContent, { paddingBottom: insets.bottom + 100 }]}
|
|
showsVerticalScrollIndicator={false}
|
|
>
|
|
{/* Hero Card */}
|
|
<View testID="collection-hero" style={styles.heroCard}>
|
|
<View style={StyleSheet.absoluteFill} />
|
|
<View style={styles.heroContent}>
|
|
<StyledText size={48} color={TEXT.PRIMARY} style={styles.heroIcon}>
|
|
{collection.icon}
|
|
</StyledText>
|
|
<StyledText size={28} weight="bold" color={TEXT.PRIMARY}>
|
|
{collection.title}
|
|
</StyledText>
|
|
<StyledText size={15} color={TEXT.SECONDARY} style={{ marginTop: SPACING[1] }}>
|
|
{collection.description}
|
|
</StyledText>
|
|
<StyledText size={13} weight="semibold" color={TEXT.TERTIARY} style={{ marginTop: SPACING[2] }}>
|
|
{t('plurals.workout', { count: workouts.length })}
|
|
</StyledText>
|
|
</View>
|
|
</View>
|
|
|
|
{/* Workout List */}
|
|
<StyledText
|
|
size={20}
|
|
weight="bold"
|
|
color={colors.text.primary}
|
|
style={{ marginTop: SPACING[6], marginBottom: SPACING[3] }}
|
|
>
|
|
{t('screens:explore.workouts')}
|
|
</StyledText>
|
|
|
|
{workouts.map((workout) => (
|
|
<Pressable
|
|
key={workout.id}
|
|
testID={`collection-workout-${workout.id}`}
|
|
style={styles.workoutCard}
|
|
onPress={() => handleWorkoutPress(workout.id)}
|
|
>
|
|
<View style={[styles.workoutAvatar, { backgroundColor: BRAND.PRIMARY }]}>
|
|
<Icon name="flame.fill" size={20} color={TEXT.PRIMARY} />
|
|
</View>
|
|
<View style={styles.workoutInfo}>
|
|
<StyledText size={17} weight="semibold" color={colors.text.primary}>
|
|
{workout.title}
|
|
</StyledText>
|
|
<StyledText size={13} color={colors.text.tertiary}>
|
|
{t('durationLevel', {
|
|
duration: workout.duration,
|
|
level: t(`levels.${(workout.level ?? 'Beginner').toLowerCase()}`),
|
|
})}
|
|
</StyledText>
|
|
</View>
|
|
<View style={styles.workoutMeta}>
|
|
<StyledText size={13} color={BRAND.PRIMARY}>
|
|
{t('units.calUnit', { count: workout.calories })}
|
|
</StyledText>
|
|
<Icon name="chevron.right" size={16} color={colors.text.tertiary} />
|
|
</View>
|
|
</Pressable>
|
|
))}
|
|
|
|
{workouts.length === 0 && (
|
|
<View style={styles.emptyState}>
|
|
<Icon name="dumbbell" size={48} color={colors.text.tertiary} />
|
|
<StyledText size={17} color={colors.text.tertiary} style={{ marginTop: SPACING[3] }}>
|
|
No workouts in this collection
|
|
</StyledText>
|
|
</View>
|
|
)}
|
|
</ScrollView>
|
|
</View>
|
|
)
|
|
}
|
|
|
|
function createStyles(colors: ThemeColors) {
|
|
return StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
backgroundColor: colors.bg.base,
|
|
},
|
|
centered: {
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
},
|
|
header: {
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between',
|
|
paddingHorizontal: LAYOUT.SCREEN_PADDING,
|
|
paddingVertical: SPACING[3],
|
|
},
|
|
backButton: {
|
|
width: 44,
|
|
height: 44,
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
},
|
|
heroCard: {
|
|
height: 200,
|
|
borderRadius: RADIUS.XL,
|
|
overflow: 'hidden',
|
|
backgroundColor: NAVY[700],
|
|
},
|
|
heroContent: {
|
|
flex: 1,
|
|
padding: SPACING[5],
|
|
justifyContent: 'flex-end',
|
|
},
|
|
heroIcon: {
|
|
marginBottom: SPACING[2],
|
|
},
|
|
scrollView: {
|
|
flex: 1,
|
|
},
|
|
scrollContent: {
|
|
paddingHorizontal: LAYOUT.SCREEN_PADDING,
|
|
},
|
|
workoutCard: {
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
paddingVertical: SPACING[3],
|
|
paddingHorizontal: SPACING[4],
|
|
backgroundColor: colors.bg.surface,
|
|
borderRadius: RADIUS.LG,
|
|
marginBottom: SPACING[2],
|
|
gap: SPACING[3],
|
|
},
|
|
workoutAvatar: {
|
|
width: 44,
|
|
height: 44,
|
|
borderRadius: RADIUS.FULL,
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
},
|
|
workoutInfo: {
|
|
flex: 1,
|
|
gap: 2,
|
|
},
|
|
workoutMeta: {
|
|
alignItems: 'flex-end',
|
|
gap: 4,
|
|
},
|
|
emptyState: {
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
paddingVertical: SPACING[12],
|
|
},
|
|
})
|
|
}
|