From 272fb9b9b3cdcc7a90b4761cd5699c7bb700016f Mon Sep 17 00:00:00 2001 From: Kenneth Date: Sun, 15 Mar 2026 00:19:44 +0000 Subject: [PATCH] feat(caldav): add FeedItemRenderer (#74) Implement renderCalDavFeedItem using JRX JSX to render CalDAV events as FeedCard components. Bump @nym.sh/jrx to 0.2.0 for null/undefined child support. Co-authored-by: Ona --- bun.lock | 5 +- package.json | 2 +- packages/aelis-source-caldav/package.json | 1 + packages/aelis-source-caldav/src/index.ts | 1 + packages/aelis-source-caldav/src/renderer.tsx | 74 +++++++++++++++++++ packages/aelis-source-caldav/tsconfig.json | 7 ++ 6 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 packages/aelis-source-caldav/src/renderer.tsx create mode 100644 packages/aelis-source-caldav/tsconfig.json diff --git a/bun.lock b/bun.lock index a864034..660b732 100644 --- a/bun.lock +++ b/bun.lock @@ -6,7 +6,7 @@ "name": "aelis", "devDependencies": { "@json-render/core": "^0.12.1", - "@nym.sh/jrx": "^0.1.0", + "@nym.sh/jrx": "^0.2.0", "@types/bun": "latest", "oxfmt": "^0.24.0", "oxlint": "^1.39.0", @@ -152,6 +152,7 @@ "name": "@aelis/source-caldav", "version": "0.0.0", "dependencies": { + "@aelis/components": "workspace:*", "@aelis/core": "workspace:*", "ical.js": "^2.1.0", "tsdav": "^2.1.7", @@ -691,7 +692,7 @@ "@nolyfill/is-core-module": ["@nolyfill/is-core-module@1.0.39", "", {}, "sha512-nn5ozdjYQpUCZlWGuxcJY/KpxkWQs4DcbMCmKojjyrYDEAGy4Ce19NN4v5MduafTwJlbKc99UA8YhSVqq9yPZA=="], - "@nym.sh/jrx": ["@nym.sh/jrx@0.1.0", "", { "peerDependencies": { "@json-render/core": ">=0.10.0" } }, "sha512-mu6fkAP/TI9FuP8A4WMCrcucpUtWF5xBTcETnrjOtvEED9i+7sQKuoOyhJeF6QaSuUkAA/8t3Xx3kYUjcAPFbw=="], + "@nym.sh/jrx": ["@nym.sh/jrx@0.2.0", "", { "peerDependencies": { "@json-render/core": ">=0.10.0" } }, "sha512-jd7Z1Q6T21366MtSUnwCFiu6Yl1AdNc9s5m6HxeUg265P+0enZCiyyxOuHsFwvpUcSEs/2DVBsqfMptdca44lA=="], "@oclif/core": ["@oclif/core@4.8.4", "", { "dependencies": { "ansi-escapes": "^4.3.2", "ansis": "^3.17.0", "clean-stack": "^3.0.1", "cli-spinners": "^2.9.2", "debug": "^4.4.3", "ejs": "^3.1.10", "get-package-type": "^0.1.0", "indent-string": "^4.0.0", "is-wsl": "^2.2.0", "lilconfig": "^3.1.3", "minimatch": "^10.2.4", "semver": "^7.7.3", "string-width": "^4.2.3", "supports-color": "^8", "tinyglobby": "^0.2.14", "widest-line": "^3.1.0", "wordwrap": "^1.0.0", "wrap-ansi": "^7.0.0" } }, "sha512-UTAqwXJJyRvLBvosL+1uPZYSpr8lEHgUb/EVGbPXo5WZqUIBHfJ0sR2bkBEsrj00/ar4IegKxx4YK0wn2c8SQg=="], diff --git a/package.json b/package.json index 205ca86..c509849 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ }, "devDependencies": { "@json-render/core": "^0.12.1", - "@nym.sh/jrx": "^0.1.0", + "@nym.sh/jrx": "^0.2.0", "@types/bun": "latest", "oxfmt": "^0.24.0", "oxlint": "^1.39.0" diff --git a/packages/aelis-source-caldav/package.json b/packages/aelis-source-caldav/package.json index d52c9ee..917f588 100644 --- a/packages/aelis-source-caldav/package.json +++ b/packages/aelis-source-caldav/package.json @@ -9,6 +9,7 @@ "test:live": "bun run scripts/test-live.ts" }, "dependencies": { + "@aelis/components": "workspace:*", "@aelis/core": "workspace:*", "ical.js": "^2.1.0", "tsdav": "^2.1.7" diff --git a/packages/aelis-source-caldav/src/index.ts b/packages/aelis-source-caldav/src/index.ts index 2059e5a..fad9c9e 100644 --- a/packages/aelis-source-caldav/src/index.ts +++ b/packages/aelis-source-caldav/src/index.ts @@ -1,6 +1,7 @@ export { CalDavCalendarKey, type CalendarContext } from "./calendar-context.ts" export { CalDavSource, type CalDavSourceOptions } from "./caldav-source.ts" export { parseICalEvents, type ICalTimeRange } from "./ical-parser.ts" +export { renderCalDavFeedItem } from "./renderer.tsx" export { AttendeeRole, AttendeeStatus, diff --git a/packages/aelis-source-caldav/src/renderer.tsx b/packages/aelis-source-caldav/src/renderer.tsx new file mode 100644 index 0000000..4062b3a --- /dev/null +++ b/packages/aelis-source-caldav/src/renderer.tsx @@ -0,0 +1,74 @@ +/** @jsxImportSource @nym.sh/jrx */ + +import type { FeedItemRenderer } from "@aelis/core" + +import { FeedCard, SansSerifText, SerifText } from "@aelis/components" + +import type { CalDavEventData } from "./types.ts" + +import { CalDavEventStatus } from "./types.ts" + +function formatTime(date: Date): string { + const hours = date.getHours() + const minutes = date.getMinutes() + const period = hours >= 12 ? "PM" : "AM" + const h = hours % 12 || 12 + const m = minutes.toString().padStart(2, "0") + return `${h}:${m} ${period}` +} + +function formatTimeRange(data: CalDavEventData): string { + if (data.isAllDay) { + return "All day" + } + return `${formatTime(data.startDate)} – ${formatTime(data.endDate)}` +} + +function formatStatus(status: CalDavEventData["status"]): string | null { + if (status === CalDavEventStatus.Cancelled) return "Cancelled" + if (status === CalDavEventStatus.Tentative) return "Tentative" + return null +} + +export const renderCalDavFeedItem: FeedItemRenderer<"caldav-event", CalDavEventData> = (item) => { + const { data, slots } = item + const statusLabel = formatStatus(data.status) + const attendeeCount = data.attendees.length + + return ( + + {statusLabel ? : null} + + + + + + {data.calendarName ? ( + + ) : null} + + {data.location ? ( + + ) : null} + + {attendeeCount > 0 ? ( + + ) : null} + + {slots?.insight?.content ? ( + + ) : null} + + {slots?.preparation?.content ? ( + + ) : null} + + {slots?.crossSource?.content ? ( + + ) : null} + + ) +} diff --git a/packages/aelis-source-caldav/tsconfig.json b/packages/aelis-source-caldav/tsconfig.json new file mode 100644 index 0000000..8d65648 --- /dev/null +++ b/packages/aelis-source-caldav/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "jsxImportSource": "@nym.sh/jrx" + }, + "include": ["src"] +}