Spaces:
Sleeping
Sleeping
axeronis commited on
Commit ·
abb8c3e
1
Parent(s): 01e5fe2
fix(ux): phase 7 final mobile polish - toggle, input, duplication, and deletion
Browse files
frontend/app/globals.css
CHANGED
|
@@ -109,7 +109,11 @@ html {
|
|
| 109 |
--md-sys-color-on-primary-container: #E0E7FF;
|
| 110 |
/* Indigo 100 */
|
| 111 |
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
--md-sys-color-secondary: var(--secondary);
|
| 114 |
--md-sys-color-on-secondary: #FFFFFF;
|
| 115 |
--md-sys-color-secondary-container: #4C1D95;
|
|
@@ -157,11 +161,16 @@ html {
|
|
| 157 |
--md-sys-color-outline-variant: var(--border-hover);
|
| 158 |
|
| 159 |
/* Elevation (Shadows) */
|
| 160 |
-
--md-sys-elevation-1: 0px 1px 2px 0px rgba(0, 0, 0, 0.3),
|
| 161 |
-
|
| 162 |
-
--md-sys-elevation-
|
| 163 |
-
|
| 164 |
-
--md-sys-elevation-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
/* Mobile Layout Constants */
|
| 167 |
--header-height-mobile: calc(52px + env(safe-area-inset-top, 0px));
|
|
|
|
| 109 |
--md-sys-color-on-primary-container: #E0E7FF;
|
| 110 |
/* Indigo 100 */
|
| 111 |
|
| 112 |
+
.touch-callout-none {
|
| 113 |
+
-webkit-touch-callout: none !important;
|
| 114 |
+
-webkit-user-select: none !important;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
--md-sys-color-secondary: var(--secondary);
|
| 118 |
--md-sys-color-on-secondary: #FFFFFF;
|
| 119 |
--md-sys-color-secondary-container: #4C1D95;
|
|
|
|
| 161 |
--md-sys-color-outline-variant: var(--border-hover);
|
| 162 |
|
| 163 |
/* Elevation (Shadows) */
|
| 164 |
+
--md-sys-elevation-1: 0px 1px 2px 0px rgba(0, 0, 0, 0.3),
|
| 165 |
+
0px 1px 3px 1px rgba(0, 0, 0, 0.15);
|
| 166 |
+
--md-sys-elevation-2: 0px 1px 2px 0px rgba(0, 0, 0, 0.3),
|
| 167 |
+
0px 2px 6px 2px rgba(0, 0, 0, 0.15);
|
| 168 |
+
--md-sys-elevation-3: 0px 1px 3px 0px rgba(0, 0, 0, 0.3),
|
| 169 |
+
0px 4px 8px 3px rgba(0, 0, 0, 0.15);
|
| 170 |
+
--md-sys-elevation-4: 0px 2px 3px 0px rgba(0, 0, 0, 0.3),
|
| 171 |
+
0px 6px 10px 4px rgba(0, 0, 0, 0.15);
|
| 172 |
+
--md-sys-elevation-5: 0px 4px 4px 0px rgba(0, 0, 0, 0.3),
|
| 173 |
+
0px 8px 12px 6px rgba(0, 0, 0, 0.15);
|
| 174 |
|
| 175 |
/* Mobile Layout Constants */
|
| 176 |
--header-height-mobile: calc(52px + env(safe-area-inset-top, 0px));
|
frontend/components/ChatWindow.tsx
CHANGED
|
@@ -168,6 +168,12 @@ export function ChatWindow({
|
|
| 168 |
if (prev.some(m => m.id === newMessage.id)) return prev
|
| 169 |
return [...prev, newMessage]
|
| 170 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
})
|
| 172 |
return () => { unsubscribe() }
|
| 173 |
}, [leadId, tenantId, conversationId])
|
|
@@ -178,6 +184,13 @@ export function ChatWindow({
|
|
| 178 |
onNewMessage: (newMessage) => {
|
| 179 |
console.log('🔔 WebSocket: New message received', newMessage.id, newMessage.content?.substring(0, 50))
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
setRealtimeMessages(prev => {
|
| 182 |
// Check if message already exists
|
| 183 |
const existingIndex = prev.findIndex(m => m.id === newMessage.id)
|
|
@@ -251,7 +264,7 @@ export function ChatWindow({
|
|
| 251 |
if (!confirm('Удалить сообщение?')) return
|
| 252 |
|
| 253 |
try {
|
| 254 |
-
const token = localStorage.getItem('
|
| 255 |
if (!token) throw new Error('Не авторизован')
|
| 256 |
|
| 257 |
const response = await fetch(
|
|
|
|
| 168 |
if (prev.some(m => m.id === newMessage.id)) return prev
|
| 169 |
return [...prev, newMessage]
|
| 170 |
})
|
| 171 |
+
// If we got a real message from us, clear optimistic state to avoid duplication
|
| 172 |
+
if (newMessage.sender_type === 'human' || newMessage.sender_type === 'ai') {
|
| 173 |
+
setOptimisticMessages(prev => prev.filter(m =>
|
| 174 |
+
m.content !== newMessage.content || m.sender_type !== newMessage.sender_type
|
| 175 |
+
))
|
| 176 |
+
}
|
| 177 |
})
|
| 178 |
return () => { unsubscribe() }
|
| 179 |
}, [leadId, tenantId, conversationId])
|
|
|
|
| 184 |
onNewMessage: (newMessage) => {
|
| 185 |
console.log('🔔 WebSocket: New message received', newMessage.id, newMessage.content?.substring(0, 50))
|
| 186 |
|
| 187 |
+
// Clear matching optimistic messages immediately to prevent duplication
|
| 188 |
+
if (newMessage.sender_type === 'human' || newMessage.sender_type === 'ai') {
|
| 189 |
+
setOptimisticMessages(prev => prev.filter(m =>
|
| 190 |
+
m.content !== newMessage.content || m.sender_type !== newMessage.sender_type
|
| 191 |
+
))
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
setRealtimeMessages(prev => {
|
| 195 |
// Check if message already exists
|
| 196 |
const existingIndex = prev.findIndex(m => m.id === newMessage.id)
|
|
|
|
| 264 |
if (!confirm('Удалить сообщение?')) return
|
| 265 |
|
| 266 |
try {
|
| 267 |
+
const token = localStorage.getItem('auth_token')
|
| 268 |
if (!token) throw new Error('Не авторизован')
|
| 269 |
|
| 270 |
const response = await fetch(
|
frontend/components/ChatWindow/ChatHeader.tsx
CHANGED
|
@@ -95,58 +95,37 @@ export function ChatHeader({
|
|
| 95 |
</button>
|
| 96 |
|
| 97 |
{/* AI Toggle Switch - FIXED UI */}
|
| 98 |
-
<div className="flex items-center gap-2">
|
| 99 |
<button
|
| 100 |
onClick={onToggleAI}
|
| 101 |
disabled={isTogglingAI}
|
| 102 |
className={cn(
|
| 103 |
-
"relative w-
|
| 104 |
isAIActive
|
| 105 |
-
? "bg-indigo-
|
| 106 |
-
: "bg-white/
|
| 107 |
isTogglingAI && "opacity-80"
|
| 108 |
)}
|
| 109 |
title={isAIActive ? 'AI Активен' : 'AI Отключен'}
|
| 110 |
>
|
| 111 |
-
{/*
|
| 112 |
-
<div
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
isTogglingAI && "opacity-80"
|
| 125 |
-
)}
|
| 126 |
-
style={{
|
| 127 |
-
width: '48px',
|
| 128 |
-
minWidth: '48px',
|
| 129 |
-
height: '24px',
|
| 130 |
-
borderRadius: '24px',
|
| 131 |
-
}}
|
| 132 |
-
title={isAIActive ? 'AI Активен' : 'AI Отключен'}
|
| 133 |
-
>
|
| 134 |
-
{/* Thumb */}
|
| 135 |
-
<motion.div
|
| 136 |
-
animate={{
|
| 137 |
-
x: isAIActive ? 26 : 2,
|
| 138 |
-
scale: isTogglingAI ? 0.85 : 1,
|
| 139 |
-
}}
|
| 140 |
-
transition={{ type: "spring", stiffness: 500, damping: 30 }}
|
| 141 |
-
className="absolute top-[2px] w-[18px] h-[18px] rounded-full bg-white shadow-md flex items-center justify-center z-10"
|
| 142 |
-
>
|
| 143 |
-
{isTogglingAI && (
|
| 144 |
-
<Loader2 className="w-3 h-3 animate-spin text-indigo-500" />
|
| 145 |
-
)}
|
| 146 |
-
</motion.div>
|
| 147 |
-
</button>
|
| 148 |
-
</div>
|
| 149 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
</div>
|
| 151 |
|
| 152 |
{/* AI Summary Button */}
|
|
|
|
| 95 |
</button>
|
| 96 |
|
| 97 |
{/* AI Toggle Switch - FIXED UI */}
|
| 98 |
+
<div className="flex items-center gap-2 flex-shrink-0">
|
| 99 |
<button
|
| 100 |
onClick={onToggleAI}
|
| 101 |
disabled={isTogglingAI}
|
| 102 |
className={cn(
|
| 103 |
+
"relative w-12 h-6 rounded-full transition-all duration-300 flex-shrink-0 border block",
|
| 104 |
isAIActive
|
| 105 |
+
? "bg-indigo-500 border-indigo-400 shadow-[0_2px_8px_rgba(99,102,241,0.3)]"
|
| 106 |
+
: "bg-white/10 border-white/10 hover:bg-white/20",
|
| 107 |
isTogglingAI && "opacity-80"
|
| 108 |
)}
|
| 109 |
title={isAIActive ? 'AI Активен' : 'AI Отключен'}
|
| 110 |
>
|
| 111 |
+
{/* Thumb */}
|
| 112 |
+
<motion.div
|
| 113 |
+
animate={{
|
| 114 |
+
x: isAIActive ? 26 : 2,
|
| 115 |
+
scale: isTogglingAI ? 0.8 : 1,
|
| 116 |
+
}}
|
| 117 |
+
transition={{ type: "spring", stiffness: 500, damping: 30 }}
|
| 118 |
+
className="absolute top-[2px] w-[18px] h-[18px] rounded-full bg-white shadow-sm flex items-center justify-center z-10"
|
| 119 |
+
>
|
| 120 |
+
{isTogglingAI && (
|
| 121 |
+
<Loader2 className="w-3 h-3 animate-spin text-indigo-500" />
|
| 122 |
+
)}
|
| 123 |
+
</motion.div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
</button>
|
| 125 |
+
<Brain className={cn(
|
| 126 |
+
"w-4 h-4 transition-colors duration-300 flex-shrink-0",
|
| 127 |
+
isAIActive ? "text-indigo-400" : "text-slate-600"
|
| 128 |
+
)} />
|
| 129 |
</div>
|
| 130 |
|
| 131 |
{/* AI Summary Button */}
|
frontend/components/ChatWindow/MessageBubble.tsx
CHANGED
|
@@ -264,71 +264,70 @@ export function MessageBubble({
|
|
| 264 |
</div>
|
| 265 |
|
| 266 |
{/* Message Bubble */}
|
| 267 |
-
<div className=
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
</div>
|
| 284 |
-
{!isSequence && (
|
| 285 |
-
<div className={cn(
|
| 286 |
-
"flex items-center gap-1 px-1",
|
| 287 |
-
isMe ? "justify-end" : "justify-start"
|
| 288 |
-
)}>
|
| 289 |
-
<span className="text-[10px] text-slate-400">
|
| 290 |
-
{formatDate(message.created_at)}
|
| 291 |
-
</span>
|
| 292 |
-
{/* Delete button - only for own non-AI messages */}
|
| 293 |
-
{isMe && !isAI && onDelete && (
|
| 294 |
-
<button
|
| 295 |
-
onClick={() => onDelete(message.id)}
|
| 296 |
-
className="opacity-0 group-hover:opacity-100 p-1 text-slate-500 hover:text-red-400 rounded transition-all"
|
| 297 |
-
title="Удалить сообщение"
|
| 298 |
-
>
|
| 299 |
-
<Trash2 className="w-3 h-3" />
|
| 300 |
-
</button>
|
| 301 |
-
)}
|
| 302 |
-
</div>
|
| 303 |
-
)}
|
| 304 |
</div>
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
{/* Context Menu Popup */}
|
| 308 |
-
{showContextMenu && canDelete && (
|
| 309 |
-
<>
|
| 310 |
-
{/* Backdrop */}
|
| 311 |
-
<div
|
| 312 |
-
className="fixed inset-0 z-40"
|
| 313 |
-
onClick={() => setShowContextMenu(false)}
|
| 314 |
-
/>
|
| 315 |
-
{/* Menu */}
|
| 316 |
<div className={cn(
|
| 317 |
-
"
|
| 318 |
-
isMe ? "
|
| 319 |
-
"top-full mt-1"
|
| 320 |
)}>
|
| 321 |
-
<
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
</div>
|
| 329 |
-
|
| 330 |
-
|
| 331 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 332 |
</div>
|
| 333 |
)
|
| 334 |
}
|
|
|
|
| 264 |
</div>
|
| 265 |
|
| 266 |
{/* Message Bubble */}
|
| 267 |
+
<div className={cn(
|
| 268 |
+
"px-4 py-2.5 text-sm leading-relaxed shadow-sm relative break-words select-none",
|
| 269 |
+
"touch-callout-none", // We'll add this to globals.css
|
| 270 |
+
isMe
|
| 271 |
+
? "bg-gradient-to-r from-indigo-600 to-violet-600 text-white rounded-2xl rounded-br-none shadow-[0_4px_15px_-3px_rgba(99,102,241,0.3)]"
|
| 272 |
+
: "bg-[#1E2030] text-slate-200 border border-white/5 rounded-2xl rounded-bl-none",
|
| 273 |
+
isSequence && isMe && "rounded-tr-md rounded-br-md",
|
| 274 |
+
isSequence && !isMe && "rounded-tl-md rounded-bl-md",
|
| 275 |
+
// If only media and no text, remove padding
|
| 276 |
+
hasMedia && !hasText && "p-2"
|
| 277 |
+
)}>
|
| 278 |
+
{/* Text content */}
|
| 279 |
+
{hasText && message.content}
|
| 280 |
|
| 281 |
+
{/* Media content (audio, image, video, file) */}
|
| 282 |
+
<MediaContent message={message} isMe={isMe} onImageClick={onImageClick} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
</div>
|
| 284 |
+
{!isSequence && (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
<div className={cn(
|
| 286 |
+
"flex items-center gap-1 px-1",
|
| 287 |
+
isMe ? "justify-end" : "justify-start"
|
|
|
|
| 288 |
)}>
|
| 289 |
+
<span className="text-[10px] text-slate-400">
|
| 290 |
+
{formatDate(message.created_at)}
|
| 291 |
+
</span>
|
| 292 |
+
{/* Delete button - only for own non-AI messages */}
|
| 293 |
+
{isMe && !isAI && onDelete && (
|
| 294 |
+
<button
|
| 295 |
+
onClick={() => onDelete(message.id)}
|
| 296 |
+
className="opacity-0 group-hover:opacity-100 p-1 text-slate-500 hover:text-red-400 rounded transition-all"
|
| 297 |
+
title="Удалить сообщение"
|
| 298 |
+
>
|
| 299 |
+
<Trash2 className="w-3 h-3" />
|
| 300 |
+
</button>
|
| 301 |
+
)}
|
| 302 |
</div>
|
| 303 |
+
)}
|
| 304 |
+
</div>
|
| 305 |
</div>
|
| 306 |
+
|
| 307 |
+
{/* Context Menu Popup */}
|
| 308 |
+
{showContextMenu && canDelete && (
|
| 309 |
+
<>
|
| 310 |
+
{/* Backdrop */}
|
| 311 |
+
<div
|
| 312 |
+
className="fixed inset-0 z-40"
|
| 313 |
+
onClick={() => setShowContextMenu(false)}
|
| 314 |
+
/>
|
| 315 |
+
{/* Menu */}
|
| 316 |
+
<div className={cn(
|
| 317 |
+
"absolute z-50 bg-[#1E2030] border border-white/10 rounded-lg shadow-xl py-1 min-w-[120px]",
|
| 318 |
+
isMe ? "right-0" : "left-0",
|
| 319 |
+
"top-full mt-1"
|
| 320 |
+
)}>
|
| 321 |
+
<button
|
| 322 |
+
onClick={handleDelete}
|
| 323 |
+
className="w-full px-3 py-2 text-sm text-red-400 hover:bg-red-500/10 flex items-center gap-2"
|
| 324 |
+
>
|
| 325 |
+
<Trash2 className="w-4 h-4" />
|
| 326 |
+
Удалить
|
| 327 |
+
</button>
|
| 328 |
+
</div>
|
| 329 |
+
</>
|
| 330 |
+
)}
|
| 331 |
</div>
|
| 332 |
)
|
| 333 |
}
|
frontend/components/ChatWindow/MessageInput.tsx
CHANGED
|
@@ -295,9 +295,13 @@ export function MessageInput({
|
|
| 295 |
onChange={(e) => onChange(e.target.value)}
|
| 296 |
onKeyDown={handleKeyDown}
|
| 297 |
placeholder="Написать..."
|
| 298 |
-
className="flex-1 bg-white/5 border border-white/
|
| 299 |
rows={1}
|
| 300 |
-
style={{
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
disabled={disabled || isRecording}
|
| 302 |
/>
|
| 303 |
|
|
|
|
| 295 |
onChange={(e) => onChange(e.target.value)}
|
| 296 |
onKeyDown={handleKeyDown}
|
| 297 |
placeholder="Написать..."
|
| 298 |
+
className="flex-1 bg-white/5 border border-white/10 rounded-[22px] focus:ring-1 focus:ring-indigo-500/30 focus:border-indigo-500/30 focus:bg-white/10 resize-none max-h-32 py-2.5 px-4 text-[16px] leading-relaxed text-white placeholder:text-slate-600 overflow-y-auto transition-all shadow-inner appearance-none"
|
| 299 |
rows={1}
|
| 300 |
+
style={{
|
| 301 |
+
minHeight: '44px',
|
| 302 |
+
display: 'flex',
|
| 303 |
+
alignItems: 'center'
|
| 304 |
+
}}
|
| 305 |
disabled={disabled || isRecording}
|
| 306 |
/>
|
| 307 |
|