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