'use client' import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import { faFeather, faGlobe, faHatWizard, faInfoCircle, faMapMarkerAlt, faUsers } from "@fortawesome/free-solid-svg-icons"; import React, {lazy, Suspense, useContext, useEffect, 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 QuillSense from "@/components/quillsense/QuillSenseComponent"; import {useTranslations} from "next-intl"; import {faSpinner} from "@fortawesome/free-solid-svg-icons"; import OfflineContext, {OfflineContextType} from "@/context/OfflineContext"; // Lazy loaded Editor components const WorldEditor = lazy(function () { return import('@/components/book/settings/world/editor/WorldEditor'); }); const LocationEditor = lazy(function () { return import('@/components/book/settings/locations/editor/LocationEditor'); }); const CharacterEditor = lazy(function () { return import('@/components/book/settings/characters/editor/CharacterEditor'); }); const SpellEditor = lazy(function () { return import('@/components/book/settings/spells/editor/SpellEditor'); }); function LoadingSpinner(): React.JSX.Element { return (
); } interface PanelContentProps { currentPanelId: number | undefined; } function PanelContent({currentPanelId}: PanelContentProps): React.JSX.Element { return ( }> {currentPanelId === 1 && } {currentPanelId === 2 && } {currentPanelId === 3 && } {currentPanelId === 4 && } {currentPanelId === 5 && } ); } interface PanelHeaderProps { currentPanel: PanelComponent | undefined; onClose: () => Promise; } function EditorPanelHeader({currentPanel, onClose}: PanelHeaderProps): React.JSX.Element { return ( ); } export default function ComposerRightBar(): React.JSX.Element { 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); function togglePanel(component: PanelComponent): void { if (panelHidden) { if (currentPanel?.id === component.id) { setPanelHidden(!panelHidden); return; } } else { setPanelHidden(true); } } 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.spells.title"), description: t("composerRightBar.editorComponents.spells.description"), badge: t("composerRightBar.editorComponents.spells.badge"), icon: faHatWizard }, ]; 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: function (): void { 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: function (): Promise { return 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: function (): Promise { return window.electron.openExternal('https://discord.gg/CHXRPvmaXm'); } } ]; function disabled(componentId: number): boolean { return book === null; } useEffect(function (): void { if (!book) { setCurrentPanel(undefined); setPanelHidden(false); } }, [book]); async function handleClosePanel(): Promise { setPanelHidden(!panelHidden); } return (
{panelHidden && (
)}
{book ? editorComponents.filter(function (component: PanelComponent): boolean { // Masquer QuillSense (id=1) si offline, livre local ou desactive pour ce livre if (component.id === 1) { if (isCurrentlyOffline() || book?.localBook) { return false; } if (book.quillsenseEnabled === false) { return false; } } // Masquer Worlds (id=2) si desactive pour ce livre if (component.id === 2 && !book?.tools?.worlds) { return false; } // Masquer Locations (id=3) si desactive pour ce livre if (component.id === 3 && !book?.tools?.locations) { return false; } // Masquer Characters (id=4) si desactive pour ce livre if (component.id === 4 && !book?.tools?.characters) { return false; } // Masquer Spells (id=5) si desactive pour ce livre if (component.id === 5 && !book?.tools?.spells) { return false; } return true; }).map(function (component: PanelComponent) { return ( ); }) : homeComponents.map(function (component: PanelComponent) { return ( ); })}
{showAbout && }
); }