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 --- scss/sidebar.scss | 71 +++++++++++++++++++++++++++++-- src/modules/sidebar/modules/calendar.tsx | 72 ++++++++++++++++++++++++++++++-- src/modules/sidebar/modules/upcoming.tsx | 4 +- 3 files changed, 139 insertions(+), 8 deletions(-) diff --git a/scss/sidebar.scss b/scss/sidebar.scss index d0f221a..1ca19b7 100644 --- a/scss/sidebar.scss +++ b/scss/sidebar.scss @@ -52,7 +52,7 @@ @include lib.element-decel; &:disabled { - color: scheme.$overlay2; + color: color.change(scheme.$overlay2, $alpha: 1); } &:hover, @@ -99,7 +99,7 @@ padding: lib.s(3) lib.s(8); &:disabled { - color: scheme.$overlay0; + color: color.change(scheme.$overlay0, $alpha: 1); } &:hover, @@ -108,7 +108,7 @@ } &:active { - color: scheme.$overlay2; + color: color.change(scheme.$overlay2, $alpha: 1); } &.enabled { @@ -952,5 +952,70 @@ } } } + + .events { + @include lib.spacing(10, true); + + .header { + font-weight: bold; + + @include lib.spacing(10); + + & > button { + @include lib.rounded(1000); + @include lib.element-decel; + + min-width: lib.s(24); + min-height: lib.s(24); + + &:hover, + &:focus { + color: scheme.$subtext0; + } + + &:active { + color: color.change(scheme.$overlay2, $alpha: 1); + } + } + } + + scrollable { + min-height: lib.s(315); + } + + .date { + margin-left: lib.s(10); + } + + .sublabel { + font-size: lib.s(14); + color: scheme.$subtext0; + } + + .list { + padding: lib.s(5); + + @include lib.spacing(10, true); + } + + .event { + @include lib.spacing(8); + } + + .calendar-indicator { + @include lib.rounded(5); + + min-width: lib.s(1); + + $-colours: scheme.$red, scheme.$sapphire, scheme.$flamingo, scheme.$maroon, scheme.$pink, scheme.$sky, + scheme.$peach, scheme.$yellow, scheme.$green, scheme.$rosewater, scheme.$mauve, scheme.$teal, + scheme.$blue; + @for $i from 1 through list.length($-colours) { + &.calendar-#{$i} { + background-color: list.nth($-colours, $i); + } + } + } + } } } 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 }) => (