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

47 lines
1.2 KiB
TypeScript
Raw Normal View History

import { useCallback, useEffect } from "react";
2021-03-25 14:22:43 +00:00
import { useSystemSettings } from ".";
2021-05-09 03:22:24 +00:00
import { siteAddNotifications, siteChangeSidebar } 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;
}
export function useSetSidebar(key: string) {
const update = useReduxAction(siteChangeSidebar);
useEffect(() => {
update(key);
}, [update, key]);
}