-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlannedTasksHeader.tsx
More file actions
57 lines (48 loc) · 1.54 KB
/
Copy pathPlannedTasksHeader.tsx
File metadata and controls
57 lines (48 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { memo } from 'react';
import { StyleSheet, View } from 'react-native';
import type { SharedValue } from 'react-native-reanimated';
import { useAnimatedReaction, useSharedValue } from 'react-native-reanimated';
import AnimatedText from '@/components/AnimatedText';
import { colors, spacing, text } from '@/theme';
import { SectionHeader } from './SectionHeader';
import { minutesToTime } from './utils';
type PlannedTasksHeaderProps = {
totalDurations: SharedValue<Record<string, number>>;
startTimeMinutes: number;
};
function PlannedTasksHeader({
startTimeMinutes,
totalDurations
}: PlannedTasksHeaderProps) {
const animatedText = useSharedValue('Planned Tasks');
useAnimatedReaction(
() => totalDurations.value,
durations => {
const keys = Object.keys(durations);
const lastKey = keys[keys.length - 1];
const totalDuration = lastKey && durations[lastKey];
if (!totalDuration) {
animatedText.value = 'No planned tasks';
} else {
const endTimeMinutes = startTimeMinutes + totalDuration;
animatedText.value = `${minutesToTime(startTimeMinutes)} - ${minutesToTime(endTimeMinutes)}`;
}
}
);
return (
<View>
<SectionHeader title='Planned Tasks' />
<AnimatedText style={styles.text} text={animatedText} />
</View>
);
}
export default memo(PlannedTasksHeader);
const styles = StyleSheet.create({
text: {
...text.subHeading3,
color: colors.foreground4,
marginBottom: spacing.lg,
marginHorizontal: spacing.sm,
textAlign: 'center'
}
});