Files
cally/hooks/firebase/useGetTodos.ts
Dejan f35033f5e7 - Fixed an issue with the Tod dialog
- Implementation of update todo and adding new days in the rule for a repeatable todo
2024-10-25 14:04:13 +02:00

30 lines
988 B
TypeScript

import { useQuery } from "react-query";
import firestore from "@react-native-firebase/firestore";
import { useAuthContext } from "@/contexts/AuthContext";
import {IToDo} from "@/hooks/firebase/types/todoData";
export const useGetTodos = () => {
const { user, profileData } = useAuthContext();
//TODO: Add role based filtering for todos
return useQuery({
queryKey: ["todos", user?.uid],
queryFn: async () => {
const snapshot = await firestore()
.collection("Todos")
.where("familyId", "==", profileData?.familyId)
.get();
return snapshot.docs.map((doc) => {
const data = doc.data();
return {
...data,
id: doc.id,
date: data.date ? new Date(data.date.seconds * 1000) : null,
repeatDays: data.repeatDays ?? []
};
}) as IToDo[];
}
})
};