Spaces:
Sleeping
Sleeping
axeronis commited on
Commit ·
8e4a89e
1
Parent(s): 40725d9
feat: Chats list sorting (New/Old/Hot/Cold), sticky header, compact UI
Browse files58 unmodified lines596061626364656667686970717273747576777879808182838485868788899065 unmodified lines15615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921058 unmodified linessetMounted(true)}, [])// Filter Logicconst filteredLeads = leads?.filter(lead => {const matchesSearch = (lead.name || '').toLowerCase().includes(searchQuery.toLowerCase())// Helper to detect channel (should ideally come from API)// fallback logic based on IDs if channel_source is missingconst isWhatsApp = !!lead.whatsapp_idconst isEmail = !!lead.email && !lead.whatsapp_id // prioritize WA if both? or just has emailconst isLinkedIn = !!lead.linkedin_profile || !!lead.linkedin_urnconst matchesTab =activeTab === 'all' ? true :activeTab === 'hot' ? lead.heat_level === 'HOT' :activeTab === 'unread' ? (lead.status || '').toLowerCase() === 'new' :activeTab === 'whatsapp' ? isWhatsApp :activeTab === 'email' ? isEmail :activeTab === 'linkedin' ? isLinkedIn : truereturn matchesSearch && matchesTab}) || []// PERSISTENCE FIX: Ensure selected lead is always visible in the list, even if filtered by tab// Check if selected lead is already in filtered listconst selectedLead = leads?.find(l => l.id === selectedLeadId)if (selectedLead && !filteredLeads.some(l => l.id === selectedLeadId)) {// Only add if it matches search (so search still works for finding specific people)if ((selectedLead.name || '').toLowerCase().includes(searchQuery.toLowerCase())) {filteredLeads.unshift(selectedLead)}65 unmodified lines)}<div className="flex flex-col h-full bg-[#0D0E18] border-r border-white/10">{/* Header & Search */}<div className="p-4 border-b border-white/10 space-y-3 flex-shrink-0 bg-surface-elevated"><div className="flex items-center justify-between"><h2 className="text-xl font-bold text-white tracking-tight">{t('chats.title')}</h2><button className="p-2 hover:bg-white/5 rounded-lg text-slate-400 hover:text-white transition-colors"><Inbox className="w-5 h-5" /></button></div>{/* Start Active Chats Section (Visual Helper) */}{/* In reference, there is a "Чаты" list directly. We keep search for usability though reference hides it or it's collapsed. */}{/* We'll keep search but style it minimally */}<div className="relative group"><Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-500 group-focus-within:text-indigo-400 transition-colors" /><inputtype="text"placeholder={t('common.search')}value={searchQuery}onChange={(e) => setSearchQuery(e.target.value)}className="w-full pl-9 pr-4 py-2 bg-[#0D0E18] border border-white/5 rounded-xl text-sm text-white focus:outline-none focus:border-indigo-500/50 transition-all placeholder:text-slate-600"/></div>{/* Tabs - Simplified to match clean look */}<div className="flex gap-1 overflow-x-auto scrollbar-hide py-1"><buttononClick={() => setActiveTab('all')}className={cn("px-3 py-1 text-xs font-semibold rounded-full transition-all whitespace-nowrap",activeTab === 'all' ? "bg-white/10 text-white" : "text-slate-500 hover:text-slate-300")}>Все</button><buttononClick={() => setActiveTab('hot')}className={cn("px-3 py-1 text-xs font-semibold rounded-full transition-all whitespace-nowrap flex items-center gap-1",activeTab === 'hot' ? "bg-red-500/10 text-red-400" : "text-slate-500 hover:text-slate-300")}><Flame className="w-3 h-3" />Важные</button></div><div className="text-[10px] font-bold text-slate-500 uppercase tracking-wider px-1">Активные чаты</div></div>58 unmodified lines596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210365 unmodified lines16917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822958 unmodified linessetMounted(true)}, [])// Filter & Sort Logicconst filteredLeads = (() => {// First filter by searchlet result = leads?.filter(lead => {const matchesSearch = (lead.name || '').toLowerCase().includes(searchQuery.toLowerCase())return matchesSearch}) || []// Then sort based on activeTabif (activeTab === 'all') {// Newest first (by last_message_at descending)result = [...result].sort((a, b) =>new Date(b.last_message_at).getTime() - new Date(a.last_message_at).getTime())} else if (activeTab === 'unread') {// Oldest first (by last_message_at ascending)result = [...result].sort((a, b) =>new Date(a.last_message_at).getTime() - new Date(b.last_message_at).getTime())} else if (activeTab === 'hot') {// Hottest first (HOT at top, then WARM, then COLD)const heatOrder: Record<string, number> = { 'HOT': 0, 'WARM': 1, 'COLD': 2 }result = [...result].sort((a, b) =>(heatOrder[a.heat_level || 'COLD'] || 2) - (heatOrder[b.heat_level || 'COLD'] || 2))} else if (activeTab === 'whatsapp') {// Coldest first (COLD at top, then WARM, then HOT)const heatOrder: Record<string, number> = { 'COLD': 0, 'WARM': 1, 'HOT': 2 }result = [...result].sort((a, b) =>(heatOrder[a.heat_level || 'COLD'] || 0) - (heatOrder[b.heat_level || 'COLD'] || 0))}return result})()// PERSISTENCE FIX: Ensure selected lead is always visible in the listconst selectedLead = leads?.find(l => l.id === selectedLeadId)if (selectedLead && !filteredLeads.some(l => l.id === selectedLeadId)) {if ((selectedLead.name || '').toLowerCase().includes(searchQuery.toLowerCase())) {filteredLeads.unshift(selectedLead)}65 unmodified lines)}<div className="flex flex-col h-full bg-[#0D0E18] border-r border-white/10">{/* Header & Search - STICKY */}<div className="sticky top-0 z-10 p-3 border-b border-white/10 space-y-2 flex-shrink-0 bg-[#0D0E18]"><h2 className="text-lg font-bold text-white tracking-tight">{t('chats.title')}</h2>{/* Search */}<div className="relative group"><Search className="absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-500 group-focus-within:text-indigo-400 transition-colors" /><inputtype="text"placeholder={t('common.search')}value={searchQuery}onChange={(e) => setSearchQuery(e.target.value)}className="w-full pl-8 pr-3 py-1.5 bg-[#0D0E18] border border-white/5 rounded-lg text-sm text-white focus:outline-none focus:border-indigo-500/50 transition-all placeholder:text-slate-600"/></div>{/* Sorting Tabs */}<div className="flex gap-1 overflow-x-auto scrollbar-hide"><buttononClick={() => setActiveTab('all')}className={cn("px-2 py-1 text-[11px] font-medium rounded-lg transition-all whitespace-nowrap",activeTab === 'all' ? "bg-white/10 text-white" : "text-slate-500 hover:text-slate-300")}>Новые ↓</button><buttononClick={() => setActiveTab('unread')}className={cn("px-2 py-1 text-[11px] font-medium rounded-lg transition-all whitespace-nowrap",activeTab === 'unread' ? "bg-white/10 text-white" : "text-slate-500 hover:text-slate-300")}>Старые ↓</button><buttononClick={() => setActiveTab('hot')}className={cn("px-2 py-1 text-[11px] font-medium rounded-lg transition-all whitespace-nowrap flex items-center gap-1",activeTab === 'hot' ? "bg-red-500/10 text-red-400" : "text-slate-500 hover:text-slate-300")}><Flame className="w-3 h-3" />Горячие</button><buttononClick={() => setActiveTab('whatsapp')}className={cn("px-2 py-1 text-[11px] font-medium rounded-lg transition-all whitespace-nowrap",activeTab === 'whatsapp' ? "bg-blue-500/10 text-blue-400" : "text-slate-500 hover:text-slate-300")}>Холодные</button></div></div>
frontend/components/LeadsList.tsx+64-45