aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/components/sidebar.tsx
blob: 018504838110125de8bcb09df2eed354282f8668 (plain) (blame)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
"use client";

import { useState } from "react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import styled from "styled-components";
import { ChevronLeft, ChevronRight, LogIn, LogOut } from "lucide-react";
import { useAuth } from "../context/auth";
import { navItems } from "./nav-items";

const SidebarRoot = styled.aside<{ $collapsed: boolean }>`
  width: ${(p) => (p.$collapsed ? "52px" : "200px")};
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #1f1f2a;
  background-color: #0b0b10;
  overflow: hidden;
  transition: width 0.2s ease;
`;

const ToggleBtn = styled.button`
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
  width: 100%;
  flex-shrink: 0;
  background: none;
  border: none;
  border-bottom: 1px solid #1f1f2a;
  cursor: pointer;
  color: #8b90a0;
  transition: background 0.15s, color 0.15s;
  &:hover {
    background-color: #1a1d29;
    color: #f5f5f5;
  }
`;

const Nav = styled.nav`
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  overflow-x: hidden;
`;

const NavItem = styled(Link)<{ $active: boolean; $collapsed: boolean }>`
  display: flex;
  align-items: center;
  justify-content: ${(p) => (p.$collapsed ? "center" : "flex-start")};
  gap: ${(p) => (p.$collapsed ? "0" : "10px")};
  padding: ${(p) => (p.$collapsed ? "9px 0" : "9px 12px")};
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  color: ${(p) => (p.$active ? "#f5f5f5" : "#8b90a0")};
  background-color: ${(p) => (p.$active ? "#1a1d29" : "transparent")};
  border-left: 2px solid ${(p) => (p.$active ? "#a78bfa" : "transparent")};
  transition: background 0.15s, color 0.15s;
  &:hover {
    background-color: #1a1d29;
    color: #f5f5f5;
  }
`;

const Label = styled.span<{ $collapsed: boolean }>`
  max-width: ${(p) => (p.$collapsed ? "0" : "200px")};
  overflow: hidden;
  white-space: nowrap;
  opacity: ${(p) => (p.$collapsed ? 0 : 1)};
  transition: max-width 0.2s ease, opacity 0.1s ease;
`;


const Footer = styled.div`
  padding: 12px 8px;
  border-top: 1px solid #1f1f2a;
  display: flex;
  flex-direction: column;
  gap: 2px;
`;

const Username = styled.span<{ $collapsed: boolean }>`
  display: block;
  padding: ${(p) => (p.$collapsed ? "0" : "6px 12px")};
  max-height: ${(p) => (p.$collapsed ? "0" : "28px")};
  font-size: 12px;
  color: #4b5563;
  overflow: hidden;
  white-space: nowrap;
  opacity: ${(p) => (p.$collapsed ? 0 : 1)};
  transition: max-height 0.2s ease, padding 0.2s ease, opacity 0.1s ease;
`;

const AuthButton = styled.button<{ $collapsed: boolean }>`
  display: flex;
  align-items: center;
  justify-content: ${(p) => (p.$collapsed ? "center" : "flex-start")};
  gap: 10px;
  padding: 9px 12px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  color: #8b90a0;
  width: 100%;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  &:hover {
    background-color: #1a1d29;
    color: #f5f5f5;
  }
`;

const AuthLink = styled(Link)<{ $collapsed: boolean }>`
  display: flex;
  align-items: center;
  justify-content: ${(p) => (p.$collapsed ? "center" : "flex-start")};
  gap: 10px;
  padding: 9px 12px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  color: #8b90a0;
  transition: background 0.15s, color 0.15s;
  &:hover {
    background-color: #1a1d29;
    color: #f5f5f5;
  }
`;

export function Sidebar() {
  const pathname = usePathname();
  const { user, signOut } = useAuth();
  const [collapsed, setCollapsed] = useState(false);

  return (
    <SidebarRoot $collapsed={collapsed}>
      <ToggleBtn
        onClick={() => setCollapsed((c) => !c)}
        aria-label={collapsed ? "Expand sidebar" : "Collapse sidebar"}
      >
        {collapsed ? <ChevronRight size={16} /> : <ChevronLeft size={16} />}
      </ToggleBtn>

      <Nav>
        {navItems.map((item) => {
          const active = pathname === item.href;
          const Icon = item.icon;
          return (
            <NavItem key={item.href} href={item.href} $active={active} $collapsed={collapsed}>
              <Icon size={16} />
              <Label $collapsed={collapsed}>{item.title}</Label>
            </NavItem>
          );
        })}
      </Nav>

      <Footer>
        {user ? (
          <>
            <Username $collapsed={collapsed}>{user.username || user.name}</Username>
            <AuthButton $collapsed={collapsed} onClick={signOut}>
              <LogOut size={16} />
              <Label $collapsed={collapsed}>Sign out</Label>
            </AuthButton>
          </>
        ) : (
          <AuthLink href="/signin" $collapsed={collapsed}>
            <LogIn size={16} />
            <Label $collapsed={collapsed}>Sign in</Label>
          </AuthLink>
        )}
      </Footer>
    </SidebarRoot>
  );
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage