import React, { FunctionComponent, useContext, useMemo } from "react"; import { Container, Image, ListGroup } from "react-bootstrap"; import { useReduxStore } from "../@redux/hooks/base"; import { useIsRadarrEnabled, useIsSonarrEnabled } from "../@redux/hooks/site"; import logo from "../@static/logo64.png"; import { SidebarToggleContext } from "../App"; import { useGotoHomepage } from "../utilities/hooks"; import { BadgesContext, CollapseItem, HiddenKeysContext, LinkItem, } from "./items"; import { RadarrDisabledKey, SidebarList, SonarrDisabledKey } from "./list"; import "./style.scss"; import { BadgeProvider } from "./types"; interface Props { open?: boolean; } const Sidebar: FunctionComponent = ({ open }) => { const toggle = useContext(SidebarToggleContext); const { movies, episodes, providers, status } = useReduxStore( (s) => s.site.badges ); const sonarrEnabled = useIsSonarrEnabled(); const radarrEnabled = useIsRadarrEnabled(); const badges = useMemo( () => ({ Wanted: { Series: sonarrEnabled ? episodes : 0, Movies: radarrEnabled ? movies : 0, }, System: { Providers: providers, Status: status, }, }), [movies, episodes, providers, sonarrEnabled, radarrEnabled, status] ); const hiddenKeys = useMemo(() => { const list = []; if (!sonarrEnabled) { list.push(SonarrDisabledKey); } if (!radarrEnabled) { list.push(RadarrDisabledKey); } return list; }, [sonarrEnabled, radarrEnabled]); const cls = ["sidebar-container"]; const overlay = ["sidebar-overlay"]; if (open === true) { cls.push("open"); overlay.push("open"); } const sidebarItems = useMemo( () => SidebarList.map((v) => { if (hiddenKeys.includes(v.hiddenKey ?? "")) { return null; } if ("children" in v) { return ; } else { return ; } }), [hiddenKeys] ); const goHome = useGotoHomepage(); return (
); }; export default Sidebar;