mirror of
https://github.com/urosran/cally.git
synced 2025-07-15 09:45:20 +00:00
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { useQuery } from "react-query";
|
|
import firestore from "@react-native-firebase/firestore";
|
|
import { useAuthContext } from "@/contexts/AuthContext";
|
|
|
|
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 {
|
|
id: doc.id,
|
|
title: data.title,
|
|
done: data.done,
|
|
date: data.date ? new Date(data.date.seconds * 1000) : null,
|
|
points: data.points,
|
|
rotate: data.points,
|
|
repeatType: data.repeatType,
|
|
creatorId: data.creatorId
|
|
};
|
|
});
|
|
}
|
|
})
|
|
}; |