Added sonarr events to calendar
Signed-off-by: Denis Papec <denis.papec@gmail.com>
This commit is contained in:
parent
1e189d601b
commit
0a4e82f161
36
src/widgets/calendar/integrations/sonarr.jsx
Normal file
36
src/widgets/calendar/integrations/sonarr.jsx
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
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: sonarrData, error: sonarrError } = useWidgetAPI(config, "calendar",
|
||||||
|
{ ...params, includeSeries: 'false', includeEpisodeFile: 'false', includeEpisodeImages: 'false', ...config?.params ?? {} }
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!sonarrData || sonarrError) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const eventsToAdd = {};
|
||||||
|
|
||||||
|
sonarrData?.forEach(event => {
|
||||||
|
const title = `${event.series.title} - S${event.seasonNumber}E${event.episodeNumber}`;
|
||||||
|
|
||||||
|
eventsToAdd[title] = {
|
||||||
|
title,
|
||||||
|
date: DateTime.fromISO(event.airDateUtc),
|
||||||
|
color: config?.color ?? 'teal'
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
|
setEvents((prevEvents) => ({ ...prevEvents, ...eventsToAdd }));
|
||||||
|
}, [sonarrData, sonarrError, config, setEvents]);
|
||||||
|
|
||||||
|
const error = sonarrError ?? sonarrData?.error;
|
||||||
|
return error && <Error error={{ message: `${config.type}: ${error.message ?? error}`}} />
|
||||||
|
}
|
||||||
@ -57,7 +57,11 @@ const widget = {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
|
calendar: {
|
||||||
|
endpoint: "calendar",
|
||||||
|
params: ["start", "end", "unmonitored", "includeSeries", "includeEpisodeFile", "includeEpisodeImages"],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user