-
Notifications
You must be signed in to change notification settings - Fork 1
feat: download iCal and add to Outlook #331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
IsaacPhoon
wants to merge
17
commits into
main
Choose a base branch
from
ip/ical-and-outlook
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a609c65
feat: ✨ add download iCal file feature
IsaacPhoon 266e5fd
fix: 🐛 fix functionality with no scheduled meetings
IsaacPhoon ef71609
fix: 🐛 button color
IsaacPhoon f14adc6
feat: ✨ add download iCal file feature
IsaacPhoon 09cb318
fix: 🐛 fix functionality with no scheduled meetings
IsaacPhoon 7108f9e
Merge branch 'ip/ical-and-outlook' of https://github.com/icssc/ZotMee…
IsaacPhoon 546f683
feat: ✨ make and use server action to query DB for schedule meeting
IsaacPhoon 7f0496a
feat: ✨ add to outlook
IsaacPhoon 7bbff74
feat: ✨ fix outlook bug and add message to indicate only first day added
IsaacPhoon 3b5dd9d
fix: 🐛 fix bug for days of week meetings
IsaacPhoon 49f8e17
feat: ✨ change iCal positioning to be next to outlook
IsaacPhoon daca91f
feat: ✨ iCal no longer shows when no meeting is scheduled
IsaacPhoon c92360b
Update src/components/availability/header/availability-header.tsx
IsaacPhoon 2546178
fix: 🐛 timezone bug
IsaacPhoon 376023f
fix: 🐛 outlook local timezone
IsaacPhoon f57a85d
fix: 🐛 get UTC dates
IsaacPhoon 6568869
fix: 🐛 cubic timezone comment
IsaacPhoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| import { fromZonedTime } from "date-fns-tz"; | ||
| import type { SelectMeeting, SelectScheduledMeeting } from "@/db/schema"; | ||
| import { | ||
| getCurrentWeekDateForAnchor, | ||
| isAnchorDateMeeting, | ||
| } from "@/lib/types/chrono"; | ||
|
|
||
| function formatICalDateTimeUTC(date: Date): string { | ||
| const year = date.getUTCFullYear(); | ||
| const month = String(date.getUTCMonth() + 1).padStart(2, "0"); | ||
| const day = String(date.getUTCDate()).padStart(2, "0"); | ||
| const hours = String(date.getUTCHours()).padStart(2, "0"); | ||
| const minutes = String(date.getUTCMinutes()).padStart(2, "0"); | ||
| const seconds = String(date.getUTCSeconds()).padStart(2, "0"); | ||
| return `${year}${month}${day}T${hours}${minutes}${seconds}Z`; | ||
| } | ||
|
|
||
| function escapeICalText(text: string): string { | ||
| return text | ||
| .replace(/\\/g, "\\\\") | ||
| .replace(/;/g, "\\;") | ||
| .replace(/,/g, "\\,") | ||
| .replace(/\n/g, "\\n"); | ||
| } | ||
|
|
||
| interface TimeInterval { | ||
| date: Date; | ||
| from: string; // "HH:mm:ss" | ||
| to: string; // "HH:mm:ss" | ||
| } | ||
|
|
||
| function mergeScheduledBlocks( | ||
| blocks: SelectScheduledMeeting[], | ||
| ): TimeInterval[] { | ||
| if (blocks.length === 0) return []; | ||
|
|
||
| const byDate = new Map<string, SelectScheduledMeeting[]>(); | ||
| for (const block of blocks) { | ||
| const key = block.scheduledDate.toISOString().split("T")[0]; | ||
| if (!byDate.has(key)) byDate.set(key, []); | ||
| const dateBlocks = byDate.get(key); | ||
| if (dateBlocks) dateBlocks.push(block); | ||
| } | ||
|
|
||
| const intervals: TimeInterval[] = []; | ||
|
|
||
| for (const [, dateBlocks] of byDate) { | ||
| const sorted = [...dateBlocks].sort((a, b) => | ||
| a.scheduledFromTime.localeCompare(b.scheduledFromTime), | ||
| ); | ||
|
|
||
| let currentFrom = sorted[0].scheduledFromTime; | ||
| let currentTo = sorted[0].scheduledToTime; | ||
| const date = sorted[0].scheduledDate; | ||
|
|
||
| for (let i = 1; i < sorted.length; i++) { | ||
| if (sorted[i].scheduledFromTime === currentTo) { | ||
| currentTo = sorted[i].scheduledToTime; | ||
| } else { | ||
| intervals.push({ date, from: currentFrom, to: currentTo }); | ||
| currentFrom = sorted[i].scheduledFromTime; | ||
| currentTo = sorted[i].scheduledToTime; | ||
| } | ||
| } | ||
| intervals.push({ date, from: currentFrom, to: currentTo }); | ||
| } | ||
|
|
||
| return intervals; | ||
| } | ||
|
|
||
| // Helper function to pad a number to 2 digits | ||
| function pad2(n: number): string { | ||
| return String(n).padStart(2, "0"); | ||
| } | ||
|
|
||
| function getYmd(date: Date): { yyyy: number; mm: string; dd: string } { | ||
| return { | ||
| yyyy: date.getFullYear(), | ||
| mm: pad2(date.getMonth() + 1), | ||
| dd: pad2(date.getDate()), | ||
|
IsaacPhoon marked this conversation as resolved.
|
||
| }; | ||
| } | ||
|
|
||
| function zonedLocalDateTimeToUTCDate( | ||
| date: Date, | ||
| time: string, | ||
| timezone: string, | ||
| ): Date { | ||
| const [h, m, s = "00"] = time.split(":"); | ||
| const { yyyy, mm, dd } = getYmd(date); | ||
| return fromZonedTime(`${yyyy}-${mm}-${dd}T${h}:${m}:${s}`, timezone); | ||
| } | ||
|
|
||
| export function generateICalString( | ||
| meetingData: SelectMeeting, | ||
| scheduledBlocks: SelectScheduledMeeting[] = [], | ||
| ): string | null { | ||
| if (scheduledBlocks.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| const lines: string[] = [ | ||
| "BEGIN:VCALENDAR", | ||
| "VERSION:2.0", | ||
| "PRODID:-//ZotMeet//ZotMeet//EN", | ||
| "CALSCALE:GREGORIAN", | ||
| "METHOD:PUBLISH", | ||
| ]; | ||
|
|
||
| const title = escapeICalText(meetingData.title); | ||
| const description = meetingData.description | ||
| ? escapeICalText(meetingData.description) | ||
| : ""; | ||
| const location = meetingData.location | ||
| ? escapeICalText(meetingData.location) | ||
| : ""; | ||
|
|
||
| const now = formatICalDateTimeUTC(new Date()); | ||
| const isDaysOfWeek = isAnchorDateMeeting(meetingData.dates); | ||
| const intervals = mergeScheduledBlocks(scheduledBlocks); | ||
|
|
||
| for (let i = 0; i < intervals.length; i++) { | ||
| const interval = intervals[i]; | ||
|
|
||
| const eventDate = isDaysOfWeek | ||
| ? getCurrentWeekDateForAnchor(interval.date) | ||
| : interval.date; | ||
|
|
||
| const startDate = zonedLocalDateTimeToUTCDate( | ||
| eventDate, | ||
| interval.from, | ||
| meetingData.timezone, | ||
| ); | ||
| const endDate = zonedLocalDateTimeToUTCDate( | ||
| eventDate, | ||
| interval.to, | ||
| meetingData.timezone, | ||
| ); | ||
|
|
||
| const { yyyy, mm, dd } = getYmd(eventDate); | ||
| const datePart = `${yyyy}-${mm}-${dd}`; | ||
| const uid = `${meetingData.id}-scheduled-${datePart}-${i}@zotmeet`; | ||
|
|
||
| lines.push("BEGIN:VEVENT"); | ||
| lines.push(`UID:${uid}`); | ||
| lines.push(`DTSTAMP:${now}`); | ||
| lines.push(`DTSTART:${formatICalDateTimeUTC(startDate)}`); | ||
| lines.push(`DTEND:${formatICalDateTimeUTC(endDate)}`); | ||
| lines.push(`SUMMARY:${title}`); | ||
| if (description) { | ||
| lines.push(`DESCRIPTION:${description}`); | ||
| } | ||
| if (location) { | ||
| lines.push(`LOCATION:${location}`); | ||
| } | ||
| lines.push("END:VEVENT"); | ||
| } | ||
|
|
||
| lines.push("END:VCALENDAR"); | ||
| return lines.join("\r\n"); | ||
| } | ||
|
|
||
| export function triggerICalDownload(content: string, filename: string): void { | ||
| const blob = new Blob([content], { | ||
| type: "text/calendar;charset=utf-8", | ||
| }); | ||
| const url = URL.createObjectURL(blob); | ||
|
|
||
| const link = document.createElement("a"); | ||
| link.href = url; | ||
| link.download = filename; | ||
| document.body.appendChild(link); | ||
| link.click(); | ||
|
|
||
| document.body.removeChild(link); | ||
| URL.revokeObjectURL(url); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| "use server"; | ||
|
|
||
| import { | ||
| getExistingMeeting, | ||
| getScheduledTimeBlocks, | ||
| } from "@data/meeting/queries"; | ||
| import { generateICalString } from "@/lib/ical"; | ||
|
|
||
| export async function getICalFileContent(meetingId: string) { | ||
| const meetingData = await getExistingMeeting(meetingId); | ||
| const blocks = await getScheduledTimeBlocks(meetingId); | ||
|
|
||
| const icalContent = generateICalString(meetingData, blocks); | ||
|
|
||
| return { | ||
| success: icalContent !== null, | ||
| content: icalContent, | ||
| filename: `${meetingData.title.replace(/[^a-zA-Z0-9]/g, "_")}.ics`, | ||
| }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Pass the meeting timezone into the Outlook link generation. The current link uses timezone-less
startdt/enddt, so Outlook will interpret the event in the opener's local timezone and shift meetings for users outsidemeetingData.timezone.Prompt for AI agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update!