import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import {faFeather, faGlobe, faInfoCircle, faMapMarkerAlt, faUsers} from "@fortawesome/free-solid-svg-icons"; import {RefObject, useContext, useEffect, useRef, useState} from "react"; import {BookContext} from "@/context/BookContext"; import {PanelComponent} from "@/lib/models/Editor"; import PanelHeader from "@/components/PanelHeader"; import AboutEditors from "@/components/rightbar/AboutERitors"; import {faDiscord, faFacebook} from "@fortawesome/free-brands-svg-icons"; import WorldSetting from "@/components/book/settings/world/WorldSetting"; import LocationComponent from "@/components/book/settings/locations/LocationComponent"; import CharacterComponent from "@/components/book/settings/characters/CharacterComponent"; import QuillSense from "@/components/quillsense/QuillSenseComponent"; import {useTranslations} from "next-intl"; import OfflineContext, {OfflineContextType} from "@/context/OfflineContext"; export default function ComposerRightBar() { const {book} = useContext(BookContext); const t = useTranslations(); const {isCurrentlyOffline} = useContext(OfflineContext) const [panelHidden, setPanelHidden] = useState(false); const [currentPanel, setCurrentPanel] = useState() const [showAbout, setShowAbout] = useState(false); const worldRef: RefObject<{ handleSave: () => Promise } | null> = useRef<{ handleSave: () => Promise }>(null); const locationRef: RefObject<{ handleSave: () => Promise } | null> = useRef<{ handleSave: () => Promise }>(null); const characterRef: RefObject<{ handleSave: () => Promise } | null> = useRef<{ handleSave: () => Promise }>(null); async function handleSaveClick(): Promise { switch (currentPanel?.id) { case 2: worldRef.current?.handleSave(); break; case 3: locationRef.current?.handleSave(); break; case 4: characterRef.current?.handleSave(); break; default: break; } } function togglePanel(component: PanelComponent): void { if (panelHidden) { if (currentPanel?.id === component.id) { setPanelHidden(!panelHidden); return; } } else { setPanelHidden(true); } } useEffect(():void => { if (!book){ setCurrentPanel(undefined); setPanelHidden(false); return; } }, [book]); const editorComponents: PanelComponent[] = [ { id: 1, title: t("composerRightBar.editorComponents.quillSense.title"), description: t("composerRightBar.editorComponents.quillSense.description"), badge: t("composerRightBar.editorComponents.quillSense.badge"), icon: faFeather }, { id: 2, title: t("composerRightBar.editorComponents.worlds.title"), description: t("composerRightBar.editorComponents.worlds.description"), badge: t("composerRightBar.editorComponents.worlds.badge"), icon: faGlobe }, { id: 3, title: t("composerRightBar.editorComponents.locations.title"), description: t("composerRightBar.editorComponents.locations.description"), badge: t("composerRightBar.editorComponents.locations.badge"), icon: faMapMarkerAlt }, { id: 4, title: t("composerRightBar.editorComponents.characters.title"), description: t("composerRightBar.editorComponents.characters.description"), badge: t("composerRightBar.editorComponents.characters.badge"), icon: faUsers }, /*{ id: 5, title: t("composerRightBar.editorComponents.items.title"), description: t("composerRightBar.editorComponents.items.description"), badge: t("composerRightBar.editorComponents.items.badge"), icon: faCube, }*/ ] const homeComponents: PanelComponent[] = [ { id: 1, title: t("composerRightBar.homeComponents.about.title"), description: t("composerRightBar.homeComponents.about.description"), badge: t("composerRightBar.homeComponents.about.badge"), icon: faInfoCircle, action: () => setShowAbout(true) }, { id: 2, title: t("composerRightBar.homeComponents.facebook.title"), description: t("composerRightBar.homeComponents.facebook.description"), badge: t("composerRightBar.homeComponents.facebook.badge"), icon: faFacebook, action: ():Promise => window.electron.openExternal('https://www.facebook.com/profile.php?id=61562628720878') }, { id: 3, title: t("composerRightBar.homeComponents.discord.title"), description: t("composerRightBar.homeComponents.discord.description"), badge: t("composerRightBar.homeComponents.discord.badge"), icon: faDiscord, action: () => window.electron.openExternal('https://discord.gg/CHXRPvmaXm') } ] function disabled(componentId: number): boolean { switch (componentId) { case 1: return book === null; default: return book === null; } } return (
{panelHidden && (
setPanelHidden(!panelHidden)} />
{currentPanel?.id === 1 && ( )} {currentPanel?.id === 2 && ( )} {currentPanel?.id === 3 && ( )} {currentPanel?.id === 4 && ( )}
)}
{book ? editorComponents .filter((component: PanelComponent):boolean => { return !((isCurrentlyOffline() || book?.localBook) && component.id === 1); }) .map((component: PanelComponent) => ( )) : homeComponents.map((component: PanelComponent) => ( ))}
{ showAbout && setShowAbout(false)}/> }
) }