mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 07:07:16 +00:00
- Improved fetching of events for family device
- Removed fetching events and considering if they're private or not
This commit is contained in:
@ -27,17 +27,23 @@ const fetchEvents = async (userId: string, profileData: UserProfile | undefined,
|
||||
let constraints;
|
||||
let familyId = profileData?.familyId;
|
||||
|
||||
if (isFamilyView || profileData?.userType === ProfileType.FAMILY_DEVICE) {
|
||||
if (profileData?.userType === ProfileType.FAMILY_DEVICE) {
|
||||
constraints = [
|
||||
eventsQuery.where("familyId", "==", familyId).where("private", "not-in", [true]),
|
||||
eventsQuery.where("creatorId", "==", userId),
|
||||
eventsQuery.where("attendees", "array-contains", userId)
|
||||
eventsQuery.where("familyId", "==", familyId)
|
||||
];
|
||||
} else {
|
||||
constraints = [
|
||||
eventsQuery.where("creatorId", "==", userId),
|
||||
eventsQuery.where("attendees", "array-contains", userId)
|
||||
];
|
||||
if (isFamilyView) {
|
||||
constraints = [
|
||||
eventsQuery.where("familyId", "==", familyId),
|
||||
eventsQuery.where("creatorId", "==", userId),
|
||||
eventsQuery.where("attendees", "array-contains", userId)
|
||||
];
|
||||
} else {
|
||||
constraints = [
|
||||
eventsQuery.where("creatorId", "==", userId),
|
||||
eventsQuery.where("attendees", "array-contains", userId)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
const snapshots = await Promise.all(constraints.map(query => query.get()));
|
||||
@ -49,6 +55,7 @@ const fetchEvents = async (userId: string, profileData: UserProfile | undefined,
|
||||
snapshots.forEach(snapshot => {
|
||||
snapshot.docs.forEach(doc => {
|
||||
const event = doc.data();
|
||||
console.log(event);
|
||||
const hash = createEventHash(event);
|
||||
|
||||
if (!processedHashes.has(hash)) {
|
||||
@ -102,13 +109,13 @@ export const useGetEvents = () => {
|
||||
await queryClient.prefetchQuery({
|
||||
queryKey: ["events", user.uid, false], // Personal events
|
||||
queryFn: () => fetchEvents(user.uid, profileData, false),
|
||||
staleTime: 5 * 60 * 1000,
|
||||
staleTime: 1000,
|
||||
});
|
||||
|
||||
await queryClient.prefetchQuery({
|
||||
queryKey: ["events", user.uid, true], // Family events
|
||||
queryFn: () => fetchEvents(user.uid, profileData, true),
|
||||
staleTime: 5 * 60 * 1000,
|
||||
staleTime:1000,
|
||||
});
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user