mirror of
https://github.com/gethomepage/homepage.git
synced 2025-12-24 05:48:08 +08:00
Feature: calendar widget (#2077)
* Implemented calendar Signed-off-by: Denis Papec <denis.papec@gmail.com> * Added lidarr events to calendar Signed-off-by: Denis Papec <denis.papec@gmail.com> * Added radarr events to calendar Signed-off-by: Denis Papec <denis.papec@gmail.com> * Added readarr events to calendar Signed-off-by: Denis Papec <denis.papec@gmail.com> * Added sonarr events to calendar Signed-off-by: Denis Papec <denis.papec@gmail.com> * fix sonarr series title * integrations * fix bad setstate call * handle user sets includeSeries: false for sonarr * Translate radarr release strings * Support all widths * readarr get author * Finished first day in week config Signed-off-by: Denis Papec <denis.papec@gmail.com> --------- Signed-off-by: Denis Papec <denis.papec@gmail.com> Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
36
src/widgets/calendar/integrations/lidarr.jsx
Normal file
36
src/widgets/calendar/integrations/lidarr.jsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import { DateTime } from "luxon";
|
||||
import { useContext, useEffect } from "react";
|
||||
|
||||
import useWidgetAPI from "../../../utils/proxy/use-widget-api";
|
||||
import { EventContext } from "../../../utils/contexts/calendar";
|
||||
import Error from "../../../components/services/widget/error";
|
||||
|
||||
export default function Integration({ config, params }) {
|
||||
const { setEvents } = useContext(EventContext);
|
||||
const { data: lidarrData, error: lidarrError } = useWidgetAPI(config, "calendar",
|
||||
{ ...params, includeArtist: 'false', ...config?.params ?? {} }
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!lidarrData || lidarrError) {
|
||||
return;
|
||||
}
|
||||
|
||||
const eventsToAdd = {};
|
||||
|
||||
lidarrData?.forEach(event => {
|
||||
const title = `${event.artist.artistName} - ${event.title}`;
|
||||
|
||||
eventsToAdd[title] = {
|
||||
title,
|
||||
date: DateTime.fromISO(event.releaseDate),
|
||||
color: config?.color ?? 'green'
|
||||
};
|
||||
})
|
||||
|
||||
setEvents((prevEvents) => ({ ...prevEvents, ...eventsToAdd }));
|
||||
}, [lidarrData, lidarrError, config, setEvents]);
|
||||
|
||||
const error = lidarrError ?? lidarrData?.error;
|
||||
return error && <Error error={{ message: `${config.type}: ${error.message ?? error}`}} />
|
||||
}
|
||||
Reference in New Issue
Block a user