fix: address final widget review findings
This commit is contained in:
1 parent
44b55a401c
commit
c09ed96978
8 files changed
+149
-37
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { Badge, Center, Group, ScrollArea, SimpleGrid, Stack, Text } from "@mantine/core";
|
||||
import { Alert, Badge, Center, Group, ScrollArea, SimpleGrid, Stack, Text } from "@mantine/core";
|
||||
import { IconAlertTriangle } from "@tabler/icons-react";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
@@ -39,7 +40,7 @@ interface TimetableWidgetInnerProps {
|
||||
}
|
||||
|
||||
const TimetableWidgetInner = ({ station, baseUrl, itemId, displayMode, width }: TimetableWidgetInnerProps) => {
|
||||
const { data: timetable } = clientApi.widget.timetable.getTimetable.useQuery({
|
||||
const { data: timetable, error } = clientApi.widget.timetable.getTimetable.useQuery({
|
||||
baseUrl,
|
||||
itemId,
|
||||
stationId: station.value,
|
||||
@@ -47,11 +48,20 @@ const TimetableWidgetInner = ({ station, baseUrl, itemId, displayMode, width }:
|
||||
});
|
||||
const t = useScopedI18n("widget.timetable");
|
||||
|
||||
if (error && timetable === undefined) throw error;
|
||||
|
||||
const entries = timetable?.entries ?? [];
|
||||
const staleWarning =
|
||||
error && timetable ? t("warning.stale", { time: dayjs(timetable.timestamp).format("HH:mm:ss") }) : undefined;
|
||||
|
||||
return (
|
||||
<Stack w="100%" h="100%" gap="xs" p="sm">
|
||||
<Text fw="bold">{t("title", { station: station.label })}</Text>
|
||||
{staleWarning && (
|
||||
<Alert role="status" color="orange" icon={<IconAlertTriangle aria-hidden size={16} />} p="xs">
|
||||
{staleWarning}
|
||||
</Alert>
|
||||
)}
|
||||
<ScrollArea style={{ flex: 1, minHeight: 0 }}>
|
||||
<SimpleGrid cols={displayMode === "advanced" && width >= 760 ? 2 : 1} spacing="xs">
|
||||
{entries.map((entry) => (
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IconBusStop } from "@tabler/icons-react";
|
||||
import { IconBusStop, IconWorldOff } from "@tabler/icons-react";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
@@ -9,6 +9,13 @@ import { optionsBuilder } from "../options";
|
||||
|
||||
export const { componentLoader, definition } = createWidgetDefinition("timetable", {
|
||||
icon: IconBusStop,
|
||||
errors: {
|
||||
BAD_REQUEST: {
|
||||
icon: IconWorldOff,
|
||||
message: (t) => t("widget.timetable.error.customSourceUnavailable"),
|
||||
hideLogsLink: true,
|
||||
},
|
||||
},
|
||||
createOptions() {
|
||||
return optionsBuilder.from((factory) => ({
|
||||
baseUrl: factory.text({
|
||||
|
||||
Reference in new issue
Block a user