mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 07:07:16 +00:00
30 lines
879 B
TypeScript
30 lines
879 B
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(),
|
|
})) as IBrainDump[];
|
|
} catch (error) {
|
|
console.error("Error fetching braindumps:", error);
|
|
throw error;
|
|
}
|
|
},
|
|
enabled: !!currentUser?.uid,
|
|
});
|
|
};
|