-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyTask.js
145 lines (135 loc) · 4.2 KB
/
MyTask.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
135
136
137
138
139
140
141
142
143
144
145
import React, { useState, useEffect, useContext } from 'react';
import { View, Text, TouchableOpacity, StyleSheet, ImageBackground } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import tasks from './TasksOrjinal';
import { GlobalContext } from './GlobalContext';
const MyTaskScreen = () => {
const navigation = useNavigation();
const [selectedCategory, setSelectedCategory] = useState(null);
const { answers, setAnswers } = useContext(GlobalContext);
const remainingTaskList = answers.filter((answer) => answer.type === 'Task' && !answer.completed);
const hasTasksInCategory = (category) => {
return remainingTaskList.some((task) => task.category === category);
};
const handleSelectCategory = (category) => {
navigation.navigate('TaskOptions', { categoryId: category });
setSelectedCategory(category);
};
const renderTaskCategories = () => {
return Array.from(new Set(tasks.map((task) => task.category))).map((category) => {
const isActive = hasTasksInCategory(category);
return (
<TouchableOpacity
key={category}
style={[
styles.button,
{ opacity: isActive ? 1 : 0.5 }
]}
onPress={() => isActive && handleSelectCategory(category)}
disabled={!isActive}
>
<ImageBackground
source={getImageForCategory(category)}
style={styles.imageBackground}
imageStyle={[styles.image, !isActive && styles.inactiveImage]}
blurRadius={!isActive ? 2 : 0}
>
<Text style={styles.buttonText}>{category}</Text>
</ImageBackground>
</TouchableOpacity>
);
});
};
const renderNoTasksMessage = () => {
return (
<View style={styles.noTasksContainer}>
<Text style={styles.noTasksText}>Congratulations!!</Text>
<Text style={styles.noTasksText}>You completed all fundamental tasks!</Text>
<Text style={styles.noTasksText}>You are a ‘Role Model’!</Text>
<Text style={styles.noTasksText}>Stay in touch for upcoming challenges...</Text>
</View>
);
};
// Helper function to get the image for each category
const getImageForCategory = (category) => {
switch (category) {
case 'Dishwashing':
return require('./images/category/dishwashing.jpg');
case 'Plumbing':
return require('./images/category/plumbing.jpeg');
case 'Shower':
return require('./images/category/shower.jpg');
case 'Laundry':
return require('./images/category/laundry.jpg');
case 'Daily activities':
return require('./images/category/dailyactivities.jpeg');
case 'Car owners':
return require('./images/category/carowners.jpg');
// Add more cases for other categories and their respective images
default:
return require('./images/category/carowners.jpg'); // Default image if category not found
}
};
return (
<View style={styles.container}>
{remainingTaskList.length > 0 ? (
<View style={styles.buttonContainer}>{renderTaskCategories()}</View>
) : (
renderNoTasksMessage()
)}
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20,
},
buttonContainer: {
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'space-between',
alignItems: 'center',
},
button: {
borderRadius: 5,
marginBottom: 10,
width: '48%',
aspectRatio: 1,
overflow: 'hidden',
},
buttonText: {
color: '#fff',
textAlign: 'center',
fontWeight: 'bold',
fontSize: 24,
textShadowColor: 'rgba(0, 0, 0, 0.75)',
textShadowOffset: {width: -1, height: 1},
textShadowRadius: 10
},
imageBackground: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
image: {
resizeMode: 'cover',
width: '100%',
height: '100%',
},
inactiveImage: {
opacity: 0.5, // Reduced opacity for inactive categories
},
noTasksContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
noTasksText: {
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
marginBottom: 10,
},
});
export default MyTaskScreen;