Added readarr events to calendar
Signed-off-by: Denis Papec <denis.papec@gmail.com>
This commit is contained in:
parent
7b7d0e0345
commit
1e189d601b
37
src/widgets/calendar/integrations/readarr.jsx
Normal file
37
src/widgets/calendar/integrations/readarr.jsx
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
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: readarrData, error: readarrError } = useWidgetAPI(config, "calendar",
|
||||||
|
{ ...params, includeAuthor: 'false', ...config?.params ?? {} },
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!readarrData || readarrError) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const eventsToAdd = {};
|
||||||
|
|
||||||
|
readarrData?.forEach(event => {
|
||||||
|
const authorName = event.authorTitle.replace(event.title, '');
|
||||||
|
const title = `${authorName} - ${event.title} ${event?.seriesTitle ? `(${event.seriesTitle})` : ''} `;
|
||||||
|
|
||||||
|
eventsToAdd[title] = {
|
||||||
|
title,
|
||||||
|
date: DateTime.fromISO(event.releaseDate),
|
||||||
|
color: config?.color ?? 'rose'
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
|
setEvents((prevEvents) => ({ ...prevEvents, ...eventsToAdd }));
|
||||||
|
}, [readarrData, readarrError, config, setEvents]);
|
||||||
|
|
||||||
|
const error = readarrError ?? readarrData?.error;
|
||||||
|
return error && <Error error={{ message: `${config.type}: ${error.message ?? error}`}} />
|
||||||
|
}
|
||||||
@ -18,6 +18,10 @@ const widget = {
|
|||||||
"wanted/missing": {
|
"wanted/missing": {
|
||||||
endpoint: "wanted/missing",
|
endpoint: "wanted/missing",
|
||||||
},
|
},
|
||||||
|
calendar: {
|
||||||
|
endpoint: "calendar",
|
||||||
|
params: ["start", "end", "unmonitored", "includeAuthor"],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user