Added lidarr events to calendar
Signed-off-by: Denis Papec <denis.papec@gmail.com>
This commit is contained in:
parent
449b957b24
commit
c4cadea317
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}`}} />
|
||||
}
|
||||
@ -14,6 +14,10 @@ const widget = {
|
||||
"queue/status": {
|
||||
endpoint: "queue/status",
|
||||
},
|
||||
calendar: {
|
||||
endpoint: "calendar",
|
||||
params: ["start", "end", "unmonitored", "includeArtist"],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user