import { mdiHistory, mdiHomeOutline, mdiTextBoxSearchOutline } from "@mdi/js"; import { Icon } from "@mdi/react"; import axios from "axios"; import React, { useCallback, useEffect, useState } from "react"; import { Link, useLocation } from "react-router-dom"; import logo from "../assets/logo.svg"; import "./Sidebar.css"; 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;