mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 15:17:17 +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,9 +27,14 @@ const fetchEvents = async (userId: string, profileData: UserProfile | undefined,
|
|||||||
let constraints;
|
let constraints;
|
||||||
let familyId = profileData?.familyId;
|
let familyId = profileData?.familyId;
|
||||||
|
|
||||||
if (isFamilyView || profileData?.userType === ProfileType.FAMILY_DEVICE) {
|
if (profileData?.userType === ProfileType.FAMILY_DEVICE) {
|
||||||
constraints = [
|
constraints = [
|
||||||
eventsQuery.where("familyId", "==", familyId).where("private", "not-in", [true]),
|
eventsQuery.where("familyId", "==", familyId)
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
if (isFamilyView) {
|
||||||
|
constraints = [
|
||||||
|
eventsQuery.where("familyId", "==", familyId),
|
||||||
eventsQuery.where("creatorId", "==", userId),
|
eventsQuery.where("creatorId", "==", userId),
|
||||||
eventsQuery.where("attendees", "array-contains", userId)
|
eventsQuery.where("attendees", "array-contains", userId)
|
||||||
];
|
];
|
||||||
@ -39,6 +44,7 @@ const fetchEvents = async (userId: string, profileData: UserProfile | undefined,
|
|||||||
eventsQuery.where("attendees", "array-contains", userId)
|
eventsQuery.where("attendees", "array-contains", userId)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const snapshots = await Promise.all(constraints.map(query => query.get()));
|
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 => {
|
snapshots.forEach(snapshot => {
|
||||||
snapshot.docs.forEach(doc => {
|
snapshot.docs.forEach(doc => {
|
||||||
const event = doc.data();
|
const event = doc.data();
|
||||||
|
console.log(event);
|
||||||
const hash = createEventHash(event);
|
const hash = createEventHash(event);
|
||||||
|
|
||||||
if (!processedHashes.has(hash)) {
|
if (!processedHashes.has(hash)) {
|
||||||
@ -102,13 +109,13 @@ export const useGetEvents = () => {
|
|||||||
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, false),
|
queryFn: () => fetchEvents(user.uid, profileData, false),
|
||||||
staleTime: 5 * 60 * 1000,
|
staleTime: 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, true),
|
queryFn: () => fetchEvents(user.uid, profileData, true),
|
||||||
staleTime: 5 * 60 * 1000,
|
staleTime:1000,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user