Extracts the media-releases fix into packages/widgets/src/common/offscreen-rows.ts and applies it to the remaining widgets whose list length is decided by remote data rather than by the tile: rssFeed, notifications and the calendar event list. Images in those lists also get loading="lazy" - the rss cards carry two each, a backdrop and a poster. The measured basis, from media-releases where the pattern was found: image requests 135 -> 55 (-59%) layout objects 8346 -> 5117 (-41%) Scope was chosen deliberately rather than applied everywhere. 26 widgets use ScrollArea, but on the measured board only two rendered more than their tile could show, and content-visibility is not free: it costs a little containment work, and on content that measures itself - charts, editors - skipping layout can be actively wrong. The widgets changed here are the ones where overdraw is a function of how much data an integration returns, so a user with a busier instance hits it even though this board does not. Chart and fixed-size widgets are deliberately left alone. Honest scope note: unlike the media-releases change, these three are NOT measured. On the test board rssFeed renders 7 nodes and the calendar's 7 rows fit their tile, so there is nothing to improve here to observe - the benefit only appears with more data than this backup has. They are typechecked and lint-clean. docs/perf/NEXT-STEPS.md tracks them alongside the media-requests change as pending verification. A duplicate `style` prop on the notifications Card was caught by typecheck and merged rather than left to override the existing colour and text-decoration styles.
89 lines
3.0 KiB
TypeScript
89 lines
3.0 KiB
TypeScript
"use client";
|
|
|
|
import { Card, Flex, Group, Image, ScrollArea, Stack, Text } from "@mantine/core";
|
|
import { IconClock } from "@tabler/icons-react";
|
|
import dayjs from "dayjs";
|
|
|
|
import type { RouterInputs } from "@homarr/api";
|
|
import { clientApi } from "@homarr/api/client";
|
|
import { useRequiredBoard } from "@homarr/boards/context";
|
|
|
|
import type { WidgetComponentProps } from "../definition";
|
|
import classes from "./component.module.scss";
|
|
import { offscreenRowStyle } from "../common/offscreen-rows";
|
|
|
|
const useLiveFeedEntries = (input: RouterInputs["widget"]["rssFeed"]["getFeeds"]) => {
|
|
const { data: feedEntries = [] } = clientApi.widget.rssFeed.getFeeds.useQuery(input);
|
|
|
|
return feedEntries;
|
|
};
|
|
|
|
export default function RssFeed({ options, width }: WidgetComponentProps<"rssFeed">) {
|
|
const feedEntries = useLiveFeedEntries({
|
|
urls: options.feedUrls,
|
|
maximumAmountPosts: typeof options.maximumAmountPosts === "number" ? options.maximumAmountPosts : 100,
|
|
});
|
|
|
|
const board = useRequiredBoard();
|
|
|
|
const languageDir = options.enableRtl ? "RTL" : "LTR";
|
|
|
|
const isNarrow = width < 128 * 3;
|
|
|
|
return (
|
|
<ScrollArea className="scroll-area-w100" w="100%" p="sm">
|
|
<Stack w={"100%"} gap="sm">
|
|
{feedEntries.map((feedEntry) => (
|
|
<Card
|
|
key={feedEntry.id}
|
|
component={"a"}
|
|
href={feedEntry.link}
|
|
style={offscreenRowStyle(96)}
|
|
radius={board.itemRadius}
|
|
target="_blank"
|
|
w="100%"
|
|
p="sm"
|
|
>
|
|
{feedEntry.enclosure !== undefined && (
|
|
<Image className={classes.backgroundImage} src={feedEntry.enclosure} alt="backdrop" loading="lazy" />
|
|
)}
|
|
|
|
<Group wrap="nowrap">
|
|
{feedEntry.enclosure !== undefined && options.showPosterImage && !isNarrow && (
|
|
<Image src={feedEntry.enclosure} alt={feedEntry.title} w={140} h={140} radius="sm" loading="lazy" />
|
|
)}
|
|
|
|
<Flex gap="sm" direction="column" w="100%">
|
|
<Text dir={languageDir} fz="sm" lh="sm" lineClamp={2}>
|
|
{feedEntry.title}
|
|
</Text>
|
|
{!options.hideDescription && feedEntry.description && (
|
|
<Text
|
|
className={feedEntry.description}
|
|
dir={languageDir}
|
|
c="dimmed"
|
|
size="sm"
|
|
lineClamp={options.textLinesClamp}
|
|
dangerouslySetInnerHTML={{ __html: feedEntry.description }}
|
|
/>
|
|
)}
|
|
|
|
{feedEntry.published && <InfoDisplay date={dayjs(feedEntry.published).fromNow()} />}
|
|
</Flex>
|
|
</Group>
|
|
</Card>
|
|
))}
|
|
</Stack>
|
|
</ScrollArea>
|
|
);
|
|
}
|
|
|
|
const InfoDisplay = ({ date }: { date: string }) => (
|
|
<Group gap={5} align={"center"}>
|
|
<IconClock size={"1rem"} color={"var(--mantine-color-dimmed)"} />
|
|
<Text size="sm" c="dimmed">
|
|
{date}
|
|
</Text>
|
|
</Group>
|
|
);
|