Added radarr events to calendar
Signed-off-by: Denis Papec <denis.papec@gmail.com>
This commit is contained in:
parent
c4cadea317
commit
7b7d0e0345
47
src/widgets/calendar/integrations/radarr.jsx
Normal file
47
src/widgets/calendar/integrations/radarr.jsx
Normal file
@ -0,0 +1,47 @@
|
||||
import { DateTime } from "luxon";
|
||||
import { useEffect, useContext } 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: radarrData, error: radarrError } = useWidgetAPI(config, "calendar",
|
||||
{ ...params, ...config?.params ?? {} }
|
||||
);
|
||||
useEffect(() => {
|
||||
if (!radarrData || radarrError) {
|
||||
return;
|
||||
}
|
||||
|
||||
const eventsToAdd = {};
|
||||
|
||||
radarrData?.forEach(event => {
|
||||
const cinemaTitle = `${event.title} - In cinemas`;
|
||||
const physicalTitle = `${event.title} - Physical release`;
|
||||
const digitalTitle = `${event.title} - Digital release`;
|
||||
|
||||
eventsToAdd[cinemaTitle] = {
|
||||
title: cinemaTitle,
|
||||
date: DateTime.fromISO(event.inCinemas),
|
||||
color: config?.color ?? 'amber'
|
||||
};
|
||||
eventsToAdd[physicalTitle] = {
|
||||
title: physicalTitle,
|
||||
date: DateTime.fromISO(event.physicalRelease),
|
||||
color: config?.color ?? 'cyan'
|
||||
};
|
||||
eventsToAdd[digitalTitle] = {
|
||||
title: digitalTitle,
|
||||
date: DateTime.fromISO(event.digitalRelease),
|
||||
color: config?.color ?? 'emerald'
|
||||
};
|
||||
})
|
||||
|
||||
setEvents((prevEvents) => ({ ...prevEvents, ...eventsToAdd }));
|
||||
}, [radarrData, radarrError, config, setEvents]);
|
||||
|
||||
const error = radarrError ?? radarrData?.error;
|
||||
return error && <Error error={{ message: `${config.type}: ${error.message ?? error}`}} />
|
||||
}
|
||||
@ -52,6 +52,10 @@ const widget = {
|
||||
return 0;
|
||||
})
|
||||
},
|
||||
calendar: {
|
||||
endpoint: "calendar",
|
||||
params: ["start", "end", "unmonitored"],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user