import React, { useState, useRef, forwardRef, useEffect } from "react"; import { ActionIcon, Stack, Divider } from "@mantine/core"; import { useTranslation } from 'react-i18next'; import MenuBookIcon from "@mui/icons-material/MenuBookRounded"; import SettingsIcon from "@mui/icons-material/SettingsRounded"; import FolderIcon from "@mui/icons-material/FolderRounded"; import { useRainbowThemeContext } from "./RainbowThemeProvider"; import AppConfigModal from './AppConfigModal'; import { useIsOverflowing } from '../../hooks/useIsOverflowing'; import { useFilesModalContext } from '../../contexts/FilesModalContext'; import { useToolWorkflow } from '../../contexts/ToolWorkflowContext'; import { ButtonConfig } from '../../types/sidebar'; import './quickAccessBar/QuickAccessBar.css'; import AllToolsNavButton from './AllToolsNavButton'; import ActiveToolButton from "./quickAccessBar/ActiveToolButton"; import { isNavButtonActive, getNavButtonStyle, getActiveNavButton, } from './quickAccessBar/QuickAccessBar'; const QuickAccessBar = forwardRef(({ }, ref) => { const { t } = useTranslation(); const { isRainbowMode } = useRainbowThemeContext(); const { openFilesModal, isFilesModalOpen } = useFilesModalContext(); const { handleReaderToggle, handleBackToTools, handleToolSelect, selectedToolKey, leftPanelView, toolRegistry, readerMode } = useToolWorkflow(); const [configModalOpen, setConfigModalOpen] = useState(false); const [activeButton, setActiveButton] = useState('tools'); const scrollableRef = useRef(null); const isOverflow = useIsOverflowing(scrollableRef); useEffect(() => { const next = getActiveNavButton(selectedToolKey, readerMode); setActiveButton(next); }, [leftPanelView, selectedToolKey, toolRegistry, readerMode]); const handleFilesButtonClick = () => { openFilesModal(); }; const buttonConfigs: ButtonConfig[] = [ { id: 'read', name: t("quickAccess.read", "Read"), icon: , size: 'lg', isRound: false, type: 'navigation', onClick: () => { setActiveButton('read'); handleBackToTools(); handleReaderToggle(); } }, { id: 'sign', name: t("quickAccess.sign", "Sign"), icon: signature , size: 'lg', isRound: false, type: 'navigation', onClick: () => { setActiveButton('sign'); handleToolSelect('sign'); } }, { id: 'automate', name: t("quickAccess.automate", "Automate"), icon: automation , size: 'lg', isRound: false, type: 'navigation', onClick: () => { setActiveButton('automate'); handleToolSelect('automate'); } }, { id: 'files', name: t("quickAccess.files", "Files"), icon: , isRound: true, size: 'lg', type: 'modal', onClick: handleFilesButtonClick }, { id: 'activity', name: t("quickAccess.activity", "Activity"), icon: vital_signs , isRound: true, size: 'lg', type: 'navigation', onClick: () => setActiveButton('activity') }, { id: 'config', name: t("quickAccess.config", "Config"), icon: , size: 'lg', type: 'modal', onClick: () => { setConfigModalOpen(true); } } ]; return (
{/* Fixed header outside scrollable area */}
{/* Conditional divider when overflowing */} {isOverflow && ( )} {/* Scrollable content area */}
{ // Prevent the wheel event from bubbling up to parent containers e.stopPropagation(); }} >
{/* Top section with main buttons */} {buttonConfigs.slice(0, -1).map((config, index) => (
{ config.onClick(); }} style={getNavButtonStyle(config, activeButton, isFilesModalOpen, configModalOpen, selectedToolKey, leftPanelView)} className={isNavButtonActive(config, activeButton, isFilesModalOpen, configModalOpen, selectedToolKey, leftPanelView) ? 'activeIconScale' : ''} data-testid={`${config.id}-button`} > {config.icon} {config.name}
{/* Add divider after Automate button (index 2) */} {index === 2 && ( )}
))}
{/* Spacer to push Config button to bottom */}
{/* Config button at the bottom */} {buttonConfigs .filter(config => config.id === 'config') .map(config => (
{config.icon} {config.name}
))}
setConfigModalOpen(false)} />
); }); export default QuickAccessBar;