2025-07-21 15:36:11 +08:00
|
|
|
import React from 'react';
|
2025-07-23 14:26:53 +08:00
|
|
|
import { View, StyleSheet, FlatList } from 'react-native';
|
2025-07-21 15:10:39 +08:00
|
|
|
import { useNavigation } from '@react-navigation/native';
|
|
|
|
import { StackNavigationProp } from '@react-navigation/stack';
|
2025-07-21 15:36:11 +08:00
|
|
|
import { useTasks } from '../context/TasksContext';
|
2025-07-21 15:10:39 +08:00
|
|
|
import TaskCard from '../components/TaskCard';
|
|
|
|
|
|
|
|
type RootStackParamList = {
|
|
|
|
TaskList: undefined;
|
2025-07-23 11:35:09 +08:00
|
|
|
TaskEdit: { taskId: string };
|
2025-07-21 15:10:39 +08:00
|
|
|
};
|
|
|
|
|
2025-07-22 15:10:57 +08:00
|
|
|
type TaskListNavigationProp = StackNavigationProp<
|
|
|
|
RootStackParamList,
|
|
|
|
'TaskList'
|
|
|
|
>;
|
2025-07-21 15:10:39 +08:00
|
|
|
|
|
|
|
export default function TaskListScreen() {
|
2025-07-21 15:36:11 +08:00
|
|
|
const { tasks } = useTasks();
|
2025-07-21 15:10:39 +08:00
|
|
|
const navigation = useNavigation<TaskListNavigationProp>();
|
|
|
|
|
2025-07-23 11:35:09 +08:00
|
|
|
const handlePressTask = (id: string) => {
|
|
|
|
navigation.navigate('TaskEdit', { taskId: id });
|
2025-07-21 15:10:39 +08:00
|
|
|
};
|
|
|
|
|
2025-07-23 14:26:53 +08:00
|
|
|
const renderItem = ({ item }: { item: (typeof tasks)[0] }) => (
|
|
|
|
<TaskCard task={item} onPress={handlePressTask} />
|
|
|
|
);
|
|
|
|
|
2025-07-21 15:10:39 +08:00
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
2025-07-23 14:26:53 +08:00
|
|
|
<FlatList
|
|
|
|
data={tasks}
|
|
|
|
renderItem={renderItem}
|
|
|
|
keyExtractor={item => item.id}
|
|
|
|
ItemSeparatorComponent={() => <View style={styles.separator} />}
|
|
|
|
/>
|
2025-07-21 15:10:39 +08:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
2025-07-23 14:26:53 +08:00
|
|
|
backgroundColor: '#1a1a1a', // 深色背景
|
2025-07-21 15:10:39 +08:00
|
|
|
},
|
2025-07-23 14:26:53 +08:00
|
|
|
separator: {
|
|
|
|
height: 1,
|
|
|
|
backgroundColor: '#333', // 分隔线颜色
|
|
|
|
marginLeft: 16,
|
2025-07-22 15:10:57 +08:00
|
|
|
},
|
|
|
|
});
|