diff --git a/components/Modals/CreateCalendarEvent.tsx b/components/Modals/CreateCalendarEvent.tsx index 401c9ba..af8e620 100644 --- a/components/Modals/CreateCalendarEvent.tsx +++ b/components/Modals/CreateCalendarEvent.tsx @@ -78,15 +78,19 @@ export default function CreateCalendarEventModal() { async function handleSubmit() { console.log("CALLED", ndk, currentUser); - if (!ndk || !currentUser) return; + if (!ndk || !currentUser) { + alert("MISSING"); + return; + } + setIsLoading(true); if (!title) { setError("Please add a title"); return; } + try { const random = randomId(); - const tags: string[][] = [ ["d", random], ["name", title], @@ -95,6 +99,7 @@ export default function CreateCalendarEventModal() { ["end", toUnix(convertToTimezone(endDate, timezone)).toString()], ["start_tzid", timezone], ]; + if (location) { tags.push([ "location", @@ -110,6 +115,7 @@ export default function CreateCalendarEventModal() { ]); tags.push(["g", location.geohash]); } + if (imageUrl) { tags.push(["image", imageUrl]); } @@ -121,6 +127,7 @@ export default function CreateCalendarEventModal() { tags: tags, kind: 31923, }; + const event = await createEvent(ndk, preEvent); if (event) { toast.success("Event Created!"); diff --git a/lib/actions/create.ts b/lib/actions/create.ts index 4300ca8..b8829ee 100644 --- a/lib/actions/create.ts +++ b/lib/actions/create.ts @@ -27,6 +27,7 @@ export async function createEvent( ) { log("func", "createEvent"); try { + alert("at pub"); const pubkey = ndk.activeUser?.pubkey; if (!pubkey) { throw new Error("No public key provided!"); diff --git a/lib/utils/dates.ts b/lib/utils/dates.ts index 3f3ee37..f984370 100644 --- a/lib/utils/dates.ts +++ b/lib/utils/dates.ts @@ -138,9 +138,20 @@ export function convertToTimezone(inputDate: Date, targetTimezone: string) { } dayjs.extend(utc); dayjs.extend(timezone); + let hours = inputDate.getHours().toString(); + if (hours.length === 1) { + hours = "0" + hours; + } + let minutes = inputDate.getMinutes().toString(); + if (minutes.length === 1) { + minutes = "0" + minutes; + } + const dateString = `${inputDate.getFullYear()}-${ + inputDate.getMonth() + 1 + }-${inputDate.getDate()}T${hours}:${minutes}:00.000Z`; // Get plain date w/o timezones - const initialDate = new Date(inputDate + "Z"); + const initialDate = new Date(dateString); const plainString = initialDate.toISOString().split(".")[0] as string; const plain = dayjs.tz(plainString, targetTimezone); return plain.toDate();