-
Notifications
You must be signed in to change notification settings - Fork 0
/
TaskToFinale.js
134 lines (106 loc) · 2.9 KB
/
TaskToFinale.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import React, { useState, useContext } from 'react';
import { View, Text, TouchableOpacity, StyleSheet, ScrollView } from 'react-native';
import { useLocalStorage } from './useLocalStorage';
import { useNavigation, useFocusEffect } from '@react-navigation/native';
import { GlobalContext } from './GlobalContext';
// TaskToFinale.js'
import questions from './questionsData'
const TaskToFinale = () => {
const navigation = useNavigation();
const { globalArray, setGlobalArray } = useContext(GlobalContext);
const [selectedTasks, setSelectedTasks] = useLocalStorage('selectedTasks', []);
const handleTaskSelection = (task) => {
const taksQuestion = questions.find((answer) => answer.id == task.questionid);
navigation.navigate('MiddleScreen', taksQuestion);
};
useFocusEffect(
React.useCallback(() => {
//console.log("welcome back cr",globalArray)
// Update selectedTasks whenever the screen gains focus
setSelectedTasks(globalArray);
}, [setSelectedTasks, globalArray])
);
return (
<ScrollView contentContainerStyle={styles.container}>
{selectedTasks.length > 0 ? (selectedTasks.map((task) => (
<TouchableOpacity
key={task.questionid}
style={[
styles.task
// task.completed && styles.completedTask,
]}
onPress={() => handleTaskSelection(task)}
>
<Text style={styles.taskName}>{task.task}</Text>
<Text style={styles.taskCategory}>{task.category}</Text>
</TouchableOpacity>
))) : (
<Text style={styles.emptyText}>Horray, nothing to do here! 🎉 If you want to do more go to tasks to select more tasks</Text>
)}
</ScrollView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
padding: 20,
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 20,
},
task: {
borderWidth: 1,
borderColor: '#ccc',
borderRadius: 5,
padding: 10,
marginBottom: 10,
},
completedTask: {
backgroundColor: '#c8f7c5', // Light green color for completed task
},
taskName: {
fontSize: 18,
fontWeight: 'bold',
marginBottom: 5,
},
taskCategory: {
fontSize: 16,
color: '#888',
},
completeButton: {
alignSelf: 'flex-end',
marginTop: 10,
backgroundColor: '#4caf50', // Green color for the complete button
paddingVertical: 8,
paddingHorizontal: 16,
borderRadius: 5,
},
completeButtonText: {
color: '#fff',
fontSize: 16,
fontWeight: 'bold',
},
subPageContainer: {
marginTop: 20,
},
subPageTitle: {
fontSize: 22,
fontWeight: 'bold',
marginBottom: 10,
},
optionButton: {
backgroundColor: '#3498db',
padding: 10,
marginVertical: 5,
borderRadius: 5,
},
optionText: {
color: 'white',
fontSize: 16,
fontWeight: 'bold',
},
});
export default TaskToFinale;