File size: 3,569 Bytes
d571830
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { useEffect, useState } from "react";
import { Link, NavLink, useNavigate } from "react-router-dom";

const ICONS = {
  home: (
    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
      <path d="M3 10.5 12 3l9 7.5" />
      <path d="M5 9.5V21h14V9.5" />
    </svg>
  ),
  search: (
    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round">
      <circle cx="11" cy="11" r="7" />
      <path d="m20 20-3.5-3.5" />
    </svg>
  ),
  book: (
    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
      <path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20" />
      <path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z" />
    </svg>
  ),
};

function NavItem({ to, end, label, icon, onClick }) {
  return (
    <NavLink
      to={to}
      end={end}
      className={({ isActive }) => `nav-item${isActive ? " active" : ""}`}
      onClick={onClick}
    >
      <span className="nav-icon">{ICONS[icon]}</span>
      {label}
    </NavLink>
  );
}

export default function Sidebar() {
  const navigate = useNavigate();
  const [open, setOpen] = useState(false);
  const [q, setQ] = useState("");

  useEffect(() => {
    const onKey = (e) => {
      if (e.key === "Escape") setOpen(false);
    };
    window.addEventListener("keydown", onKey);
    return () => window.removeEventListener("keydown", onKey);
  }, []);

  function submit(e) {
    e.preventDefault();
    if (!q.trim()) return;
    close();
    navigate(`/search?q=${encodeURIComponent(q.trim())}`);
  }

  return (
    <>
      <header className="topbar">
        <span className="mark"></span>
        <span className="topbar-title">anicove</span>
        <button
          className={`menu-btn${open ? " active" : ""}`}
          onClick={() => setOpen((v) => !v)}
          aria-label="Toggle menu"
        >
          <span />
          <span />
          <span />
        </button>
      </header>

      <div className={`overlay${open ? " open" : ""}`} onClick={close} />

      <aside className={`sidebar${open ? " open" : ""}`}>
        <div className="logo">
          <Link to="/home" onClick={close} style={{ display: "flex", alignItems: "center", gap: 10 }}>
            <span className="mark"></span>
            <span className="logo-text">anicove</span>
          </Link>
          <span className="logo-version">v0.1</span>
        </div>

        <form className="sidebar-search" onSubmit={submit}>
          {ICONS.search}
          <input
            value={q}
            onChange={(e) => setQ(e.target.value)}
            placeholder="Search anime…"
            aria-label="Search anime"
          />
        </form>

        <nav className="nav">
          <div className="nav-section">
            <div className="nav-label">Browse</div>
            <NavItem to="/home" label="Home" icon="home" onClick={close} />
            <NavItem to="/search" label="Search" icon="search" onClick={close} />
          </div>
          <div className="nav-section">
            <div className="nav-label">Library</div>
            <NavItem to="/manga" label="Manga" icon="book" onClick={close} />
          </div>
        </nav>

        <div className="sidebar-foot">
          Streaming via <b>Anicove</b> · 13 providers
          <br />
          Fallback: <b>Aniraku</b>
        </div>
      </aside>
    </>
  );
}