mirror of
https://github.com/urosran/cally.git
synced 2025-07-15 17:47:08 +00:00
29 lines
952 B
TypeScript
29 lines
952 B
TypeScript
import { useQuery } from "react-query";
|
|
import firestore from "@react-native-firebase/firestore";
|
|
import { useAuthContext } from "@/contexts/AuthContext";
|
|
import {UserProfile} from "@/hooks/firebase/types/profileTypes";
|
|
import {IToDo} from "@/hooks/firebase/types/todoData";
|
|
|
|
export const useGetTodos = () => {
|
|
const { user, profileData } = useAuthContext();
|
|
|
|
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,
|
|
};
|
|
}) as IToDo[];
|
|
}
|
|
})
|
|
}; |