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
|
"use client";
import { cn } from "@repo/lib/utils";
import { Badge } from "@repo/ui/components/badge";
import { ChevronDown, Eye } from "lucide-react";
import { memo, useEffect, useRef, useState } from "react";
import type { SpacesDropdownProps } from "./types";
export const SpacesDropdown = memo<SpacesDropdownProps>(
({ selectedSpace, availableSpaces, spaceMemoryCounts, onSpaceChange }) => {
const [isOpen, setIsOpen] = useState(false);
const dropdownRef = useRef<HTMLDivElement>(null);
// Close dropdown when clicking outside
useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (
dropdownRef.current &&
!dropdownRef.current.contains(event.target as Node)
) {
setIsOpen(false);
}
};
document.addEventListener("mousedown", handleClickOutside);
return () =>
document.removeEventListener("mousedown", handleClickOutside);
}, []);
const totalMemories = Object.values(spaceMemoryCounts).reduce(
(sum, count) => sum + count,
0,
);
return (
<div className="relative" ref={dropdownRef}>
<button
className={cn(
"flex items-center gap-3 px-4 py-3 rounded-xl border-2 border-solid border-transparent",
"[background-image:linear-gradient(#1a1f29,_#1a1f29),_linear-gradient(150.262deg,_#A4E8F5_0%,_#267FFA_26%,_#464646_49%,_#747474_70%,_#A4E8F5_100%)]",
"[background-origin:border-box] [background-clip:padding-box,_border-box]",
"shadow-[inset_0px_2px_1px_rgba(84,84,84,0.15)] backdrop-blur-md",
"transition-all duration-200 hover:shadow-[inset_0px_2px_1px_rgba(84,84,84,0.25)]",
"cursor-pointer min-w-60",
)}
onClick={() => setIsOpen(!isOpen)}
type="button"
>
<Eye className="w-4 h-4 text-slate-300" />
<div className="flex-1 text-left">
<span className="text-sm text-slate-200 font-medium">
{selectedSpace === "all"
? "All Spaces"
: selectedSpace || "Select space"}
</span>
<div className="text-xs text-slate-400">
{selectedSpace === "all"
? `${totalMemories} total memories`
: `${spaceMemoryCounts[selectedSpace] || 0} memories`}
</div>
</div>
<ChevronDown
className={cn(
"w-4 h-4 text-slate-300 transition-transform duration-200",
isOpen && "rotate-180",
)}
/>
</button>
{isOpen && (
<div className="absolute top-full left-0 right-0 mt-2 bg-slate-900/95 backdrop-blur-md border border-slate-700/40 rounded-xl shadow-xl z-20 overflow-hidden">
<div className="p-1">
<button
className={cn(
"w-full flex items-center justify-between px-3 py-2 rounded-lg text-left transition-colors",
selectedSpace === "all"
? "bg-blue-500/20 text-blue-300"
: "text-slate-200 hover:bg-slate-700/50",
)}
onClick={() => {
onSpaceChange("all");
setIsOpen(false);
}}
type="button"
>
<span className="text-sm">All Spaces</span>
<Badge className="bg-slate-700/50 text-slate-300 text-xs">
{totalMemories}
</Badge>
</button>
{availableSpaces.map((space) => (
<button
className={cn(
"w-full flex items-center justify-between px-3 py-2 rounded-lg text-left transition-colors",
selectedSpace === space
? "bg-blue-500/20 text-blue-300"
: "text-slate-200 hover:bg-slate-700/50",
)}
key={space}
onClick={() => {
onSpaceChange(space);
setIsOpen(false);
}}
type="button"
>
<span className="text-sm truncate flex-1">{space}</span>
<Badge className="bg-slate-700/50 text-slate-300 text-xs ml-2">
{spaceMemoryCounts[space] || 0}
</Badge>
</button>
))}
</div>
</div>
)}
</div>
);
},
);
SpacesDropdown.displayName = "SpacesDropdown";
|