bazarr/frontend/src/@redux/hooks/site.ts

40 lines
1.0 KiB
TypeScript
Raw Normal View History

2021-08-31 16:08:47 +00:00
import { useCallback } from "react";
2021-03-25 14:22:43 +00:00
import { useSystemSettings } from ".";
2021-08-31 16:08:47 +00:00
import { siteAddNotifications } from "../actions";
2021-03-25 14:22:43 +00:00
import { useReduxAction, useReduxStore } from "./base";
2021-05-09 03:22:24 +00:00
export function useNotification(id: string, timeout: number = 5000) {
const add = useReduxAction(siteAddNotifications);
2021-03-25 14:22:43 +00:00
return useCallback(
(msg: Omit<Server.Notification, "id" | "timeout">) => {
const notification: Server.Notification = {
2021-03-25 14:22:43 +00:00
...msg,
2021-05-09 03:22:24 +00:00
id,
timeout,
2021-03-25 14:22:43 +00:00
};
2021-05-09 03:22:24 +00:00
add([notification]);
2021-03-25 14:22:43 +00:00
},
2021-05-09 03:22:24 +00:00
[add, timeout, id]
2021-03-25 14:22:43 +00:00
);
}
export function useIsOffline() {
return useReduxStore((s) => s.site.offline);
}
export function useIsSonarrEnabled() {
const settings = useSystemSettings();
return settings.content?.general.use_sonarr ?? true;
2021-03-25 14:22:43 +00:00
}
export function useIsRadarrEnabled() {
const settings = useSystemSettings();
return settings.content?.general.use_radarr ?? true;
2021-03-25 14:22:43 +00:00
}
export function useShowOnlyDesired() {
const settings = useSystemSettings();
return settings.content?.general.embedded_subs_show_desired ?? false;
}