Spaces:
Runtime error
Runtime error
File size: 7,835 Bytes
c5cf697 49f22ac c5cf697 | 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 | import ComsatsLogo from '../ComsatsLogo'
function PlusIcon({ className = '' }) {
return (
<svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden>
<path strokeLinecap="round" strokeLinejoin="round" d="M12 4v16m8-8H4" />
</svg>
)
}
function ChevronLeftIcon({ className = '' }) {
return (
<svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden>
<path strokeLinecap="round" strokeLinejoin="round" d="M15 19l-7-7 7-7" />
</svg>
)
}
function UserCircleIcon({ className = '' }) {
return (
<svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" aria-hidden>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M15.75 6a3.75 3.75 0 11-7.5 0 3.75 3.75 0 017.5 0zM4.501 20.118a7.5 7.5 0 0114.998 0A17.933 17.933 0 0112 21.75c-2.676 0-5.216-.584-7.499-1.632z"
/>
</svg>
)
}
function LogoutIcon({ className = '' }) {
return (
<svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" aria-hidden>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M15.75 9V5.25A2.25 2.25 0 0013.5 3h-6a2.25 2.25 0 00-2.25 2.25v13.5A2.25 2.25 0 007.5 21h6a2.25 2.25 0 002.25-2.25V15m3 0l3-3m0 0l-3-3m3 3H9"
/>
</svg>
)
}
export default function ChatSidebar({
user,
chats,
selectedId,
onSelectChat,
onNewChat,
onDeleteChat,
onEditProfile,
onLogout,
onCloseSidebar,
loadingList,
hasMoreChats,
loadingMoreChats,
onLoadMoreChats,
chatListTotal,
}) {
return (
<aside className="relative flex h-full min-h-0 w-full min-w-0 flex-col bg-chat-sidebar">
<div className="shrink-0 border-b border-slate-200/60 bg-gradient-to-br from-white via-chat-sidebar to-comsats-purple/[0.04] px-3 py-3.5 md:px-3.5">
<div className="flex items-start gap-2">
<div className="flex min-w-0 flex-1 items-center gap-3">
<ComsatsLogo className="h-10 w-10 shrink-0 shadow-sm ring-2 ring-white md:h-11 md:w-11" />
<div className="min-w-0 flex-1">
<p className="truncate text-[14px] font-bold tracking-tight text-comsats-purple">
CUI Connect
</p>
<p className="truncate text-[11px] leading-tight text-slate-500">{user?.email}</p>
</div>
</div>
<button
type="button"
onClick={onCloseSidebar}
aria-label="Close sidebar"
title="Close sidebar"
className="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl border border-slate-200/80 bg-white/90 text-slate-600 shadow-sm transition-colors hover:border-comsats-purple/25 hover:bg-white hover:text-comsats-purple"
>
<ChevronLeftIcon className="h-[18px] w-[18px]" />
</button>
</div>
</div>
<div className="shrink-0 px-2.5 pb-2 pt-3 md:px-3">
<button
type="button"
onClick={onNewChat}
className="flex w-full items-center justify-center gap-2 rounded-xl bg-gradient-to-r from-comsats-purple to-[#3d2469] px-3 py-2.5 text-[13px] font-semibold text-white shadow-md shadow-comsats-purple/25 transition-all hover:brightness-110 hover:shadow-lg active:scale-[0.99]"
>
<PlusIcon className="h-4 w-4 opacity-95" />
New chat
</button>
</div>
<div className="min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-2 pb-2 md:px-2.5">
<p className="flex items-center justify-between px-1.5 pb-2 pt-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400">
<span>Your chats</span>
{chatListTotal > 0 ? (
<span className="font-medium normal-case tracking-normal text-slate-400 tabular-nums">
{chats.length}/{chatListTotal}
</span>
) : null}
</p>
{loadingList ? (
<p className="px-2 py-3 text-[13px] text-slate-500">Loading…</p>
) : chats.length === 0 ? (
<div className="mx-2 rounded-xl border border-dashed border-slate-200/90 bg-white/50 px-3 py-6 text-center">
<p className="text-[13px] leading-relaxed text-slate-500">No chats yet. Start one above.</p>
</div>
) : (
<ul className="flex flex-col gap-1">
{chats.map((c) => {
const active = selectedId === c.chat_id
return (
<li key={c.chat_id}>
<div
className={`group flex items-stretch overflow-hidden rounded-xl border transition-all ${
active
? 'border-comsats-purple/25 bg-white shadow-[0_4px_14px_-6px_rgba(75,46,131,0.35)] ring-1 ring-comsats-purple/15'
: 'border-transparent hover:border-slate-200/80 hover:bg-white/70'
}`}
>
<button
type="button"
onClick={() => onSelectChat(c.chat_id)}
className={`min-w-0 flex-1 border-l-[3px] py-2.5 pl-3 pr-2 text-left ${
active ? 'border-l-comsats-purple' : 'border-l-transparent'
}`}
>
<span
className={`line-clamp-2 text-[13px] leading-snug ${
active ? 'font-semibold text-slate-900' : 'font-medium text-slate-700'
}`}
>
{c.preview}
</span>
<span className="mt-1 block text-[11px] text-slate-400">
{c.message_count ? `${c.message_count} messages` : 'Empty'}
</span>
</button>
<button
type="button"
title="Delete chat"
onClick={(e) => {
e.stopPropagation()
onDeleteChat(c.chat_id)
}}
className="shrink-0 px-2.5 text-slate-400 opacity-0 transition-opacity hover:text-red-600 group-hover:opacity-100"
>
×
</button>
</div>
</li>
)
})}
</ul>
)}
{hasMoreChats ? (
<div className="px-1 pt-3">
<button
type="button"
disabled={loadingMoreChats || loadingList}
onClick={onLoadMoreChats}
className="w-full rounded-xl py-2.5 text-[12px] font-semibold text-comsats-purple hover:bg-white/70 disabled:opacity-50"
>
{loadingMoreChats ? 'Loading…' : 'Load more chats'}
</button>
</div>
) : null}
</div>
<div className="shrink-0 border-t border-slate-200/60 bg-white/40 p-2 md:p-2.5">
<button
type="button"
onClick={onEditProfile}
className="flex w-full items-center gap-2.5 rounded-xl px-3 py-2.5 text-left text-[13px] font-medium text-slate-700 transition-colors hover:bg-white"
>
<UserCircleIcon className="h-5 w-5 shrink-0 text-slate-500" />
Edit profile
</button>
<button
type="button"
onClick={onLogout}
className="flex w-full items-center gap-2.5 rounded-xl px-3 py-2.5 text-left text-[13px] font-medium text-red-600 transition-colors hover:bg-red-50"
>
<LogoutIcon className="h-5 w-5 shrink-0 opacity-90" />
Log out
</button>
</div>
</aside>
)
}
|