Files
digital-pilates/components/MoodCard.tsx
richarjiang 8b9689b269 Refactor components and enhance background task management
- Updated font sizes and weights in BasalMetabolismCard, MoodCard, HealthDataCard, and NutritionRadarCard for improved readability.
- Removed loading state from MoodCard to simplify the component.
- Adjusted styles in WeightHistoryCard for better layout and spacing.
- Integrated expo-background-fetch for improved background task handling.
- Updated Info.plist to include background fetch capability.
- Enhanced background task registration and execution logic in backgroundTaskManager.
- Added debug function to manually trigger background task execution for testing purposes.
2025-09-03 16:17:29 +08:00

99 lines
2.3 KiB
TypeScript

import { MoodCheckin, getMoodConfig } from '@/services/moodCheckins';
import dayjs from 'dayjs';
import LottieView from 'lottie-react-native';
import React, { useEffect, useRef } from 'react';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
interface MoodCardProps {
moodCheckin: MoodCheckin | null;
onPress: () => void;
isLoading?: boolean;
}
export function MoodCard({ moodCheckin, onPress }: MoodCardProps) {
const moodConfig = moodCheckin ? getMoodConfig(moodCheckin.moodType) : null;
const animationRef = useRef<LottieView>(null);
useEffect(() => {
if (animationRef.current) {
animationRef.current.play();
}
}, []);
return (
<TouchableOpacity onPress={onPress} style={styles.moodCardContent} >
<View style={styles.moodCardHeader}>
<Text style={styles.cardTitle}></Text>
<LottieView
ref={animationRef}
source={require('@/assets/lottie/mood/mood_demo.json')}
autoPlay
loop
style={styles.lottieAnimation}
/>
</View>
{moodCheckin ? (
<View style={styles.moodPreview}>
<Text style={styles.moodPreviewText}>
{moodConfig?.label || moodCheckin.moodType}
</Text>
<Text style={styles.moodPreviewTime}>
{dayjs(moodCheckin.createdAt).format('HH:mm')}
</Text>
</View>
) : (
<Text style={styles.moodEmptyText}></Text>
)}
</TouchableOpacity>
);
}
const styles = StyleSheet.create({
moodCardContent: {
width: '100%',
},
moodCardHeader: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
},
cardTitle: {
fontSize: 14,
color: '#192126',
},
lottieAnimation: {
width: 30,
height: 30,
},
moodPreview: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
marginTop: 12,
},
moodPreviewText: {
fontSize: 14,
color: '#059669',
fontWeight: '600',
},
moodPreviewTime: {
fontSize: 12,
color: '#6B7280',
},
moodEmptyText: {
fontSize: 12,
color: '#9CA3AF',
fontStyle: 'italic',
marginTop: 22,
},
moodLoadingText: {
fontSize: 12,
color: '#9CA3AF',
fontStyle: 'italic',
marginTop: 22,
},
});