From 0216fd3dd2831e19bc4312e1315283c53676af27 Mon Sep 17 00:00:00 2001
From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
Date: Wed, 2 Apr 2025 13:20:26 +1100
Subject: sidebar: time pane
Also some fixes for calendar recurring events
Also fix reminders time
---
src/modules/sidebar/index.tsx | 3 +-
src/modules/sidebar/modules/calendar.tsx | 186 +++++++++++++++++++++++++++++++
src/modules/sidebar/modules/upcoming.tsx | 10 +-
src/modules/sidebar/time.tsx | 14 +++
4 files changed, 207 insertions(+), 6 deletions(-)
create mode 100644 src/modules/sidebar/modules/calendar.tsx
create mode 100644 src/modules/sidebar/time.tsx
(limited to 'src/modules/sidebar')
diff --git a/src/modules/sidebar/index.tsx b/src/modules/sidebar/index.tsx
index d4c1855..9d61bae 100644
--- a/src/modules/sidebar/index.tsx
+++ b/src/modules/sidebar/index.tsx
@@ -7,6 +7,7 @@ import Connectivity from "./connectivity";
import Dashboard from "./dashboard";
import NotifPane from "./notifpane";
import Packages from "./packages";
+import Time from "./time";
@register()
export default class SideBar extends Widget.Window {
@@ -23,7 +24,7 @@ export default class SideBar extends Widget.Window {
visible: false,
});
- const panes = [, , , , ];
+ const panes = [, , , , , ];
this.shown = Variable(panes[0].name);
this.add(
diff --git a/src/modules/sidebar/modules/calendar.tsx b/src/modules/sidebar/modules/calendar.tsx
new file mode 100644
index 0000000..5cf56dd
--- /dev/null
+++ b/src/modules/sidebar/modules/calendar.tsx
@@ -0,0 +1,186 @@
+import Calendar from "@/services/calendar";
+import { setupCustomTooltip } from "@/utils/widgets";
+import { bind, GLib, Variable } from "astal";
+import { Gtk } from "astal/gtk3";
+import ical from "ical.js";
+
+const isLeapYear = (year: number) => year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0);
+
+const getMonthDays = (month: number, year: number) => {
+ const leapYear = isLeapYear(year);
+ if (month === 2 && leapYear) return leapYear ? 29 : 28;
+ if ((month <= 7 && month % 2 === 1) || (month >= 8 && month % 2 === 0)) return 31;
+ return 30;
+};
+
+const getNextMonthDays = (month: number, year: number) => {
+ if (month === 12) return 31;
+ return getMonthDays(month + 1, year);
+};
+
+const getPrevMonthDays = (month: number, year: number) => {
+ if (month === 1) return 31;
+ return getMonthDays(month - 1, year);
+};
+
+export function getCalendarLayout(date: ical.Time) {
+ const weekdayOfMonthFirst = date.startOfMonth().dayOfWeek(ical.Time.MONDAY);
+ const daysInMonth = getMonthDays(date.month, date.year);
+ const daysInPrevMonth = getPrevMonthDays(date.month, date.year);
+
+ const calendar: ical.Time[][] = [];
+ let idx = -weekdayOfMonthFirst + 2;
+
+ for (let i = 0; i < 6; i++) {
+ calendar.push([]);
+
+ for (let j = 0; j < 7; j++) {
+ let cDay = idx++;
+ let cMonth = date.month;
+ let cYear = date.year;
+
+ if (idx < 0) {
+ cDay = daysInPrevMonth + cDay;
+ cMonth--;
+
+ if (cMonth < 0) {
+ cMonth += 12;
+ cYear--;
+ }
+ } else if (idx > daysInMonth) {
+ cDay -= daysInMonth;
+ cMonth++;
+
+ if (cMonth > 12) {
+ cMonth -= 12;
+ cYear++;
+ }
+ }
+
+ calendar[i].push(ical.Time.fromData({ day: cDay, month: cMonth, year: cYear }));
+ }
+ }
+
+ return calendar;
+}
+
+const dateToMonthYear = (date: ical.Time) => {
+ const months = [
+ "January",
+ "February",
+ "March",
+ "April",
+ "May",
+ "June",
+ "July",
+ "August",
+ "September",
+ "October",
+ "November",
+ "December",
+ ];
+ return `${months[date.month - 1]} ${date.year}`;
+};
+
+const addMonths = (date: ical.Time, num: number) => {
+ date = date.clone();
+ if (num > 0) for (let i = 0; i < num; i++) date.adjust(getNextMonthDays(date.month, date.year), 0, 0, 0);
+ else for (let i = 0; i > num; i--) date.adjust(-getPrevMonthDays(date.month, date.year), 0, 0, 0);
+ return date;
+};
+
+const getDayClassName = (day: ical.Time, current: Variable) => {
+ const isToday = day.toJSDate().toDateString() === new Date().toDateString() ? "today" : "";
+ const numEvents = Math.min(5, Calendar.get_default().getEventsForDay(day).length);
+ return `day ${isToday} ${day.month !== current.get().month ? "dim" : ""} events-${numEvents}`;
+};
+
+const getDayTooltip = (day: ical.Time) => {
+ const events = Calendar.get_default().getEventsForDay(day);
+ if (!events.length) return "";
+ const eventsStr = events
+ .map(e => {
+ const start = GLib.DateTime.new_from_unix_local(e.startDate.toUnixTime());
+ const end = GLib.DateTime.new_from_unix_local(e.endDate.toUnixTime());
+ const sameAmPm = start.format("%P") === end.format("%P");
+ const time = `${start.format(`%-I:%M${sameAmPm ? "" : "%P"}`)} — ${end.format("%-I:%M%P")}`;
+ return `${e.event.summary.replaceAll("&", "&")} • ${time}`;
+ })
+ .join("\n");
+ return `${events.length} event${events.length === 1 ? "" : "s"}\n${eventsStr}`;
+};
+
+const Day = ({ day, shown, current }: { day: ical.Time; shown: Variable; current: Variable }) => (
+
+);
+
+const CalendarView = ({ shown, current }: { shown: Variable; current: Variable }) => (
+
+
+
+
+ {["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"].map(d => (
+
+ ))}
+
+
+ {bind(current).as(c =>
+ getCalendarLayout(c).map(r => (
+
+ {r.map(d => (
+
+ ))}
+
+ ))
+ )}
+
+
+);
+const Events = ({ shown, current }: { shown: Variable; current: Variable }) => (
+
+);
+
+export default () => {
+ const shown = Variable("calendar");
+ const current = Variable(ical.Time.now());
+
+ return (
+
+
+
+
+
+
+ );
+};
diff --git a/src/modules/sidebar/modules/upcoming.tsx b/src/modules/sidebar/modules/upcoming.tsx
index 816dff8..0023e31 100644
--- a/src/modules/sidebar/modules/upcoming.tsx
+++ b/src/modules/sidebar/modules/upcoming.tsx
@@ -4,7 +4,7 @@ import { bind, GLib } from "astal";
import { Gtk } from "astal/gtk3";
const getDateHeader = (events: IEvent[]) => {
- const date = events[0].event.startDate;
+ const date = events[0].startDate;
const isToday = date.toJSDate().toDateString() === new Date().toDateString();
return (
(isToday ? "Today • " : "") +
@@ -14,13 +14,13 @@ const getDateHeader = (events: IEvent[]) => {
};
const getEventHeader = (e: IEvent) => {
- const start = GLib.DateTime.new_from_unix_local(e.event.startDate.toUnixTime());
+ 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}`;
};
const getEventTooltip = (e: IEvent) => {
- const start = GLib.DateTime.new_from_unix_local(e.event.startDate.toUnixTime());
+ 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")}`;
@@ -31,7 +31,7 @@ const getEventTooltip = (e: IEvent) => {
const Event = (event: IEvent) => (
setupCustomTooltip(self, getEventTooltip(event), { useMarkup: true })}>
-
+
{event.event.location && }
@@ -55,7 +55,7 @@ const List = () => (
{bind(Calendar.get_default(), "upcoming").as(u =>
Object.values(u)
- .sort((a, b) => a[0].event.startDate.compare(b[0].event.startDate))
+ .sort((a, b) => a[0].startDate.compare(b[0].startDate))
.map(e => )
)}
diff --git a/src/modules/sidebar/time.tsx b/src/modules/sidebar/time.tsx
new file mode 100644
index 0000000..c7b68ba
--- /dev/null
+++ b/src/modules/sidebar/time.tsx
@@ -0,0 +1,14 @@
+import Calendar from "./modules/calendar";
+import Upcoming from "./modules/upcoming";
+
+const TimeDate = () => ;
+
+export default () => (
+
+
+
+
+
+
+
+);
--
cgit v1.2.3-freya