mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 07:07:16 +00:00
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { useAuthContext } from "@/contexts/AuthContext";
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import firestore from "@react-native-firebase/firestore";
|
|
import { IBrainDump } from "@/contexts/DumpContext";
|
|
|
|
export const useGetNotes = () => {
|
|
const { user: currentUser } = useAuthContext();
|
|
|
|
return useQuery<IBrainDump[]>({
|
|
queryKey: ["braindumps", currentUser?.uid],
|
|
queryFn: async () => {
|
|
try {
|
|
const snapshot = await firestore()
|
|
.collection("BrainDumps")
|
|
.where("creatorId", "==", currentUser?.uid)
|
|
.orderBy("updatedAt", "desc")
|
|
.get();
|
|
|
|
return snapshot.docs.map((doc) => ({
|
|
...doc.data(),
|
|
id: doc.id,
|
|
createdAt: doc.data().createdAt,
|
|
updatedAt: doc.data().updatedAt,
|
|
})) as IBrainDump[];
|
|
} catch (error) {
|
|
console.error("Error fetching braindumps:", error);
|
|
throw error;
|
|
}
|
|
},
|
|
enabled: !!currentUser?.uid,
|
|
staleTime: Infinity,
|
|
gcTime: Infinity,
|
|
placeholderData: (previousData) => previousData,
|
|
});
|
|
};
|