From ebd6fcbfabeceb1ec2e3c239b0ff21734ae0076f Mon Sep 17 00:00:00 2001 From: Dejan Date: Mon, 4 Nov 2024 22:37:56 +0100 Subject: [PATCH] - Sorted the users when adding todo --- components/pages/todos/AddChoreDialog.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/pages/todos/AddChoreDialog.tsx b/components/pages/todos/AddChoreDialog.tsx index 099d690..aac0737 100644 --- a/components/pages/todos/AddChoreDialog.tsx +++ b/components/pages/todos/AddChoreDialog.tsx @@ -25,6 +25,7 @@ import CalendarIcon from "@/assets/svgs/CalendarIcon"; import ClockOIcon from "@/assets/svgs/ClockOIcon"; import ProfileIcon from "@/assets/svgs/ProfileIcon"; import RepeatFreq from "./RepeatFreq"; +import {useAuthContext} from "@/contexts/AuthContext"; interface IAddChoreDialog { isVisible: boolean; @@ -44,6 +45,7 @@ const defaultTodo = { }; const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => { + const {user} = useAuthContext() const {addToDo, updateToDo} = useToDosContext(); const [todo, setTodo] = useState( addChoreDialogProps.selectedTodo ?? defaultTodo @@ -57,6 +59,11 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => { const titleRef = useRef(null) const {data: members} = useGetFamilyMembers(); + let sortedMembers = members?.sort((a, b) => { + if (a.uid === user?.uid) return -1; + if (b.uid === user?.uid) return 1; + return 0; + }) const handleClose = () => { setTodo(defaultTodo); @@ -272,7 +279,7 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => { /> )} > - {members?.map((member) => ( + {sortedMembers?.map((member) => (