From 205712b42253ae0baea26d62528c8470500d6af1 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Wed, 2 Apr 2025 14:19:57 +1100 Subject: sidebar: show events for each day --- src/modules/sidebar/modules/calendar.tsx | 72 ++++++++++++++++++++++++++++++-- src/modules/sidebar/modules/upcoming.tsx | 4 +- 2 files changed, 71 insertions(+), 5 deletions(-) (limited to 'src/modules/sidebar') diff --git a/src/modules/sidebar/modules/calendar.tsx b/src/modules/sidebar/modules/calendar.tsx index 5cf56dd..bb36909 100644 --- a/src/modules/sidebar/modules/calendar.tsx +++ b/src/modules/sidebar/modules/calendar.tsx @@ -1,4 +1,4 @@ -import Calendar from "@/services/calendar"; +import Calendar, { type IEvent } from "@/services/calendar"; import { setupCustomTooltip } from "@/utils/widgets"; import { bind, GLib, Variable } from "astal"; import { Gtk } from "astal/gtk3"; @@ -110,6 +110,32 @@ const getDayTooltip = (day: ical.Time) => { return `${events.length} event${events.length === 1 ? "" : "s"}\n${eventsStr}`; }; +const getEventsHeader = (current: ical.Time) => { + const events = Calendar.get_default().getEventsForDay(current); + const isToday = current.toJSDate().toDateString() === new Date().toDateString(); + return ( + (isToday ? "Today • " : "") + + GLib.DateTime.new_from_unix_local(current.toUnixTime()).format("%B %-d • %A") + + ` • ${events.length} event${events.length === 1 ? "" : "s"}` + ); +}; + +const getEventHeader = (e: IEvent) => { + const start = GLib.DateTime.new_from_unix_local(e.startDate.toUnixTime()); + const time = `${start.format("%-I")}${start.get_minute() > 0 ? `:${start.get_minute()}` : ""}${start.format("%P")}`; + return `${time} ${e.event.summary.replaceAll("&", "&")}`; +}; + +const getEventTooltip = (e: IEvent) => { + const start = GLib.DateTime.new_from_unix_local(e.startDate.toUnixTime()); + const end = GLib.DateTime.new_from_unix_local(e.event.endDate.toUnixTime()); + const sameAmPm = start.format("%P") === end.format("%P"); + const time = `${start.format(`%A, %-d %B • %-I:%M${sameAmPm ? "" : "%P"}`)} — ${end.format("%-I:%M%P")}`; + const locIfExists = e.event.location ? ` ${e.event.location}\n` : ""; + const descIfExists = e.event.description ? `󰒿 ${e.event.description}\n` : ""; + return `${e.event.summary}\n${time}\n${locIfExists}${descIfExists}󰃭 ${e.calendar}`.replaceAll("&", "&"); +}; + const Day = ({ day, shown, current }: { day: ical.Time; shown: Variable; current: Variable }) => (