Add option to manually edit the refresh interval

This commit is contained in:
ajnart
2023-04-05 14:53:18 +09:00
parent 9d51e2ce52
commit 31a80f5588
3 changed files with 21 additions and 8 deletions

View File

@@ -7,14 +7,17 @@
"rssFeedUrl": {
"label": "RSS feeds urls",
"description": "The urls of the RSS feeds you want to display from."
},
"refreshInterval": {
"label": "Refresh interval (in seconds)"
}
}
},
"card": {
"errors": {
"general": {
"title": "Unable to retrieve RSS feed",
"text": "There was a problem reaching out the RSS feed. Make sure that you have correctly configured the RSS feed using a valid URL. URLs should match the official specification. After updating the feed, you may need to refresh the dashboard."
},
"card": {
"errors": {
"general": {
"title": "Unable to retrieve RSS feed",
"text": "There was a problem reaching out the RSS feed. Make sure that you have correctly configured the RSS feed using a valid URL. URLs should match the official specification. After updating the feed, you may need to refresh the dashboard."
}
}
}
}

View File

@@ -184,6 +184,7 @@ const WidgetOptionTypeSwitch: FC<{
case 'slider':
return (
<Stack spacing="xs">
<Text>{t(`descriptor.settings.${key}.label`)}</Text>
<Slider
color={primaryColor}
label={value}

View File

@@ -32,6 +32,13 @@ const definition = defineWidget({
type: 'multiple-text',
defaultValue: ['https://github.com/ajnart/homarr/tags.atom'],
},
refreshInterval: {
type: 'slider',
defaultValue: 60,
min: 30,
max: 300,
step: 30,
},
},
gridstack: {
minWidth: 2,
@@ -48,11 +55,12 @@ interface RssTileProps {
widget: IRssWidget;
}
export const useGetRssFeeds = (feedUrls: string[], widgetId: string) =>
export const useGetRssFeeds = (feedUrls: string[], refreshInterval: number, widgetId: string) =>
useQuery({
queryKey: ['rss-feeds', feedUrls],
// Cache the results for 24 hours
cacheTime: 1000 * 60 * 60 * 24,
staleTime: 1000 * refreshInterval,
queryFn: async () => {
const responses = await Promise.all(
feedUrls.map((feedUrl) =>
@@ -69,6 +77,7 @@ function RssTile({ widget }: RssTileProps) {
const { t } = useTranslation('modules/rss');
const { data, isLoading, isFetching, isError, refetch } = useGetRssFeeds(
widget.properties.rssFeedUrl,
widget.properties.refreshInterval,
widget.id
);
const { classes } = useStyles();