mirror of
https://github.com/urosran/cally.git
synced 2026-10-23 09:57:55 +00:00
Event creation
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
export interface EventData {
|
||||
title: string,
|
||||
startDate: Date,
|
||||
endDate: Date,
|
||||
allDay: boolean,
|
||||
repeatDays: string[],
|
||||
creatorId: string[],
|
||||
userIds: string[],
|
||||
timeZone?: string,
|
||||
surpriseEvent?: boolean,
|
||||
notes?: string,
|
||||
reminders?: string[]
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import {useAuthContext} from "@/contexts/AuthContext";
|
||||
import {useMutation, useQueryClient} from "react-query";
|
||||
import firestore from "@react-native-firebase/firestore";
|
||||
import {EventData} from "@/hooks/firebase/types/eventData";
|
||||
|
||||
export const useCreateEvent = () => {
|
||||
const {user: currentUser} = useAuthContext()
|
||||
const queryClients = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationKey: ["createEvent"],
|
||||
mutationFn: async (eventData: Partial<EventData>) => {
|
||||
try {
|
||||
await firestore()
|
||||
.collection("Events")
|
||||
.add({...eventData, creatorId: currentUser?.uid})
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClients.invalidateQueries("events")
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import {useQuery} from "react-query";
|
||||
import firestore from "@react-native-firebase/firestore";
|
||||
import {ReactElement} from "react";
|
||||
import {useAuthContext} from "@/contexts/AuthContext";
|
||||
import {ICalendarEventBase} from "react-native-big-calendar";
|
||||
|
||||
export const useGetEvents = () => {
|
||||
const {user} = useAuthContext()
|
||||
|
||||
return useQuery({
|
||||
queryKey: ["events", user?.uid],
|
||||
queryFn: async () => {
|
||||
const snapshot = await firestore()
|
||||
.collection("Events")
|
||||
.where("creatorId", "==", user?.uid)
|
||||
.get();
|
||||
|
||||
const events: ICalendarEventBase[] = snapshot.docs.map((doc) => {
|
||||
const data = doc.data();
|
||||
return {
|
||||
title: data.title,
|
||||
start: new Date(data.startDate.seconds * 1000),
|
||||
end: new Date(data.endDate.seconds * 1000),
|
||||
hideHours: data.allDay,
|
||||
};
|
||||
});
|
||||
|
||||
return events;
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -14,18 +14,12 @@ export const useUpdateUserData = () => {
|
||||
|
||||
if (user) {
|
||||
try {
|
||||
console.log("yall don't even");
|
||||
console.log(newUserData)
|
||||
await firestore()
|
||||
.collection("Profiles")
|
||||
.doc(user.uid)
|
||||
.set(newUserData);
|
||||
|
||||
console.log("wtf")
|
||||
const profileData = await firestore().collection("Profiles").doc(user?.uid!).get()
|
||||
console.log("wtf222")
|
||||
|
||||
console.log(profileData)
|
||||
setProfileData(profileData.data() as UserProfile)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
|
||||
Reference in New Issue
Block a user