mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 00:24:53 +00:00
Merge branch 'dev' of https://github.com/urosran/cally into dev
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import React, {useState} from "react";
|
||||
import {MaterialIcons,} from "@expo/vector-icons";
|
||||
import {Button, Card, Dialog, PanningProvider, Text, View,} from "react-native-ui-lib";
|
||||
import {StyleSheet, TouchableOpacity} from "react-native";
|
||||
import AddChoreDialog from "../todos/AddChoreDialog";
|
||||
@ -11,7 +10,6 @@ import NavToDosIcon from "@/assets/svgs/NavToDosIcon";
|
||||
import {useSetAtom} from "jotai";
|
||||
import {selectedNewEventDateAtom} from "@/components/pages/calendar/atoms";
|
||||
import PlusIcon from "@/assets/svgs/PlusIcon";
|
||||
import {useNavigation} from "expo-router";
|
||||
|
||||
export const AddEventDialog = () => {
|
||||
const [show, setShow] = useState(false);
|
||||
@ -33,7 +31,6 @@ export const AddEventDialog = () => {
|
||||
}, 100);
|
||||
};
|
||||
|
||||
const navigation = useNavigation()
|
||||
return (
|
||||
<ToDosContextProvider>
|
||||
<>
|
||||
@ -118,7 +115,7 @@ export const AddEventDialog = () => {
|
||||
}}
|
||||
label="Add To Do"
|
||||
labelStyle={styles.btnLabel}
|
||||
onPress={() => navigation.navigate("todos")}
|
||||
onPress={() => setChoreDialogVisible(true)}
|
||||
iconSource={() => (
|
||||
<NavToDosIcon
|
||||
color="white"
|
||||
|
||||
@ -106,6 +106,24 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => {
|
||||
}, 500)
|
||||
}, []);
|
||||
|
||||
const repeatPickerRef = useRef();
|
||||
const showRepeatPicker = () => {
|
||||
repeatPickerRef.current?.toggleExpandable(true);
|
||||
}
|
||||
|
||||
const validateTodo = () => {
|
||||
if (!todo?.title) {
|
||||
Alert.alert('Alert', 'Title field cannot be empty');
|
||||
return false;
|
||||
}
|
||||
if (!selectedAssignees || selectedAssignees?.length === 0) {
|
||||
Alert.alert('Alert', 'Cannot have a todo without any assignees');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
bottom={true}
|
||||
@ -146,27 +164,28 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => {
|
||||
onPress={() => {
|
||||
try {
|
||||
if (addChoreDialogProps.selectedTodo) {
|
||||
if (!todo?.title) {
|
||||
Alert.alert('Alert', 'Title field cannot be empty');
|
||||
|
||||
if (validateTodo()) {
|
||||
updateToDo({
|
||||
...todo,
|
||||
points: points,
|
||||
assignees: selectedAssignees
|
||||
});
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
updateToDo({
|
||||
...todo,
|
||||
points: points,
|
||||
assignees: selectedAssignees
|
||||
});
|
||||
} else {
|
||||
if (!todo?.title) {
|
||||
Alert.alert('Alert', 'Title field cannot be empty');
|
||||
if (validateTodo()) {
|
||||
addToDo({
|
||||
...todo,
|
||||
done: false,
|
||||
points: points,
|
||||
assignees: selectedAssignees,
|
||||
repeatDays: todo.repeatDays ?? []
|
||||
});
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
addToDo({
|
||||
...todo,
|
||||
done: false,
|
||||
points: points,
|
||||
assignees: selectedAssignees,
|
||||
repeatDays: todo.repeatDays ?? []
|
||||
});
|
||||
}
|
||||
handleClose();
|
||||
} catch (error) {
|
||||
@ -210,26 +229,19 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => {
|
||||
)}
|
||||
</View>
|
||||
<View row centerV>
|
||||
<TodoRepeatIcon />
|
||||
<TodoRepeatIcon onPress={showRepeatPicker}/>
|
||||
<Picker
|
||||
ref={repeatPickerRef}
|
||||
marginL-12
|
||||
placeholder="Select Repeat Type"
|
||||
value={todo?.repeatType}
|
||||
onChange={(value) => {
|
||||
if (value) {
|
||||
if (value.toString() == "None") {
|
||||
setTodo((oldValue) => ({
|
||||
...oldValue,
|
||||
date: null,
|
||||
repeatType: "None",
|
||||
}));
|
||||
} else {
|
||||
setTodo((oldValue) => ({
|
||||
...oldValue,
|
||||
date: new Date(),
|
||||
repeatType: value.toString(),
|
||||
}));
|
||||
}
|
||||
setTodo((oldValue) => ({
|
||||
...oldValue,
|
||||
date: new Date(),
|
||||
repeatType: value.toString(),
|
||||
}));
|
||||
}
|
||||
}}
|
||||
topBarProps={{title: "Repeat"}}
|
||||
|
||||
@ -8,9 +8,14 @@ import {IToDo} from "@/hooks/firebase/types/todoData";
|
||||
import DropdownIcon from "@/assets/svgs/DropdownIcon";
|
||||
import {Dropdown} from "react-native-element-dropdown";
|
||||
import {useGetFamilyMembers} from "@/hooks/firebase/useGetFamilyMembers";
|
||||
import {ProfileType, useAuthContext} from "@/contexts/AuthContext";
|
||||
import {useAuthContext} from "@/contexts/AuthContext";
|
||||
import {StyleSheet} from "react-native";
|
||||
|
||||
const FILTER_OPTIONS = {
|
||||
ME: "Me",
|
||||
EVERYONE: "Everyone"
|
||||
};
|
||||
|
||||
const groupToDosByDate = (toDos: IToDo[]) => {
|
||||
let sortedTodos = toDos.sort((a, b) => a.date - b.date);
|
||||
return sortedTodos.reduce(
|
||||
@ -75,13 +80,16 @@ const groupToDosByDate = (toDos: IToDo[]) => {
|
||||
|
||||
const resolveFilterOptions = (members, user) => {
|
||||
|
||||
return members?.map((member) => {
|
||||
let options = members?.map((member) => {
|
||||
let label = member?.firstName;
|
||||
if (member.uid === user?.uid) {
|
||||
label = "Me";
|
||||
label = FILTER_OPTIONS.ME;
|
||||
}
|
||||
return (member.uid !== user?.uid || member.profileType !== ProfileType.PARENT) && {value: member?.uid, label: label};
|
||||
return {value: member?.uid, label: label};
|
||||
});
|
||||
options.push({value: FILTER_OPTIONS.EVERYONE, label: FILTER_OPTIONS.EVERYONE})
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
const ToDosList = ({ isSettings }: { isSettings?: boolean }) => {
|
||||
@ -110,10 +118,15 @@ const ToDosList = ({ isSettings }: { isSettings?: boolean }) => {
|
||||
|
||||
useEffect(() => {
|
||||
if (toDos && selectedFilter) {
|
||||
let filtered = toDos?.filter((todo) => todo.assignees?.includes(selectedFilter.value) || todo.creatorId === selectedFilter.value) || [];
|
||||
let resolvedGroupedTodos;
|
||||
if (selectedFilter?.value === FILTER_OPTIONS.EVERYONE) {
|
||||
resolvedGroupedTodos = groupToDosByDate(toDos ?? []);
|
||||
} else {
|
||||
let filtered = toDos?.filter((todo) => todo.assignees?.includes(selectedFilter.value)) || [];
|
||||
|
||||
let filteredGroupedTodos = groupToDosByDate(filtered || []);
|
||||
setGroupedToDos(filteredGroupedTodos || []);
|
||||
resolvedGroupedTodos = groupToDosByDate(filtered || []);
|
||||
}
|
||||
setGroupedToDos(resolvedGroupedTodos || []);
|
||||
}
|
||||
}, [selectedFilter, JSON.stringify(toDos)]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user