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