import { ActionIcon, Badge, Card, Center, createStyles, Flex, Group, Image, Loader, LoadingOverlay, MediaQuery, ScrollArea, Stack, Text, Title, } from '@mantine/core'; import { IconBulldozer, IconCalendarTime, IconClock, IconCopyright, IconRefresh, IconRss, IconSpeakerphone, } from '@tabler/icons'; import { useQuery } from '@tanstack/react-query'; import dayjs from 'dayjs'; import { useTranslation } from 'next-i18next'; import Link from 'next/link'; import { useState } from 'react'; import { defineWidget } from '../helper'; import { IWidget } from '../widgets'; const definition = defineWidget({ id: 'rss', icon: IconRss, options: { rssFeedUrl: { type: 'text', defaultValue: '', }, }, gridstack: { minWidth: 2, minHeight: 2, maxWidth: 12, maxHeight: 12, }, component: RssTile, }); export type IRssWidget = IWidget<(typeof definition)['id'], typeof definition>; interface RssTileProps { widget: IRssWidget; } const useGetRssFeed = (feedUrl: string) => useQuery({ queryKey: ['rss-feed', feedUrl], queryFn: async () => { const response = await fetch('/api/modules/rss'); return response.json(); }, }); function RssTile({ widget }: RssTileProps) { const { t } = useTranslation('modules/rss'); const { data, isLoading, isFetching, isError, refetch } = useGetRssFeed( widget.properties.rssFeedUrl ); const { classes } = useStyles(); const [loadingOverlayVisible, setLoadingOverlayVisible] = useState(false); function formatDate(input: string): string { // Parse the input date as a local date const inputDate = dayjs(new Date(input)); const now = dayjs(); // Current date and time const diffInHours = now.diff(inputDate, 'hour'); const diffInDays = now.diff(inputDate, 'day'); // If the input date is more than 2 weeks ago, return the formatted date if (diffInDays > 14) { return inputDate.format('DD MMM YYYY'); } if (diffInDays >= 1) { return `${diffInDays} days ago`; } return `${diffInHours} hours ago`; } if (!data || isLoading) { return (