import axios from "axios"; import React, { useCallback, useEffect, useState } from 'react'; import "./Sidebar.css"; import { Link, useLocation } from 'react-router-dom'; import { Icon } from '@mdi/react'; import { mdiHomeOutline, mdiTextBoxSearchOutline, mdiHistory } from '@mdi/js'; import logo from "../assets/logo.svg"; interface SidebarProps { onSelectPage: (page: string) => void; } const Sidebar: React.FC = ({ onSelectPage }) => { const [collapsed, setCollapsed] = useState(false); const location = useLocation(); const toggleSidebar = () => { setCollapsed(!collapsed); }; const handlePageClick = (page: string) => { onSelectPage(page); }; // Get whether experimental OCR is enabled const [ocrEnabled, setOcrEnabled] = useState(false); const fetchOcrEnabled = useCallback(async () => { try { const res = await axios.get<{ enabled: boolean }>("/api/experimental/ocr"); setOcrEnabled(res.data.enabled); } catch (err) { console.error(err); } }, []); useEffect(() => { fetchOcrEnabled(); }, [fetchOcrEnabled]); const menuItems = [ { name: 'home', path: '/', icon: mdiHomeOutline, title: 'Home' }, { name: 'history', path: '/history', icon: mdiHistory, title: 'History' }, ]; // If OCR is enabled, add the OCR menu item if (ocrEnabled) { menuItems.push({ name: 'ocr', path: '/experimental-ocr', icon: mdiTextBoxSearchOutline, title: 'OCR' }); } return (
{!collapsed && Logo}
); }; export default Sidebar;