Files
cally/components/pages/todos/AddChore.tsx
2024-09-12 15:39:20 +02:00

244 lines
6.6 KiB
TypeScript

import { StyleSheet } from "react-native";
import React, { useEffect, useState } from "react";
import {
Button,
ButtonSize,
View,
Text,
ActionSheet,
TextField,
Dialog,
Slider,
NumberInput,
NumberInputData,
DateTimePicker,
Switch,
} from "react-native-ui-lib";
import { AntDesign, Feather, Ionicons } from "@expo/vector-icons";
import LinearGradient from "react-native-linear-gradient";
import { PanningDirectionsEnum } from "react-native-ui-lib/src/components/panningViews/panningProvider";
import { useToDosContext } from "@/contexts/ToDosContext";
const AddChore = () => {
const { addToDo, toDos } = useToDosContext();
const [newTitle, setNewTitle] = useState<string>("");
const [isVisible, setIsVisible] = useState<boolean>(false);
const [points, setPoints] = useState<number>(10);
const [choreDate, setChoreDate] = useState<Date>(new Date());
const [rotate, setRotate] = useState<boolean>(false);
const handleChange = (text: string) => {
const numericValue = parseInt(text, 10);
if (!isNaN(numericValue) && numericValue >= 0 && numericValue <= 100) {
setPoints(numericValue);
} else if (text === "") {
setPoints(0);
}
};
return (
<LinearGradient
colors={["transparent", "#f9f8f7"]}
locations={[0, 0.5]}
style={styles.gradient}
>
<View style={styles.buttonContainer}>
<Button
marginH-25
size={ButtonSize.large}
style={styles.button}
onPress={() => setIsVisible(!isVisible)}
>
<AntDesign name="plus" size={24} color="white" />
<Text white text60R marginL-10>
Create new chore
</Text>
</Button>
</View>
<Dialog
bottom={true}
height={"90%"}
panDirection={PanningDirectionsEnum.DOWN}
onDismiss={() => setIsVisible(false)}
containerStyle={{
borderRadius: 10,
backgroundColor: "white",
width: "100%",
alignSelf: "stretch",
padding: 0,
margin: 0,
}}
visible={isVisible}
>
<View row spread>
<Button color="#05a8b6" style={styles.topBtn} label="Cancel" onPress={() => {setIsVisible(false)}} />
<Button
style={styles.topBtn}
iconSource={() => (
<Feather name="chevron-down" size={24} color="black" />
)} onPress={() => {setIsVisible(false)}}
/>
<Button
color="#05a8b6"
style={styles.topBtn}
label="Save"
onPress={() => {
addToDo({
id: 0,
title: newTitle,
done: false,
date: choreDate,
points: points,
rotate: rotate,
});
setIsVisible(false);
console.log(toDos);
}}
/>
</View>
<TextField
placeholder="Add chore title"
value={newTitle}
onChangeText={(text) => {
setNewTitle(text);
}}
placeholderTextColor="#2d2d30"
text60R
marginT-15
marginL-30
/>
<View style={styles.divider} />
<View marginL-30 centerV>
<View row marginB-10>
<Feather name="calendar" size={28} color="#919191" />
<DateTimePicker
value={choreDate}
text70
marginL-10
onChange={(date) => {
setChoreDate(date);
}}
/>
</View>
<View row>
<AntDesign name="clockcircleo" size={28} color="#919191" />
</View>
</View>
<View style={styles.divider} />
<View marginH-30 marginB-10 row centerV>
<Ionicons name="person-circle-outline" size={30} color="#919191" />
<Text text60R marginL-10>
Assignees
</Text>
<Button
size={ButtonSize.small}
paddingH-8
iconSource={() => (
<Ionicons name="add-outline" size={20} color="#ea156c" />
)}
style={{
marginLeft: "auto",
borderRadius: 8,
backgroundColor: "#ffe8f1",
borderColor: "#ea156c",
borderWidth: 1,
}}
color="#ea156c"
label="Assign"
/>
</View>
<View row>
<View
marginL-30
style={{
aspectRatio: 1,
width: 60,
backgroundColor: "red",
borderRadius: 50,
}}
/>
<View
marginL-30
style={{
aspectRatio: 1,
width: 60,
backgroundColor: "red",
borderRadius: 50,
}}
/>
</View>
<Switch onColor={'#ea156c'} value={rotate} style={styles.rotateSwitch} onValueChange={(value) => setRotate(value)} />
<View style={styles.divider} />
<View marginH-30 marginB-10 row centerV>
<Ionicons name="gift-outline" size={30} color="#919191" />
<Text text60R marginL-10>
Reward Points
</Text>
</View>
<View marginH-30 row spread>
<View width={"85%"}>
<Slider
value={points}
onValueChange={(value) => setPoints(value)}
minimumValue={0}
step={10}
maximumValue={100}
/>
<View row spread>
<Text>0</Text>
<Text>50</Text>
<Text>100</Text>
</View>
</View>
<View style={{ marginLeft: "auto" }}>
<TextField
value={points.toString()}
onChangeText={(text) => {
handleChange(text);
}}
containerStyle={{
borderWidth: 1,
borderColor: "#d9d9d9",
width: 45,
borderRadius: 5,
}}
/>
</View>
</View>
</Dialog>
</LinearGradient>
);
};
export default AddChore;
const styles = StyleSheet.create({
divider: { height: 1, backgroundColor: "#e4e4e4", marginVertical: 15 },
gradient: {
height: "25%",
position: "absolute",
bottom: 0,
width: "100%",
},
buttonContainer: {
position: "absolute",
bottom: 25,
width: "100%",
},
button: {
backgroundColor: "rgb(253, 23, 117)",
paddingVertical: 20,
},
topBtn: {
backgroundColor: "white",
color: "#05a8b6",
},
rotateSwitch: {
marginLeft: 'auto',
marginRight: 35
}
});