|
1 | 1 | import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; |
| 2 | +import { useEffect, useCallback } from "react"; |
2 | 3 | import { NavLink, useParams } from "react-router-dom"; |
3 | 4 | import { useGeneStore } from "../store"; |
| 5 | +const API = `${location.protocol}//${location.host}/api/v1`; |
4 | 6 | const NAV_ITEMS = [ |
5 | 7 | { |
6 | 8 | path: "", |
@@ -36,8 +38,23 @@ const NAV_ITEMS = [ |
36 | 38 | export function Sidebar() { |
37 | 39 | const { genomeId } = useParams(); |
38 | 40 | const genomes = useGeneStore((s) => s.genomes); |
| 41 | + const setGenomes = useGeneStore((s) => s.setGenomes); |
39 | 42 | const activeGenomeId = useGeneStore((s) => s.activeGenomeId); |
| 43 | + const fetchGenomes = useCallback(async () => { |
| 44 | + try { |
| 45 | + const res = await fetch(`${API}/genomes`); |
| 46 | + if (res.ok) { |
| 47 | + const data = await res.json(); |
| 48 | + setGenomes(data); |
| 49 | + } |
| 50 | + } |
| 51 | + catch { /* silent */ } |
| 52 | + }, [setGenomes]); |
| 53 | + useEffect(() => { |
| 54 | + if (genomes.length === 0) |
| 55 | + fetchGenomes(); |
| 56 | + }, [genomes.length, fetchGenomes]); |
40 | 57 | const basePath = genomeId ? `/g/${genomeId}` : activeGenomeId ? `/g/${activeGenomeId}` : ""; |
41 | 58 | return (_jsxs("nav", { className: "sidebar", children: [_jsx("div", { className: "sidebar-logo", children: _jsxs(NavLink, { to: "/", className: "sidebar-logo-link", children: [_jsx("span", { className: "logo-gene", children: "G" }), _jsx("span", { className: "logo-life", children: "L" })] }) }), _jsx("div", { className: "sidebar-nav", children: basePath && |
42 | | - NAV_ITEMS.map((item) => (_jsxs(NavLink, { to: `${basePath}${item.path}`, end: item.path === "", className: ({ isActive }) => `sidebar-item ${isActive ? "sidebar-item-active" : ""}`, title: item.label, children: [_jsx("span", { className: "sidebar-icon", children: item.icon }), _jsx("span", { className: "sidebar-label", children: item.label })] }, item.path))) }), _jsx("div", { className: "sidebar-footer", children: genomes.length > 0 && (_jsxs(NavLink, { to: "/genomes", className: "sidebar-item sidebar-genome-picker", title: "Switch Genome", children: [_jsx("span", { className: "sidebar-icon", children: _jsxs("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.5", children: [_jsx("path", { d: "M3 7l7-5 7 5-7 5z" }), _jsx("path", { d: "M3 13l7 5 7-5" }), _jsx("path", { d: "M3 10l7 5 7-5" })] }) }), _jsx("span", { className: "sidebar-label", children: "Genomes" })] })) })] })); |
| 59 | + NAV_ITEMS.map((item) => (_jsxs(NavLink, { to: `${basePath}${item.path}`, end: item.path === "", className: ({ isActive }) => `sidebar-item ${isActive ? "sidebar-item-active" : ""}`, title: item.label, children: [_jsx("span", { className: "sidebar-icon", children: item.icon }), _jsx("span", { className: "sidebar-label", children: item.label })] }, item.path))) }), _jsx("div", { className: "sidebar-footer", children: _jsxs(NavLink, { to: "/genomes", className: "sidebar-item sidebar-genome-picker", title: "Switch Genome", children: [_jsx("span", { className: "sidebar-icon", children: _jsxs("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.5", children: [_jsx("path", { d: "M3 7l7-5 7 5-7 5z" }), _jsx("path", { d: "M3 13l7 5 7-5" }), _jsx("path", { d: "M3 10l7 5 7-5" })] }) }), _jsx("span", { className: "sidebar-label", children: "Genomes" })] }) })] })); |
43 | 60 | } |
0 commit comments