-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddTaskModal.js
More file actions
125 lines (118 loc) · 2.89 KB
/
AddTaskModal.js
File metadata and controls
125 lines (118 loc) · 2.89 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
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
import React, { useState, useEffect } from "react";
import { View, StyleSheet, Alert, Platform } from "react-native";
import { TextInput, Button, Modal } from "react-native-paper";
import DropdownMenu from "./DropdownMenu";
import getDbConnection from "../db/dbConnection";
export default AddTaskModal = ({
modalVisible,
addTaskTag,
setModalVisible,
}) => {
const [taskTitle, setTaskTitle] = useState("");
const [tagsList, setTagsList] = useState([]);
const [selectedTag, setSelectedTag] = useState({});
const closeModal = () => {
setModalVisible(false);
};
const handleAddTask = () => {
if (taskTitle.trim()) {
addTaskTag({ title: taskTitle.trim(), isCompleted: false }, selectedTag);
setTaskTitle("");
setSelectedTag({});
closeModal();
} else {
Alert.alert("Please add a new task.");
}
};
const getTags = async () => {
try {
const tags = await getDbConnection().sql("SELECT * FROM tags");
setTagsList(tags);
} catch (error) {
console.error("Error getting tags", error);
}
};
useEffect(() => {
getTags();
}, []);
return (
<Modal
style={styles.modalContainer}
visible={modalVisible}
onDismiss={closeModal}
>
<View>
<View style={styles.newTaskBox}>
<TextInput
mode="flat"
style={[
styles.textInput,
Platform.OS === "web" && {
boxShadow: "none",
border: "none",
outline: "none",
},
]}
contentStyle={styles.textInputContent}
underlineColor="transparent"
activeUnderlineColor="#6BA2EA"
value={taskTitle}
onChangeText={setTaskTitle}
label="Enter a new task"
keyboardType="default"
/>
</View>
<DropdownMenu tagsList={tagsList} setSelectedTag={setSelectedTag} />
<Button
style={styles.addTaskButton}
textColor="black"
onPress={handleAddTask}
>
Add task
</Button>
</View>
</Modal>
);
};
const styles = StyleSheet.create({
modalContainer: {
flex: 1,
backgroundColor: "white",
padding: 10,
},
newTaskBox: {
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
borderWidth: 1,
borderColor: "lightgray",
backgroundColor: "#f0f5fd",
marginBottom: 10,
},
textInput: {
width: "100%",
backgroundColor: "transparent",
height: 50,
},
textInputContent: {
backgroundColor: "transparennt",
borderWidth: 0,
paddingLeft: 10,
},
button: {
height: 50,
width: 50,
justifyContent: "center",
alignItems: "center",
},
closeButton: {
alignItems: "flex-start",
bottom: 180,
left: -10,
zIndex: 1,
},
addTaskButton: {
backgroundColor: "#b2cae9",
marginTop: 10,
},
});