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
186
187
188
189
190
191
192
193
|
"use client";
import { MemoryIcon } from "../../assets/Memories";
import { Trash2, User2 } from "lucide-react";
import React, { useEffect, useState } from "react";
import { MemoriesBar } from "./MemoriesBar";
import { AnimatePresence, motion } from "framer-motion";
import { Bin } from "@/assets/Bin";
import { Avatar, AvatarFallback, AvatarImage } from "@radix-ui/react-avatar";
import { useSession } from "next-auth/react";
import MessagePoster from "@/app/MessagePoster";
import Image from "next/image";
import WordMark from "../WordMark";
export type MenuItem = {
icon: React.ReactNode | React.ReactNode[];
label: string;
content?: React.ReactNode;
labelDisplay?: React.ReactNode;
};
export default function Sidebar({
selectChange,
jwt,
}: {
selectChange?: (selectedItem: string | null) => void;
jwt: string;
}) {
const { data: session } = useSession();
const menuItemsTop: Array<MenuItem> = [
{
icon: <MemoryIcon className="h-10 w-10" />,
label: "Memories",
content: <MemoriesBar />,
},
];
const menuItemsBottom: Array<MenuItem> = [
{
icon: <Trash2 strokeWidth={1.3} className="h-6 w-6" />,
label: "Trash",
},
{
icon: (
<div>
<Avatar>
{session?.user?.image ? (
<AvatarImage
className="h-6 w-6 rounded-full"
src={session?.user?.image}
alt="user pfp"
/>
) : (
<User2 strokeWidth={1.3} className="h-6 w-6" />
)}
<AvatarFallback>
{session?.user?.name?.split(" ").map((n) => n[0])}{" "}
</AvatarFallback>
</Avatar>
</div>
),
label: "Profile",
},
];
const menuItems = [...menuItemsTop, ...menuItemsBottom];
const [selectedItem, setSelectedItem] = useState<string | null>(null);
const Subbar = menuItems.find((i) => i.label === selectedItem)?.content ?? (
<></>
);
useEffect(() => {
void selectChange?.(selectedItem);
}, [selectedItem]);
return (
<>
<div className="relative hidden h-screen max-h-screen w-max flex-col items-center text-sm font-light md:flex">
<div className="bg-rgray-3 border-r-rgray-6 relative z-[50] flex h-full w-full flex-col items-center justify-center border-r px-2 py-5 ">
<Image
className="mb-4 rounded-md"
src="/icons/logo_bw_without_bg.png"
alt="Smort logo"
width={50}
height={50}
/>
<div className="bg-rgray-6 mb-8 h-[1px] w-full" />
<MenuItem
item={{
label: "Memories",
icon: <MemoryIcon className="h-10 w-10" />,
content: <MemoriesBar />,
}}
selectedItem={selectedItem}
setSelectedItem={setSelectedItem}
/>
<div className="mt-auto" />
<MenuItem
item={{
label: "Trash",
icon: <Bin id="trash" className="z-[300] h-7 w-7" />,
}}
selectedItem={selectedItem}
id="trash-button"
setSelectedItem={setSelectedItem}
/>
<MenuItem
item={{
label: "Profile",
icon: (
<div className="mb-2">
<Avatar>
{session?.user?.image ? (
<AvatarImage
className="h-6 w-6 rounded-full"
src={session?.user?.image}
alt="@shadcn"
/>
) : (
<User2 strokeWidth={1.3} className="h-6 w-6" />
)}
<AvatarFallback>
{session?.user?.name?.split(" ").map((n) => n[0])}{" "}
</AvatarFallback>
</Avatar>
</div>
),
}}
selectedItem={selectedItem}
setSelectedItem={setSelectedItem}
/>
<MessagePoster jwt={jwt} />
</div>
<AnimatePresence>
{selectedItem && <SubSidebar>{Subbar}</SubSidebar>}
</AnimatePresence>
</div>
</>
);
}
const MenuItem = ({
item: { icon, label, labelDisplay },
selectedItem,
setSelectedItem,
...props
}: React.HTMLAttributes<HTMLButtonElement> & {
item: MenuItem;
selectedItem: string | null;
setSelectedItem: React.Dispatch<React.SetStateAction<string | null>>;
}) => (
<button
data-state-on={selectedItem === label}
onClick={() => setSelectedItem((prev) => (prev === label ? null : label))}
className="on:opacity-100 on:bg-rgray-4 focus-visible:ring-rgray-7 relative z-[100] flex w-full flex-col items-center justify-center rounded-md px-3 py-3 opacity-80 ring-2 ring-transparent transition hover:opacity-100 focus-visible:opacity-100 focus-visible:outline-none"
{...props}
>
{icon}
<span className="">{labelDisplay ?? label}</span>
</button>
);
export function SubSidebar({ children }: { children?: React.ReactNode }) {
return (
<motion.div
initial={{ opacity: 0, x: "-100%" }}
animate={{ opacity: 1, x: 0 }}
exit={{
opacity: 0,
x: "-100%",
transition: { delay: 0.2 },
}}
transition={{
duration: 0.2,
}}
className="bg-rgray-3 border-r-rgray-6 absolute left-[100%] top-0 z-[10] hidden h-screen w-[30vw] items-start justify-center overflow-x-hidden border-r font-light md:flex"
>
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0, transition: { delay: 0 } }}
transition={{
delay: 0.2,
}}
className="z-[10] flex h-full w-full min-w-full flex-col items-center opacity-0"
>
{children}
</motion.div>
</motion.div>
);
}
|