mirror of
https://github.com/urosran/cally.git
synced 2025-07-14 17:25:46 +00:00
- Introduced attribute id in the eventData type
- INtroduced new method to save the event data from the google and microsoft providers only if there isn't already an event with the same id
This commit is contained in:
@ -6,7 +6,7 @@ import { colorMap } from "@/contexts/SettingsContext";
|
|||||||
import { TouchableOpacity } from "react-native-gesture-handler";
|
import { TouchableOpacity } from "react-native-gesture-handler";
|
||||||
import { fetchGoogleCalendarEvents } from "@/calendar-integration/google-calendar-utils";
|
import { fetchGoogleCalendarEvents } from "@/calendar-integration/google-calendar-utils";
|
||||||
import { fetchMicrosoftCalendarEvents } from "@/calendar-integration/microsoft-calendar-utils";
|
import { fetchMicrosoftCalendarEvents } from "@/calendar-integration/microsoft-calendar-utils";
|
||||||
import { useCreateEvent } from "@/hooks/firebase/useCreateEvent";
|
import { useCreateEventFromProvider } from "@/hooks/firebase/useCreateEvent";
|
||||||
import { useAuthContext } from "@/contexts/AuthContext";
|
import { useAuthContext } from "@/contexts/AuthContext";
|
||||||
import { useUpdateUserData } from "@/hooks/firebase/useUpdateUserData";
|
import { useUpdateUserData } from "@/hooks/firebase/useUpdateUserData";
|
||||||
import { GoogleSignin } from "@react-native-google-signin/google-signin";
|
import { GoogleSignin } from "@react-native-google-signin/google-signin";
|
||||||
@ -48,7 +48,7 @@ const CalendarSettingsPage = (props: {
|
|||||||
const [startDate, setStartDate] = useState<boolean>(true);
|
const [startDate, setStartDate] = useState<boolean>(true);
|
||||||
const { profileData } = useAuthContext();
|
const { profileData } = useAuthContext();
|
||||||
|
|
||||||
const { mutateAsync: createEvent } = useCreateEvent();
|
const { mutateAsync: createEventFromProvider } = useCreateEventFromProvider();
|
||||||
const { mutateAsync: updateUserData } = useUpdateUserData();
|
const { mutateAsync: updateUserData } = useUpdateUserData();
|
||||||
|
|
||||||
const fetchAndSaveGoogleEvents = () => {
|
const fetchAndSaveGoogleEvents = () => {
|
||||||
@ -67,7 +67,7 @@ const CalendarSettingsPage = (props: {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async function saveData(item) {
|
async function saveData(item) {
|
||||||
await createEvent(item);
|
await createEventFromProvider(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchAndSaveMicrosoftEvents = () => {
|
const fetchAndSaveMicrosoftEvents = () => {
|
||||||
|
@ -10,4 +10,5 @@ export interface EventData {
|
|||||||
surpriseEvent?: boolean,
|
surpriseEvent?: boolean,
|
||||||
notes?: string,
|
notes?: string,
|
||||||
reminders?: string[]
|
reminders?: string[]
|
||||||
|
id?: string,
|
||||||
}
|
}
|
@ -23,3 +23,31 @@ export const useCreateEvent = () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const useCreateEventFromProvider = () => {
|
||||||
|
const {user: currentUser} = useAuthContext()
|
||||||
|
const queryClients = useQueryClient()
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationKey: ["createEventFromProvider"],
|
||||||
|
mutationFn: async (eventData: Partial<EventData>) => {
|
||||||
|
try {
|
||||||
|
const snapshot = await firestore()
|
||||||
|
.collection("Events")
|
||||||
|
.where("id", "==", eventData.id)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
if (snapshot.empty) {
|
||||||
|
await firestore()
|
||||||
|
.collection("Events")
|
||||||
|
.add({...eventData, creatorId: currentUser?.uid})
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClients.invalidateQueries("events")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
Reference in New Issue
Block a user