fix: address widget review findings
This commit is contained in:
1 parent
a3a89db727
commit
f38eb034da
20 files changed
+280
-142
No files matched your search
@@ -24,8 +24,13 @@ import { getSafeApplicationUrl, SAFE_NEW_TAB_REL } from "../common/application-u
|
||||
import { formatLocalizedTime } from "../common/locale";
|
||||
import classes from "./calendar-event-list.module.css";
|
||||
|
||||
export type CalendarEventWithSource = CalendarEvent & {
|
||||
source?: { integrationId: string; integrationName: string };
|
||||
};
|
||||
|
||||
interface CalendarEventListProps {
|
||||
events: CalendarEvent[];
|
||||
events: CalendarEventWithSource[];
|
||||
advanced?: boolean;
|
||||
fillHeight?: boolean;
|
||||
groupByDate?: boolean;
|
||||
locale?: string;
|
||||
@@ -33,6 +38,7 @@ interface CalendarEventListProps {
|
||||
|
||||
export const CalendarEventList = ({
|
||||
events,
|
||||
advanced = false,
|
||||
fillHeight = false,
|
||||
groupByDate = false,
|
||||
locale,
|
||||
@@ -70,26 +76,34 @@ export const CalendarEventList = ({
|
||||
{dateFormatter.format(groupedEvents[0]?.startDate)}
|
||||
</Text>
|
||||
<Stack mt="xs">
|
||||
<CalendarEventRows events={groupedEvents} locale={effectiveLocale} />
|
||||
<CalendarEventRows events={groupedEvents} locale={effectiveLocale} advanced={advanced} />
|
||||
</Stack>
|
||||
</Box>
|
||||
);
|
||||
})
|
||||
) : (
|
||||
<CalendarEventRows events={events} locale={effectiveLocale} />
|
||||
<CalendarEventRows events={events} locale={effectiveLocale} advanced={advanced} />
|
||||
)}
|
||||
</Stack>
|
||||
</ScrollArea>
|
||||
);
|
||||
};
|
||||
|
||||
const CalendarEventRows = ({ events, locale }: Pick<CalendarEventListProps, "events"> & { locale: string }) => {
|
||||
const CalendarEventRows = ({
|
||||
events,
|
||||
locale,
|
||||
advanced,
|
||||
}: Pick<CalendarEventListProps, "events" | "advanced"> & { locale: string }) => {
|
||||
const { colorScheme } = useMantineColorScheme();
|
||||
const t = useI18n();
|
||||
return (
|
||||
<>
|
||||
{events.map((event, eventIndex) => (
|
||||
<Group key={`event-${eventIndex}`} align={"stretch"} wrap="nowrap">
|
||||
<Group
|
||||
key={`${event.source?.integrationId ?? "event"}-${event.startDate.toISOString()}-${event.title}-${eventIndex}`}
|
||||
align={"stretch"}
|
||||
wrap="nowrap"
|
||||
>
|
||||
{event.image !== null && (
|
||||
<Box pos="relative">
|
||||
<Image
|
||||
@@ -115,13 +129,18 @@ const CalendarEventRows = ({ events, locale }: Pick<CalendarEventListProps, "eve
|
||||
<Group justify="space-between" align="start" mb="xs" wrap="wrap">
|
||||
<Stack gap={0} style={{ flex: "1 1 12rem", minWidth: 0 }}>
|
||||
{event.subTitle !== null && (
|
||||
<Text lineClamp={1} size="sm">
|
||||
<Text lineClamp={advanced ? undefined : 1} size="sm">
|
||||
{event.subTitle}
|
||||
</Text>
|
||||
)}
|
||||
<Text fw={"bold"} lineClamp={1} size="sm">
|
||||
<Text fw={"bold"} lineClamp={advanced ? undefined : 1} size="sm">
|
||||
{event.title}
|
||||
</Text>
|
||||
{advanced && event.source && (
|
||||
<Badge size="xs" variant="light" w="fit-content">
|
||||
{event.source.integrationName}
|
||||
</Badge>
|
||||
)}
|
||||
</Stack>
|
||||
{event.metadata?.type === "radarr" && (
|
||||
<Group wrap="nowrap">
|
||||
@@ -159,14 +178,14 @@ const CalendarEventRows = ({ events, locale }: Pick<CalendarEventListProps, "eve
|
||||
{event.location !== null && (
|
||||
<Group gap={4} mb={isNullOrWhitespace(event.description) ? 0 : "sm"}>
|
||||
<IconPin opacity={0.7} size={"1rem"} />
|
||||
<Text size={"xs"} c={"dimmed"} lineClamp={1}>
|
||||
<Text size={"xs"} c={"dimmed"} lineClamp={advanced ? undefined : 1}>
|
||||
{event.location}
|
||||
</Text>
|
||||
</Group>
|
||||
)}
|
||||
|
||||
{!isNullOrWhitespace(event.description) && (
|
||||
<Text size={"xs"} c={"dimmed"} lineClamp={2}>
|
||||
<Text size={"xs"} c={"dimmed"} lineClamp={advanced ? undefined : 2}>
|
||||
{event.description}
|
||||
</Text>
|
||||
)}
|
||||
|
||||
@@ -10,11 +10,11 @@ export const moveCalendarMonth = (month: Date, amount: number): Date =>
|
||||
const matchesReleaseType = (event: CalendarEvent, releaseTypes: readonly string[]) =>
|
||||
event.metadata?.type !== "radarr" || releaseTypes.includes(event.metadata.releaseType);
|
||||
|
||||
export const getCalendarAgendaEvents = (
|
||||
events: CalendarEvent[],
|
||||
export const getCalendarAgendaEvents = <TEvent extends CalendarEvent>(
|
||||
events: TEvent[],
|
||||
viewedMonth: Date,
|
||||
releaseTypes: readonly string[],
|
||||
): CalendarEvent[] => {
|
||||
): TEvent[] => {
|
||||
const monthStart = dayjs(viewedMonth).startOf("month");
|
||||
const monthEnd = monthStart.add(1, "month");
|
||||
|
||||
@@ -31,8 +31,8 @@ export const getCalendarAgendaEvents = (
|
||||
.toSorted((eventA, eventB) => eventA.startDate.getTime() - eventB.startDate.getTime());
|
||||
};
|
||||
|
||||
export const groupEventsByDate = (events: CalendarEvent[]): Map<string, CalendarEvent[]> => {
|
||||
const result = new Map<string, CalendarEvent[]>();
|
||||
export const groupEventsByDate = <TEvent extends CalendarEvent>(events: TEvent[]): Map<string, TEvent[]> => {
|
||||
const result = new Map<string, TEvent[]>();
|
||||
for (const event of events) {
|
||||
const key = toCalendarDateKey(event.startDate);
|
||||
const entries = result.get(key) ?? [];
|
||||
|
||||
@@ -90,6 +90,15 @@ describe("getCalendarAgendaEvents", () => {
|
||||
|
||||
expect(getCalendarAgendaEvents([cinema, digital], new Date(2025, 0, 1), ["inCinemas"])).toEqual([cinema]);
|
||||
});
|
||||
|
||||
test("preserves source ownership through advanced filtering", () => {
|
||||
const event = {
|
||||
...createEvent(new Date(2025, 0, 5)),
|
||||
source: { integrationId: "calendar-1", integrationName: "Family calendar" },
|
||||
};
|
||||
|
||||
expect(getCalendarAgendaEvents([event], new Date(2025, 0, 1), [])).toEqual([event]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("moveCalendarMonth", () => {
|
||||
|
||||
Reference in new issue
Block a user