mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-21 17:41:18 +00:00
Compare commits
5 Commits
feat/calda
...
feat/tfl-r
| Author | SHA1 | Date | |
|---|---|---|---|
|
78fc028ee5
|
|||
|
adbc2c17ac
|
|||
|
f7f91316f1
|
|||
|
1dd14da71d
|
|||
| ec083c3c77 |
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -21,4 +21,4 @@ jobs:
|
|||||||
run: bun install --frozen-lockfile
|
run: bun install --frozen-lockfile
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: bun test
|
run: bun run test
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import Feather from "@expo/vector-icons/Feather"
|
|
||||||
import { View } from "react-native"
|
import { View } from "react-native"
|
||||||
import tw from "twrnc"
|
import tw from "twrnc"
|
||||||
|
|
||||||
@@ -15,22 +14,22 @@ function ButtonShowcase() {
|
|||||||
<Button
|
<Button
|
||||||
style={tw`self-start`}
|
style={tw`self-start`}
|
||||||
label="Add item"
|
label="Add item"
|
||||||
leadingIcon={<Feather name="plus" size={18} color="#e7e5e4" />}
|
leadingIcon={<Button.Icon name="plus" />}
|
||||||
/>
|
/>
|
||||||
</Section>
|
</Section>
|
||||||
<Section title="Trailing icon">
|
<Section title="Trailing icon">
|
||||||
<Button
|
<Button
|
||||||
style={tw`self-start`}
|
style={tw`self-start`}
|
||||||
label="Next"
|
label="Next"
|
||||||
trailingIcon={<Feather name="arrow-right" size={18} color="#e7e5e4" />}
|
trailingIcon={<Button.Icon name="arrow-right" />}
|
||||||
/>
|
/>
|
||||||
</Section>
|
</Section>
|
||||||
<Section title="Both icons">
|
<Section title="Both icons">
|
||||||
<Button
|
<Button
|
||||||
style={tw`self-start`}
|
style={tw`self-start`}
|
||||||
label="Download"
|
label="Download"
|
||||||
leadingIcon={<Feather name="download" size={18} color="#e7e5e4" />}
|
leadingIcon={<Button.Icon name="download" />}
|
||||||
trailingIcon={<Feather name="chevron-down" size={18} color="#e7e5e4" />}
|
trailingIcon={<Button.Icon name="chevron-down" />}
|
||||||
/>
|
/>
|
||||||
</Section>
|
</Section>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -1,8 +1,19 @@
|
|||||||
|
import Feather from "@expo/vector-icons/Feather"
|
||||||
import { type PressableProps, Pressable, View } from "react-native"
|
import { type PressableProps, Pressable, View } from "react-native"
|
||||||
import tw from "twrnc"
|
import tw from "twrnc"
|
||||||
|
|
||||||
import { SansSerifText } from "./sans-serif-text"
|
import { SansSerifText } from "./sans-serif-text"
|
||||||
|
|
||||||
|
type FeatherIconName = React.ComponentProps<typeof Feather>["name"]
|
||||||
|
|
||||||
|
type ButtonIconProps = {
|
||||||
|
name: FeatherIconName
|
||||||
|
}
|
||||||
|
|
||||||
|
function ButtonIcon({ name }: ButtonIconProps) {
|
||||||
|
return <Feather name={name} size={18} color={tw.color("text-stone-100 dark:text-stone-200")} />
|
||||||
|
}
|
||||||
|
|
||||||
type ButtonProps = Omit<PressableProps, "children"> & {
|
type ButtonProps = Omit<PressableProps, "children"> & {
|
||||||
label: string
|
label: string
|
||||||
leadingIcon?: React.ReactNode
|
leadingIcon?: React.ReactNode
|
||||||
@@ -12,7 +23,7 @@ type ButtonProps = Omit<PressableProps, "children"> & {
|
|||||||
export function Button({ style, label, leadingIcon, trailingIcon, ...props }: ButtonProps) {
|
export function Button({ style, label, leadingIcon, trailingIcon, ...props }: ButtonProps) {
|
||||||
const hasIcons = leadingIcon != null || trailingIcon != null
|
const hasIcons = leadingIcon != null || trailingIcon != null
|
||||||
|
|
||||||
const textElement = <SansSerifText style={tw`text-stone-200 font-medium`}>{label}</SansSerifText>
|
const textElement = <SansSerifText style={tw`text-stone-100 dark:text-stone-200 font-medium`}>{label}</SansSerifText>
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Pressable style={[tw`rounded-full bg-teal-600 px-4 py-3 w-fit`, style]} {...props}>
|
<Pressable style={[tw`rounded-full bg-teal-600 px-4 py-3 w-fit`, style]} {...props}>
|
||||||
@@ -28,3 +39,5 @@ export function Button({ style, label, leadingIcon, trailingIcon, ...props }: Bu
|
|||||||
</Pressable>
|
</Pressable>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Button.Icon = ButtonIcon
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import Feather from "@expo/vector-icons/Feather"
|
|
||||||
import { defineRegistry } from "@json-render/react-native"
|
import { defineRegistry } from "@json-render/react-native"
|
||||||
import { View } from "react-native"
|
import { View } from "react-native"
|
||||||
import tw from "twrnc"
|
import tw from "twrnc"
|
||||||
@@ -11,10 +10,7 @@ import { SerifText } from "@/components/ui/serif-text"
|
|||||||
|
|
||||||
import { catalog } from "./catalog"
|
import { catalog } from "./catalog"
|
||||||
|
|
||||||
function featherIcon(name: string | null | undefined) {
|
type ButtonIconName = React.ComponentProps<typeof Button.Icon>["name"]
|
||||||
if (!name) return undefined
|
|
||||||
return <Feather name={name as React.ComponentProps<typeof Feather>["name"]} size={18} color="#e7e5e4" />
|
|
||||||
}
|
|
||||||
|
|
||||||
export const { registry } = defineRegistry(catalog, {
|
export const { registry } = defineRegistry(catalog, {
|
||||||
components: {
|
components: {
|
||||||
@@ -22,8 +18,8 @@ export const { registry } = defineRegistry(catalog, {
|
|||||||
Button: ({ props, emit }) => (
|
Button: ({ props, emit }) => (
|
||||||
<Button
|
<Button
|
||||||
label={props.label}
|
label={props.label}
|
||||||
leadingIcon={featherIcon(props.leadingIcon)}
|
leadingIcon={props.leadingIcon ? <Button.Icon name={props.leadingIcon as ButtonIconName} /> : undefined}
|
||||||
trailingIcon={featherIcon(props.trailingIcon)}
|
trailingIcon={props.trailingIcon ? <Button.Icon name={props.trailingIcon as ButtonIconName} /> : undefined}
|
||||||
onPress={() => emit("press")}
|
onPress={() => emit("press")}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
|
|||||||
6
bun.lock
6
bun.lock
@@ -152,7 +152,6 @@
|
|||||||
"name": "@aelis/source-caldav",
|
"name": "@aelis/source-caldav",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aelis/components": "workspace:*",
|
|
||||||
"@aelis/core": "workspace:*",
|
"@aelis/core": "workspace:*",
|
||||||
"ical.js": "^2.1.0",
|
"ical.js": "^2.1.0",
|
||||||
"tsdav": "^2.1.7",
|
"tsdav": "^2.1.7",
|
||||||
@@ -178,10 +177,15 @@
|
|||||||
"name": "@aelis/source-tfl",
|
"name": "@aelis/source-tfl",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@aelis/components": "workspace:*",
|
||||||
"@aelis/core": "workspace:*",
|
"@aelis/core": "workspace:*",
|
||||||
"@aelis/source-location": "workspace:*",
|
"@aelis/source-location": "workspace:*",
|
||||||
"arktype": "^2.1.0",
|
"arktype": "^2.1.0",
|
||||||
},
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@json-render/core": "*",
|
||||||
|
"@nym.sh/jrx": "*",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"packages/aelis-source-weatherkit": {
|
"packages/aelis-source-weatherkit": {
|
||||||
"name": "@aelis/source-weatherkit",
|
"name": "@aelis/source-weatherkit",
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
"test:live": "bun run scripts/test-live.ts"
|
"test:live": "bun run scripts/test-live.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aelis/components": "workspace:*",
|
|
||||||
"@aelis/core": "workspace:*",
|
"@aelis/core": "workspace:*",
|
||||||
"ical.js": "^2.1.0",
|
"ical.js": "^2.1.0",
|
||||||
"tsdav": "^2.1.7"
|
"tsdav": "^2.1.7"
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
export { CalDavCalendarKey, type CalendarContext } from "./calendar-context.ts"
|
export { CalDavCalendarKey, type CalendarContext } from "./calendar-context.ts"
|
||||||
export { CalDavSource, type CalDavSourceOptions } from "./caldav-source.ts"
|
export { CalDavSource, type CalDavSourceOptions } from "./caldav-source.ts"
|
||||||
export { parseICalEvents, type ICalTimeRange } from "./ical-parser.ts"
|
export { parseICalEvents, type ICalTimeRange } from "./ical-parser.ts"
|
||||||
export { renderCalDavFeedItem } from "./renderer.tsx"
|
|
||||||
export {
|
export {
|
||||||
AttendeeRole,
|
AttendeeRole,
|
||||||
AttendeeStatus,
|
AttendeeStatus,
|
||||||
|
|||||||
@@ -1,74 +0,0 @@
|
|||||||
/** @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 (
|
|
||||||
<FeedCard>
|
|
||||||
{statusLabel ? <SansSerifText content={statusLabel} style="text-xs uppercase" /> : null}
|
|
||||||
|
|
||||||
<SerifText content={data.title} style="text-lg" />
|
|
||||||
|
|
||||||
<SansSerifText content={formatTimeRange(data)} style="text-sm" />
|
|
||||||
|
|
||||||
{data.calendarName ? (
|
|
||||||
<SansSerifText content={data.calendarName} style="text-sm text-secondary" />
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
{data.location ? (
|
|
||||||
<SansSerifText content={data.location} style="text-sm text-secondary" />
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
{attendeeCount > 0 ? (
|
|
||||||
<SansSerifText
|
|
||||||
content={`${attendeeCount} attendee${attendeeCount === 1 ? "" : "s"}`}
|
|
||||||
style="text-sm text-secondary"
|
|
||||||
/>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
{slots?.insight?.content ? (
|
|
||||||
<SansSerifText content={slots.insight.content} style="text-sm" />
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
{slots?.preparation?.content ? (
|
|
||||||
<SansSerifText content={slots.preparation.content} style="text-sm" />
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
{slots?.crossSource?.content ? (
|
|
||||||
<SansSerifText content={slots.crossSource.content} style="text-sm" />
|
|
||||||
) : null}
|
|
||||||
</FeedCard>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,12 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aelis/core": "workspace:*",
|
"@aelis/core": "workspace:*",
|
||||||
|
"@aelis/components": "workspace:*",
|
||||||
"@aelis/source-location": "workspace:*",
|
"@aelis/source-location": "workspace:*",
|
||||||
"arktype": "^2.1.0"
|
"arktype": "^2.1.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@json-render/core": "*",
|
||||||
|
"@nym.sh/jrx": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,3 +11,4 @@ export {
|
|||||||
type TflLineStatus,
|
type TflLineStatus,
|
||||||
type TflSourceOptions,
|
type TflSourceOptions,
|
||||||
} from "./types.ts"
|
} from "./types.ts"
|
||||||
|
export { renderTflAlert } from "./renderer.tsx"
|
||||||
|
|||||||
103
packages/aelis-source-tfl/src/renderer.test.tsx
Normal file
103
packages/aelis-source-tfl/src/renderer.test.tsx
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
/** @jsxImportSource @nym.sh/jrx */
|
||||||
|
import { render } from "@nym.sh/jrx"
|
||||||
|
import { describe, expect, test } from "bun:test"
|
||||||
|
|
||||||
|
import type { TflAlertFeedItem } from "./types.ts"
|
||||||
|
|
||||||
|
import { renderTflAlert } from "./renderer.tsx"
|
||||||
|
|
||||||
|
function makeItem(overrides: Partial<TflAlertFeedItem["data"]> = {}): TflAlertFeedItem {
|
||||||
|
return {
|
||||||
|
id: "tfl-alert-northern-minor-delays",
|
||||||
|
type: "tfl-alert",
|
||||||
|
timestamp: new Date("2026-01-15T12:00:00Z"),
|
||||||
|
data: {
|
||||||
|
line: "northern",
|
||||||
|
lineName: "Northern",
|
||||||
|
severity: "minor-delays",
|
||||||
|
description: "Minor delays due to signal failure",
|
||||||
|
closestStationDistance: null,
|
||||||
|
...overrides,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("renderTflAlert", () => {
|
||||||
|
test("renders a FeedCard with title and description", () => {
|
||||||
|
const node = renderTflAlert(makeItem())
|
||||||
|
const spec = render(node)
|
||||||
|
|
||||||
|
const root = spec.elements[spec.root]!
|
||||||
|
expect(root.type).toBe("FeedCard")
|
||||||
|
expect(root.children!.length).toBeGreaterThanOrEqual(2)
|
||||||
|
|
||||||
|
const title = spec.elements[root.children![0]!]!
|
||||||
|
expect(title.type).toBe("SansSerifText")
|
||||||
|
expect(title.props.content).toBe("Northern · Minor delays")
|
||||||
|
|
||||||
|
const body = spec.elements[root.children![1]!]!
|
||||||
|
expect(body.type).toBe("SansSerifText")
|
||||||
|
expect(body.props.content).toBe("Minor delays due to signal failure")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("shows nearest station distance when available", () => {
|
||||||
|
const node = renderTflAlert(makeItem({ closestStationDistance: 0.35 }))
|
||||||
|
const spec = render(node)
|
||||||
|
|
||||||
|
const root = spec.elements[spec.root]!
|
||||||
|
expect(root.children).toHaveLength(3)
|
||||||
|
|
||||||
|
const caption = spec.elements[root.children![2]!]!
|
||||||
|
expect(caption.type).toBe("SansSerifText")
|
||||||
|
expect(caption.props.content).toBe("Nearest station: 350m away")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("formats distance in km when >= 1km", () => {
|
||||||
|
const node = renderTflAlert(makeItem({ closestStationDistance: 2.456 }))
|
||||||
|
const spec = render(node)
|
||||||
|
|
||||||
|
const root = spec.elements[spec.root]!
|
||||||
|
const caption = spec.elements[root.children![2]!]!
|
||||||
|
expect(caption.props.content).toBe("Nearest station: 2.5km away")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("formats near-1km boundary as km not meters", () => {
|
||||||
|
const node = renderTflAlert(makeItem({ closestStationDistance: 0.9999 }))
|
||||||
|
const spec = render(node)
|
||||||
|
|
||||||
|
const root = spec.elements[spec.root]!
|
||||||
|
const caption = spec.elements[root.children![2]!]!
|
||||||
|
expect(caption.props.content).toBe("Nearest station: 1.0km away")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("omits station distance when null", () => {
|
||||||
|
const node = renderTflAlert(makeItem({ closestStationDistance: null }))
|
||||||
|
const spec = render(node)
|
||||||
|
|
||||||
|
const root = spec.elements[spec.root]!
|
||||||
|
// Title + body only, no caption (empty fragment doesn't produce a child)
|
||||||
|
const children = root.children!.filter((key) => {
|
||||||
|
const el = spec.elements[key]
|
||||||
|
return el && el.type !== "Fragment"
|
||||||
|
})
|
||||||
|
expect(children).toHaveLength(2)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("renders closure severity label", () => {
|
||||||
|
const node = renderTflAlert(makeItem({ severity: "closure", lineName: "Central" }))
|
||||||
|
const spec = render(node)
|
||||||
|
|
||||||
|
const root = spec.elements[spec.root]!
|
||||||
|
const title = spec.elements[root.children![0]!]!
|
||||||
|
expect(title.props.content).toBe("Central · Closed")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("renders major delays severity label", () => {
|
||||||
|
const node = renderTflAlert(makeItem({ severity: "major-delays", lineName: "Jubilee" }))
|
||||||
|
const spec = render(node)
|
||||||
|
|
||||||
|
const root = spec.elements[spec.root]!
|
||||||
|
const title = spec.elements[root.children![0]!]!
|
||||||
|
expect(title.props.content).toBe("Jubilee · Major delays")
|
||||||
|
})
|
||||||
|
})
|
||||||
40
packages/aelis-source-tfl/src/renderer.tsx
Normal file
40
packages/aelis-source-tfl/src/renderer.tsx
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/** @jsxImportSource @nym.sh/jrx */
|
||||||
|
import type { FeedItemRenderer } from "@aelis/core"
|
||||||
|
|
||||||
|
import { FeedCard, SansSerifText } from "@aelis/components"
|
||||||
|
|
||||||
|
import type { TflAlertData } from "./types.ts"
|
||||||
|
|
||||||
|
import { TflAlertSeverity } from "./types.ts"
|
||||||
|
|
||||||
|
const SEVERITY_LABEL: Record<TflAlertSeverity, string> = {
|
||||||
|
[TflAlertSeverity.Closure]: "Closed",
|
||||||
|
[TflAlertSeverity.MajorDelays]: "Major delays",
|
||||||
|
[TflAlertSeverity.MinorDelays]: "Minor delays",
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDistance(km: number): string {
|
||||||
|
const meters = Math.round(km * 1000)
|
||||||
|
if (meters < 1000) {
|
||||||
|
return `${meters}m away`
|
||||||
|
}
|
||||||
|
return `${(meters / 1000).toFixed(1)}km away`
|
||||||
|
}
|
||||||
|
|
||||||
|
export const renderTflAlert: FeedItemRenderer<"tfl-alert", TflAlertData> = (item) => {
|
||||||
|
const { lineName, severity, description, closestStationDistance } = item.data
|
||||||
|
const severityLabel = SEVERITY_LABEL[severity]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FeedCard>
|
||||||
|
<SansSerifText content={`${lineName} · ${severityLabel}`} style="text-base font-semibold" />
|
||||||
|
<SansSerifText content={description} style="text-sm" />
|
||||||
|
{closestStationDistance !== null ? (
|
||||||
|
<SansSerifText
|
||||||
|
content={`Nearest station: ${formatDistance(closestStationDistance)}`}
|
||||||
|
style="text-xs text-stone-500"
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</FeedCard>
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user