mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 07:25:48 +01:00
Merge branch 'dev' into HEAD
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -25,6 +25,7 @@ yarn-debug.log*
|
|||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
|
|
||||||
# local env files
|
# local env files
|
||||||
|
.env
|
||||||
.env.local
|
.env.local
|
||||||
.env.development.local
|
.env.development.local
|
||||||
.env.test.local
|
.env.test.local
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ const usePrepareGridstack = () => {
|
|||||||
}, [width]);
|
}, [width]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isReady: !!mainAreaWidth,
|
isReady: Boolean(mainAreaWidth),
|
||||||
mainAreaRef,
|
mainAreaRef,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export const useGetUsenetInfo = (params: UsenetInfoRequestParams) =>
|
|||||||
refetchInterval: POLLING_INTERVAL,
|
refetchInterval: POLLING_INTERVAL,
|
||||||
keepPreviousData: true,
|
keepPreviousData: true,
|
||||||
retry: 2,
|
retry: 2,
|
||||||
enabled: !!params.appId,
|
enabled: Boolean(params.appId),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
import { useQuery } from '@tanstack/react-query';
|
|
||||||
|
|
||||||
export const useGetRssFeed = (feedUrl: string, widgetId: string) =>
|
|
||||||
useQuery({
|
|
||||||
queryKey: ['rss-feed', feedUrl],
|
|
||||||
queryFn: async () => {
|
|
||||||
const response = await fetch(`/api/modules/rss?widgetId=${widgetId}`);
|
|
||||||
return response.json();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -9,7 +9,12 @@ export default class DockerSingleton extends Docker {
|
|||||||
|
|
||||||
public static getInstance(): DockerSingleton {
|
public static getInstance(): DockerSingleton {
|
||||||
if (!DockerSingleton.dockerInstance) {
|
if (!DockerSingleton.dockerInstance) {
|
||||||
DockerSingleton.dockerInstance = new DockerSingleton();
|
DockerSingleton.dockerInstance = new Docker({
|
||||||
|
// If env variable DOCKER_HOST is not set, it will use the default socket
|
||||||
|
...(process.env.DOCKER_HOST && { host: process.env.DOCKER_HOST }),
|
||||||
|
// Same thing for docker port
|
||||||
|
...(process.env.DOCKER_PORT && { port: process.env.DOCKER_PORT }),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return DockerSingleton.dockerInstance;
|
return DockerSingleton.dockerInstance;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import {
|
|||||||
Stack,
|
Stack,
|
||||||
Text,
|
Text,
|
||||||
Title,
|
Title,
|
||||||
UnstyledButton,
|
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import {
|
import {
|
||||||
IconBulldozer,
|
IconBulldozer,
|
||||||
@@ -25,11 +24,11 @@ import {
|
|||||||
IconRss,
|
IconRss,
|
||||||
IconSpeakerphone,
|
IconSpeakerphone,
|
||||||
} from '@tabler/icons';
|
} from '@tabler/icons';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
import { useTranslation } from 'next-i18next';
|
import { useTranslation } from 'next-i18next';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useGetRssFeed } from '../../hooks/widgets/rss/useGetRssFeed';
|
|
||||||
import { sleep } from '../../tools/client/time';
|
|
||||||
import { defineWidget } from '../helper';
|
import { defineWidget } from '../helper';
|
||||||
import { IWidget } from '../widgets';
|
import { IWidget } from '../widgets';
|
||||||
|
|
||||||
@@ -57,6 +56,15 @@ interface RssTileProps {
|
|||||||
widget: IRssWidget;
|
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) {
|
function RssTile({ widget }: RssTileProps) {
|
||||||
const { t } = useTranslation('modules/rss');
|
const { t } = useTranslation('modules/rss');
|
||||||
const { data, isLoading, isFetching, isError, refetch } = useGetRssFeed(
|
const { data, isLoading, isFetching, isError, refetch } = useGetRssFeed(
|
||||||
@@ -66,9 +74,21 @@ function RssTile({ widget }: RssTileProps) {
|
|||||||
const { classes } = useStyles();
|
const { classes } = useStyles();
|
||||||
const [loadingOverlayVisible, setLoadingOverlayVisible] = useState(false);
|
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
|
||||||
|
|
||||||
|
// The difference between the input date and now
|
||||||
|
const difference = now.diff(inputDate, 'ms');
|
||||||
|
const duration = dayjs.duration(difference, 'ms');
|
||||||
|
const humanizedDuration = duration.humanize();
|
||||||
|
return `${humanizedDuration} ago`;
|
||||||
|
}
|
||||||
|
|
||||||
if (!data || isLoading) {
|
if (!data || isLoading) {
|
||||||
return (
|
return (
|
||||||
<Center>
|
<Center h="100%">
|
||||||
<Loader />
|
<Loader />
|
||||||
</Center>
|
</Center>
|
||||||
);
|
);
|
||||||
@@ -88,32 +108,8 @@ function RssTile({ widget }: RssTileProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack h="100%">
|
<Stack h="100%">
|
||||||
<LoadingOverlay visible={loadingOverlayVisible} />
|
<LoadingOverlay visible={isFetching} />
|
||||||
<Flex gap="md">
|
<Flex align="end">{data.feed.title && <Title order={5}>{data.feed.title}</Title>}</Flex>
|
||||||
{data.feed.image ? (
|
|
||||||
<Image
|
|
||||||
src={data.feed.image.url}
|
|
||||||
alt={data.feed.image.title}
|
|
||||||
width="auto"
|
|
||||||
height={40}
|
|
||||||
mx="auto"
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<Title order={6}>{data.feed.title}</Title>
|
|
||||||
)}
|
|
||||||
<UnstyledButton
|
|
||||||
onClick={async () => {
|
|
||||||
setLoadingOverlayVisible(true);
|
|
||||||
await Promise.all([sleep(1500), refetch()]);
|
|
||||||
setLoadingOverlayVisible(false);
|
|
||||||
}}
|
|
||||||
disabled={isFetching || isLoading}
|
|
||||||
>
|
|
||||||
<ActionIcon>
|
|
||||||
<IconRefresh />
|
|
||||||
</ActionIcon>
|
|
||||||
</UnstyledButton>
|
|
||||||
</Flex>
|
|
||||||
<ScrollArea className="scroll-area-w100" w="100%">
|
<ScrollArea className="scroll-area-w100" w="100%">
|
||||||
<Stack w="100%" spacing="xs">
|
<Stack w="100%" spacing="xs">
|
||||||
{data.feed.items.map((item: any, index: number) => (
|
{data.feed.items.map((item: any, index: number) => (
|
||||||
@@ -151,7 +147,7 @@ function RssTile({ widget }: RssTileProps) {
|
|||||||
{item.categories && (
|
{item.categories && (
|
||||||
<Flex gap="xs" wrap="wrap" h={20} style={{ overflow: 'hidden' }}>
|
<Flex gap="xs" wrap="wrap" h={20} style={{ overflow: 'hidden' }}>
|
||||||
{item.categories.map((category: any, categoryIndex: number) => (
|
{item.categories.map((category: any, categoryIndex: number) => (
|
||||||
<Badge key={categoryIndex}>{category._}</Badge>
|
<Badge key={categoryIndex}>{category}</Badge>
|
||||||
))}
|
))}
|
||||||
</Flex>
|
</Flex>
|
||||||
)}
|
)}
|
||||||
@@ -161,7 +157,7 @@ function RssTile({ widget }: RssTileProps) {
|
|||||||
{item.content}
|
{item.content}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
{item.pubDate && <TimeDisplay date={item.pubDate} />}
|
{item.pubDate && <TimeDisplay date={formatDate(item.pubDate)} />}
|
||||||
</Flex>
|
</Flex>
|
||||||
</Flex>
|
</Flex>
|
||||||
</Card>
|
</Card>
|
||||||
@@ -170,23 +166,27 @@ function RssTile({ widget }: RssTileProps) {
|
|||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
|
|
||||||
<Flex wrap="wrap" columnGap="md">
|
<Flex wrap="wrap" columnGap="md">
|
||||||
<Group spacing="sm">
|
{data.feed.copyright && (
|
||||||
<IconCopyright size={14} />
|
<Group spacing="sm">
|
||||||
<Text color="dimmed" size="sm">
|
<IconCopyright size={14} />
|
||||||
{data.feed.copyright}
|
<Text color="dimmed" size="sm">
|
||||||
</Text>
|
{data.feed.copyright}
|
||||||
</Group>
|
</Text>
|
||||||
<Group>
|
</Group>
|
||||||
<IconCalendarTime size={14} />
|
)}
|
||||||
<Text color="dimmed" size="sm">
|
{data.feed.pubDate && (
|
||||||
{data.feed.pubDate}
|
<Group>
|
||||||
</Text>
|
<IconCalendarTime size={14} />
|
||||||
</Group>
|
<Text color="dimmed" size="sm">
|
||||||
|
{data.feed.pubDate}
|
||||||
|
</Text>
|
||||||
|
</Group>
|
||||||
|
)}
|
||||||
{data.feed.lastBuildDate && (
|
{data.feed.lastBuildDate && (
|
||||||
<Group>
|
<Group>
|
||||||
<IconBulldozer size={14} />
|
<IconBulldozer size={14} />
|
||||||
<Text color="dimmed" size="sm">
|
<Text color="dimmed" size="sm">
|
||||||
{data.feed.lastBuildDate}
|
{formatDate(data.feed.lastBuildDate)}
|
||||||
</Text>
|
</Text>
|
||||||
</Group>
|
</Group>
|
||||||
)}
|
)}
|
||||||
@@ -205,6 +205,25 @@ function RssTile({ widget }: RssTileProps) {
|
|||||||
</Text>
|
</Text>
|
||||||
</Group>
|
</Group>
|
||||||
)}
|
)}
|
||||||
|
<ActionIcon
|
||||||
|
size="sm"
|
||||||
|
radius="xl"
|
||||||
|
pos="absolute"
|
||||||
|
right={10}
|
||||||
|
onClick={() => refetch()}
|
||||||
|
bottom={10}
|
||||||
|
styles={{
|
||||||
|
root: {
|
||||||
|
borderColor: 'red',
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{data.feed.image ? (
|
||||||
|
<Image src={data.feed.image.url} alt={data.feed.image.title} mx="auto" />
|
||||||
|
) : (
|
||||||
|
<IconRefresh />
|
||||||
|
)}
|
||||||
|
</ActionIcon>
|
||||||
</Flex>
|
</Flex>
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export const useWeatherForCity = (cityName: string) => {
|
|||||||
const weatherQuery = useQuery({
|
const weatherQuery = useQuery({
|
||||||
queryKey: ['weather', { cityName }],
|
queryKey: ['weather', { cityName }],
|
||||||
queryFn: () => fetchWeather(city?.results[0]),
|
queryFn: () => fetchWeather(city?.results[0]),
|
||||||
enabled: !!city,
|
enabled: Boolean(city),
|
||||||
cacheTime: 1000 * 60 * 60 * 6, // the weather is cached for 6 hours
|
cacheTime: 1000 * 60 * 60 * 6, // the weather is cached for 6 hours
|
||||||
staleTime: 1000 * 60 * 5, // the weather is considered stale after 5 minutes
|
staleTime: 1000 * 60 * 5, // the weather is considered stale after 5 minutes
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user