mirror of
https://github.com/urosran/cally.git
synced 2025-07-09 22:57:16 +00:00
- Fixed events not fetching for the family device
This commit is contained in:
@ -44,10 +44,6 @@ const UsersList = () => {
|
||||
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
console.log(selectedUser);
|
||||
}, [selectedUser]);
|
||||
|
||||
return (
|
||||
<View centerH paddingT-10 marginB-70>
|
||||
{sortedMembers?.map((member, index) => (
|
||||
|
@ -1,10 +1,11 @@
|
||||
import {useQuery, useQueryClient} from "@tanstack/react-query";
|
||||
import firestore from "@react-native-firebase/firestore";
|
||||
import {useAuthContext} from "@/contexts/AuthContext";
|
||||
import {ProfileType, useAuthContext} from "@/contexts/AuthContext";
|
||||
import {useAtomValue} from "jotai";
|
||||
import {isFamilyViewAtom} from "@/components/pages/calendar/atoms";
|
||||
import {colorMap} from "@/constants/colorMap";
|
||||
import {useEffect, useRef} from "react";
|
||||
import {UserProfile} from "@/hooks/firebase/types/profileTypes";
|
||||
|
||||
const createEventHash = (event: any): string => {
|
||||
const str = `${event.startDate?.seconds || ''}-${event.endDate?.seconds || ''}-${
|
||||
@ -20,12 +21,13 @@ const createEventHash = (event: any): string => {
|
||||
return hash.toString(36);
|
||||
};
|
||||
|
||||
const fetchEvents = async (userId: string, familyId: string | undefined, isFamilyView: boolean) => {
|
||||
const fetchEvents = async (userId: string, profileData: UserProfile | undefined, isFamilyView: boolean) => {
|
||||
const db = firestore();
|
||||
const eventsQuery = db.collection("Events");
|
||||
let constraints = [];
|
||||
let constraints;
|
||||
let familyId = profileData?.familyId;
|
||||
|
||||
if (isFamilyView) {
|
||||
if (isFamilyView || profileData?.userType === ProfileType.FAMILY_DEVICE) {
|
||||
constraints = [
|
||||
eventsQuery.where("familyId", "==", familyId).where("private", "==", false),
|
||||
eventsQuery.where("creatorId", "==", userId),
|
||||
@ -99,13 +101,13 @@ export const useGetEvents = () => {
|
||||
const prefetchEvents = async () => {
|
||||
await queryClient.prefetchQuery({
|
||||
queryKey: ["events", user.uid, false], // Personal events
|
||||
queryFn: () => fetchEvents(user.uid, profileData.familyId, false),
|
||||
queryFn: () => fetchEvents(user.uid, profileData, false),
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
|
||||
await queryClient.prefetchQuery({
|
||||
queryKey: ["events", user.uid, true], // Family events
|
||||
queryFn: () => fetchEvents(user.uid, profileData.familyId, true),
|
||||
queryFn: () => fetchEvents(user.uid, profileData, true),
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
};
|
||||
@ -141,7 +143,7 @@ export const useGetEvents = () => {
|
||||
|
||||
return useQuery({
|
||||
queryKey: ["events", user?.uid, isFamilyView],
|
||||
queryFn: () => fetchEvents(user?.uid!, profileData?.familyId, isFamilyView),
|
||||
queryFn: () => fetchEvents(user?.uid!, profileData, isFamilyView),
|
||||
staleTime: Infinity,
|
||||
gcTime: Infinity,
|
||||
placeholderData: (previousData) => previousData,
|
||||
|
Reference in New Issue
Block a user