Spaces:
Running
Running
axeronis commited on
Commit ·
4147439
1
Parent(s): d57223b
feat(ui): final polish for mobile chat UI, AI toggle switch, and reliable voice recording
Browse files
frontend/components/ChatWindow.tsx
CHANGED
|
@@ -365,24 +365,11 @@ export function ChatWindow({
|
|
| 365 |
// ============================================================================
|
| 366 |
|
| 367 |
return (
|
| 368 |
-
<
|
| 369 |
-
|
| 370 |
-
dragConstraints={{ left: 0, right: 0 }}
|
| 371 |
-
dragElastic={0.1}
|
| 372 |
-
onDragEnd={(_, info) => {
|
| 373 |
-
const threshold = 50 // Responsive threshold
|
| 374 |
-
if (info.offset.x > threshold) {
|
| 375 |
-
// Swipe Right -> Back to list
|
| 376 |
-
onBack?.()
|
| 377 |
-
} else if (info.offset.x < -threshold) {
|
| 378 |
-
// Swipe Left -> Open AI Analysis
|
| 379 |
-
onOpenMobileDrawer?.()
|
| 380 |
-
}
|
| 381 |
-
}}
|
| 382 |
-
className="flex flex-col h-full bg-transparent font-['Inter'] relative overflow-hidden touch-pan-y"
|
| 383 |
style={{
|
| 384 |
-
|
| 385 |
-
|
| 386 |
}}
|
| 387 |
>
|
| 388 |
{/* Background Atmosphere - Synced with Main Layout */}
|
|
@@ -408,10 +395,10 @@ export function ChatWindow({
|
|
| 408 |
|
| 409 |
{/* Messages Area */}
|
| 410 |
<div
|
| 411 |
-
className="flex-1 overflow-y-auto px-4 md:px-6 space-y-6 scrollbar-
|
| 412 |
style={{
|
| 413 |
WebkitOverflowScrolling: 'touch',
|
| 414 |
-
|
| 415 |
}}
|
| 416 |
>
|
| 417 |
{/* Top spacer to show content blurring behind header when scrolling */}
|
|
|
|
| 365 |
// ============================================================================
|
| 366 |
|
| 367 |
return (
|
| 368 |
+
<div
|
| 369 |
+
className="flex flex-col h-full bg-transparent font-['Inter'] relative overflow-hidden"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
style={{
|
| 371 |
+
paddingTop: 'var(--header-height-mobile)',
|
| 372 |
+
paddingBottom: 'var(--footer-height-mobile)'
|
| 373 |
}}
|
| 374 |
>
|
| 375 |
{/* Background Atmosphere - Synced with Main Layout */}
|
|
|
|
| 395 |
|
| 396 |
{/* Messages Area */}
|
| 397 |
<div
|
| 398 |
+
className="flex-1 overflow-y-auto px-4 md:px-6 space-y-6 scrollbar-none"
|
| 399 |
style={{
|
| 400 |
WebkitOverflowScrolling: 'touch',
|
| 401 |
+
scrollBehavior: 'smooth'
|
| 402 |
}}
|
| 403 |
>
|
| 404 |
{/* Top spacer to show content blurring behind header when scrolling */}
|
frontend/components/ChatWindow/ChatHeader.tsx
CHANGED
|
@@ -33,9 +33,9 @@ export function ChatHeader({
|
|
| 33 |
onTrainAI,
|
| 34 |
}: ChatHeaderProps) {
|
| 35 |
return (
|
| 36 |
-
<div className="h-[52px] md:h-16 shrink-0 flex items-center justify-between px-3 md:px-6 relative z-[50] bg-[#050510]/
|
| 37 |
{/* Aurora Background Atmosphere - Synced */}
|
| 38 |
-
<div className="absolute inset-0 pointer-events-none overflow-hidden -z-10 bg-gradient-to-r from-indigo-500/
|
| 39 |
|
| 40 |
{/* Left: Lead Info */}
|
| 41 |
<div className="flex items-center gap-2 md:gap-3 overflow-hidden">
|
|
@@ -43,7 +43,7 @@ export function ChatHeader({
|
|
| 43 |
<div className="md:hidden">
|
| 44 |
<button
|
| 45 |
onClick={onBack}
|
| 46 |
-
className="p-
|
| 47 |
>
|
| 48 |
<ArrowLeft className="w-5 h-5" />
|
| 49 |
</button>
|
|
@@ -86,37 +86,42 @@ export function ChatHeader({
|
|
| 86 |
Записать
|
| 87 |
</button>
|
| 88 |
|
| 89 |
-
{/* AI Toggle Switch - FIXED UI */}
|
| 90 |
<div className="flex items-center gap-2">
|
| 91 |
<button
|
| 92 |
onClick={onToggleAI}
|
| 93 |
disabled={isTogglingAI}
|
| 94 |
className={cn(
|
| 95 |
-
"relative w-
|
| 96 |
isAIActive
|
| 97 |
-
? "bg-indigo-600/
|
| 98 |
-
: "bg-
|
| 99 |
isTogglingAI && "opacity-80"
|
| 100 |
)}
|
| 101 |
title={isAIActive ? 'AI Активен' : 'AI Отключен'}
|
| 102 |
>
|
| 103 |
<motion.div
|
| 104 |
animate={{
|
| 105 |
-
x: isAIActive ?
|
| 106 |
-
scale: isTogglingAI ? 0.
|
| 107 |
}}
|
| 108 |
-
transition={{ type: "spring", stiffness:
|
| 109 |
className={cn(
|
| 110 |
-
"absolute top-
|
| 111 |
isAIActive
|
| 112 |
-
? "bg-white shadow-[
|
| 113 |
-
: "bg-slate-500"
|
| 114 |
)}
|
| 115 |
>
|
| 116 |
{isTogglingAI && (
|
| 117 |
<Loader2 className="w-2.5 h-2.5 animate-spin text-indigo-500" />
|
| 118 |
)}
|
| 119 |
</motion.div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
</button>
|
| 121 |
</div>
|
| 122 |
|
|
|
|
| 33 |
onTrainAI,
|
| 34 |
}: ChatHeaderProps) {
|
| 35 |
return (
|
| 36 |
+
<div className="h-[52px] md:h-16 shrink-0 flex items-center justify-between px-3 md:px-6 relative z-[50] bg-[#050510]/80 backdrop-blur-2xl border-b border-white/10">
|
| 37 |
{/* Aurora Background Atmosphere - Synced */}
|
| 38 |
+
<div className="absolute inset-0 pointer-events-none overflow-hidden -z-10 bg-gradient-to-r from-indigo-500/10 to-purple-500/10 opacity-30 blur-2xl" />
|
| 39 |
|
| 40 |
{/* Left: Lead Info */}
|
| 41 |
<div className="flex items-center gap-2 md:gap-3 overflow-hidden">
|
|
|
|
| 43 |
<div className="md:hidden">
|
| 44 |
<button
|
| 45 |
onClick={onBack}
|
| 46 |
+
className="p-2 -ml-1 text-slate-400 hover:text-white hover:bg-white/10 rounded-full transition-colors active:scale-90"
|
| 47 |
>
|
| 48 |
<ArrowLeft className="w-5 h-5" />
|
| 49 |
</button>
|
|
|
|
| 86 |
Записать
|
| 87 |
</button>
|
| 88 |
|
| 89 |
+
{/* AI Toggle Switch - FIXED PILL UI */}
|
| 90 |
<div className="flex items-center gap-2">
|
| 91 |
<button
|
| 92 |
onClick={onToggleAI}
|
| 93 |
disabled={isTogglingAI}
|
| 94 |
className={cn(
|
| 95 |
+
"relative w-[52px] h-[26px] rounded-full transition-all duration-500 flex-shrink-0 border-2",
|
| 96 |
isAIActive
|
| 97 |
+
? "bg-indigo-600/40 border-indigo-500/60 shadow-[0_0_15px_rgba(99,102,241,0.3)]"
|
| 98 |
+
: "bg-slate-800/80 border-slate-700/50",
|
| 99 |
isTogglingAI && "opacity-80"
|
| 100 |
)}
|
| 101 |
title={isAIActive ? 'AI Активен' : 'AI Отключен'}
|
| 102 |
>
|
| 103 |
<motion.div
|
| 104 |
animate={{
|
| 105 |
+
x: isAIActive ? 28 : 4,
|
| 106 |
+
scale: isTogglingAI ? 0.9 : 1,
|
| 107 |
}}
|
| 108 |
+
transition={{ type: "spring", stiffness: 500, damping: 30 }}
|
| 109 |
className={cn(
|
| 110 |
+
"absolute top-[3px] w-4 h-4 rounded-full flex items-center justify-center transition-all duration-300 z-10",
|
| 111 |
isAIActive
|
| 112 |
+
? "bg-white shadow-[0_0_12px_rgba(255,255,255,0.6)]"
|
| 113 |
+
: "bg-slate-500 shadow-inner"
|
| 114 |
)}
|
| 115 |
>
|
| 116 |
{isTogglingAI && (
|
| 117 |
<Loader2 className="w-2.5 h-2.5 animate-spin text-indigo-500" />
|
| 118 |
)}
|
| 119 |
</motion.div>
|
| 120 |
+
{/* Background labels/icons for more clarity */}
|
| 121 |
+
<div className="flex justify-between items-center px-1.5 h-full pointer-events-none opacity-40">
|
| 122 |
+
<Bot className={cn("w-3 h-3 text-white", !isAIActive && "invisible")} />
|
| 123 |
+
<Sparkles className={cn("w-3 h-3 text-white", isAIActive && "invisible")} />
|
| 124 |
+
</div>
|
| 125 |
</button>
|
| 126 |
</div>
|
| 127 |
|
frontend/components/ChatWindow/MessageInput.tsx
CHANGED
|
@@ -37,26 +37,28 @@ export function MessageInput({
|
|
| 37 |
}
|
| 38 |
}
|
| 39 |
|
| 40 |
-
const
|
| 41 |
-
e.preventDefault()
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
}
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
| 47 |
setSelectedFile(null)
|
| 48 |
setPendingAudio(null)
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
const handleFileSelect = (e: React.ChangeEvent<HTMLInputElement>) => {
|
| 52 |
-
if (e.target.files && e.target.files[0]) {
|
| 53 |
-
setSelectedFile(e.target.files[0])
|
| 54 |
-
setPendingAudio(null) // Clear audio if file selected
|
| 55 |
-
}
|
| 56 |
}
|
| 57 |
|
| 58 |
const startRecording = async () => {
|
| 59 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
const stream = await navigator.mediaDevices.getUserMedia({ audio: true })
|
| 61 |
streamRef.current = stream
|
| 62 |
const mediaRecorder = new MediaRecorder(stream)
|
|
@@ -64,18 +66,14 @@ export function MessageInput({
|
|
| 64 |
chunksRef.current = []
|
| 65 |
|
| 66 |
mediaRecorder.ondataavailable = (e) => {
|
| 67 |
-
if (e.data.size > 0)
|
| 68 |
-
chunksRef.current.push(e.data)
|
| 69 |
-
}
|
| 70 |
}
|
| 71 |
|
| 72 |
mediaRecorder.onstop = () => {
|
| 73 |
-
// Save to pending instead of sending
|
| 74 |
if (chunksRef.current.length > 0) {
|
| 75 |
const blob = new Blob(chunksRef.current, { type: 'audio/webm' })
|
| 76 |
setPendingAudio(blob)
|
| 77 |
}
|
| 78 |
-
// Cleanup stream
|
| 79 |
streamRef.current?.getTracks().forEach(track => track.stop())
|
| 80 |
streamRef.current = null
|
| 81 |
}
|
|
@@ -84,12 +82,20 @@ export function MessageInput({
|
|
| 84 |
setIsRecording(true)
|
| 85 |
} catch (err) {
|
| 86 |
console.error('Error accessing microphone:', err)
|
| 87 |
-
alert('Не удалось получить доступ к микрофону')
|
| 88 |
}
|
| 89 |
}
|
| 90 |
|
| 91 |
-
const stopRecording = () => {
|
| 92 |
if (mediaRecorderRef.current && isRecording) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
mediaRecorderRef.current.stop()
|
| 94 |
setIsRecording(false)
|
| 95 |
}
|
|
@@ -98,10 +104,10 @@ export function MessageInput({
|
|
| 98 |
const cancelRecording = () => {
|
| 99 |
if (mediaRecorderRef.current && isRecording) {
|
| 100 |
chunksRef.current = []
|
|
|
|
| 101 |
mediaRecorderRef.current.stop()
|
| 102 |
setIsRecording(false)
|
| 103 |
}
|
| 104 |
-
// Also cleanup stream immediately
|
| 105 |
streamRef.current?.getTracks().forEach(track => track.stop())
|
| 106 |
streamRef.current = null
|
| 107 |
}
|
|
@@ -117,12 +123,10 @@ export function MessageInput({
|
|
| 117 |
|
| 118 |
const toggleAudioPreview = () => {
|
| 119 |
if (!pendingAudio) return
|
| 120 |
-
|
| 121 |
if (!audioPreviewRef.current) {
|
| 122 |
audioPreviewRef.current = new Audio(URL.createObjectURL(pendingAudio))
|
| 123 |
audioPreviewRef.current.onended = () => setIsPlayingPreview(false)
|
| 124 |
}
|
| 125 |
-
|
| 126 |
if (isPlayingPreview) {
|
| 127 |
audioPreviewRef.current.pause()
|
| 128 |
setIsPlayingPreview(false)
|
|
@@ -133,92 +137,90 @@ export function MessageInput({
|
|
| 133 |
}
|
| 134 |
|
| 135 |
return (
|
| 136 |
-
<div className="px-2 sm:px-3 pb-[calc(env(safe-area-inset-bottom,0px)+
|
| 137 |
<div className="max-w-4xl mx-auto relative">
|
| 138 |
{/* File Preview */}
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
<
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
{/* Audio Preview */}
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
onClick={toggleAudioPreview}
|
| 162 |
-
className="w-8 h-8 rounded-full bg-indigo-500/20 flex items-center justify-center text-indigo-400 hover:bg-indigo-500/30"
|
| 163 |
>
|
| 164 |
-
{isPlayingPreview ? <Pause className="w-4 h-4" /> : <Play className="w-4 h-4 ml-0.5" />}
|
| 165 |
-
</button>
|
| 166 |
-
<span className="text-xs text-indigo-300 font-medium">🎤 Готовое сообщение</span>
|
| 167 |
-
<button onClick={clearPendingAudio} className="p-1 hover:bg-white/10 rounded-full">
|
| 168 |
-
<X className="w-3 h-3 text-slate-400" />
|
| 169 |
-
</button>
|
| 170 |
-
</motion.div>
|
| 171 |
-
)}
|
| 172 |
-
|
| 173 |
-
{/* Audio Recording UI */}
|
| 174 |
-
{isRecording && (
|
| 175 |
-
<motion.div
|
| 176 |
-
initial={{ opacity: 0, scale: 0.95 }}
|
| 177 |
-
animate={{ opacity: 1, scale: 1 }}
|
| 178 |
-
className="absolute inset-0 bg-[#050510]/95 backdrop-blur-2xl rounded-2xl border border-red-500/30 flex items-center justify-between px-4 z-40 shadow-2xl"
|
| 179 |
-
>
|
| 180 |
-
<div className="flex items-center gap-3 text-red-400">
|
| 181 |
-
<div className="flex gap-1 items-end h-4">
|
| 182 |
-
<div className="w-1 bg-red-500 rounded-full animate-[voice-wave_1s_infinite_0s]" style={{ height: '60%' }} />
|
| 183 |
-
<div className="w-1 bg-red-500 rounded-full animate-[voice-wave_1s_infinite_0.2s]" style={{ height: '100%' }} />
|
| 184 |
-
<div className="w-1 bg-red-500 rounded-full animate-[voice-wave_1s_infinite_0.4s]" style={{ height: '40%' }} />
|
| 185 |
-
<div className="w-1 bg-red-500 rounded-full animate-[voice-wave_1s_infinite_0.1s]" style={{ height: '80%' }} />
|
| 186 |
-
</div>
|
| 187 |
-
<span className="text-sm font-bold tracking-tight">ЗАПИСЬ...</span>
|
| 188 |
-
</div>
|
| 189 |
-
<div className="flex items-center gap-3">
|
| 190 |
<button
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
className="p-2.5 bg-white/5 text-slate-400 rounded-full hover:bg-white/10 hover:text-white transition-all active:scale-90"
|
| 194 |
-
title="Отменить"
|
| 195 |
>
|
| 196 |
-
<
|
| 197 |
</button>
|
| 198 |
-
<
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
e.preventDefault();
|
| 202 |
-
e.stopPropagation();
|
| 203 |
-
stopRecording();
|
| 204 |
-
// Trigger submission via a small timeout to allow onstop to finish
|
| 205 |
-
setTimeout(() => {
|
| 206 |
-
const form = (e.target as HTMLElement).closest('form');
|
| 207 |
-
if (form) form.requestSubmit();
|
| 208 |
-
}, 100);
|
| 209 |
-
}}
|
| 210 |
-
className="p-2.5 bg-red-500/20 text-red-500 rounded-full hover:bg-red-500/30 transition-all active:scale-90 shadow-[0_0_15px_rgba(239,68,68,0.2)]"
|
| 211 |
-
title="Готово"
|
| 212 |
-
>
|
| 213 |
-
<Send className="w-5 h-5" />
|
| 214 |
</button>
|
| 215 |
-
</div>
|
| 216 |
-
|
| 217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
|
| 219 |
<form
|
| 220 |
-
onSubmit={
|
| 221 |
-
className="flex items-center gap-1.5 px-0.5
|
| 222 |
>
|
| 223 |
<input
|
| 224 |
type="file"
|
|
@@ -228,13 +230,13 @@ export function MessageInput({
|
|
| 228 |
accept="image/*,.pdf,.txt,.doc,.docx"
|
| 229 |
/>
|
| 230 |
|
| 231 |
-
<div className="flex items-center">
|
| 232 |
<button
|
| 233 |
type="button"
|
| 234 |
onClick={() => fileInputRef.current?.click()}
|
| 235 |
className={cn(
|
| 236 |
"p-2.5 rounded-full transition-all active:scale-90",
|
| 237 |
-
selectedFile ? "text-indigo-400 bg-indigo-500/10" : "text-slate-
|
| 238 |
)}
|
| 239 |
>
|
| 240 |
<Paperclip className="w-5 h-5" />
|
|
@@ -248,7 +250,7 @@ export function MessageInput({
|
|
| 248 |
onTouchEnd={(e) => { e.preventDefault(); stopRecording(); }}
|
| 249 |
className={cn(
|
| 250 |
"p-2.5 rounded-full transition-all active:scale-95",
|
| 251 |
-
isRecording ? "text-red-
|
| 252 |
)}
|
| 253 |
disabled={!!selectedFile}
|
| 254 |
>
|
|
@@ -261,7 +263,7 @@ export function MessageInput({
|
|
| 261 |
onChange={(e) => onChange(e.target.value)}
|
| 262 |
onKeyDown={handleKeyDown}
|
| 263 |
placeholder="Написать..."
|
| 264 |
-
className="flex-1 bg-white/
|
| 265 |
rows={1}
|
| 266 |
style={{ minHeight: '44px' }}
|
| 267 |
disabled={disabled || isRecording}
|
|
@@ -271,10 +273,10 @@ export function MessageInput({
|
|
| 271 |
type="submit"
|
| 272 |
disabled={(!value.trim() && !selectedFile && !pendingAudio) || isSending || disabled}
|
| 273 |
className={cn(
|
| 274 |
-
"p-2.5 rounded-full transition-all duration-300 flex items-center justify-center",
|
| 275 |
((value.trim() || selectedFile || pendingAudio) && !isSending && !disabled)
|
| 276 |
-
? "text-indigo-400 bg-indigo-500/
|
| 277 |
-
: "text-slate-
|
| 278 |
)}
|
| 279 |
>
|
| 280 |
{isSending ? (
|
|
@@ -282,17 +284,14 @@ export function MessageInput({
|
|
| 282 |
) : (
|
| 283 |
<Send className={cn(
|
| 284 |
"w-5 h-5",
|
| 285 |
-
((value.trim() || selectedFile || pendingAudio) && !isSending && !disabled) && "fill-indigo-400
|
| 286 |
)} />
|
| 287 |
)}
|
| 288 |
</button>
|
| 289 |
</form>
|
| 290 |
-
<div className="hidden md:block text-center mt-2">
|
| 291 |
-
<p className="text-[10px] text-slate-400 font-medium">
|
| 292 |
-
Enter для отправки • Shift + Enter для переноса
|
| 293 |
-
</p>
|
| 294 |
-
</div>
|
| 295 |
</div>
|
| 296 |
</div>
|
| 297 |
)
|
|
|
|
|
|
|
| 298 |
}
|
|
|
|
| 37 |
}
|
| 38 |
}
|
| 39 |
|
| 40 |
+
const handleSendMessage = (e: React.FormEvent, file?: File | null, audioBlob?: Blob | null) => {
|
| 41 |
+
if (e) e.preventDefault()
|
| 42 |
+
|
| 43 |
+
// If we have an explicit audioBlob (from stopRecording), use it
|
| 44 |
+
const finalAudio = audioBlob || pendingAudio
|
| 45 |
+
const textToSend = value.trim() || (finalAudio ? '🎤 Голосовое сообщение' : (file ? `📎 Файл: ${file.name}` : ''))
|
| 46 |
+
|
| 47 |
+
if (!textToSend && !file && !finalAudio) return
|
| 48 |
+
|
| 49 |
+
onSubmit(e, file, finalAudio)
|
| 50 |
setSelectedFile(null)
|
| 51 |
setPendingAudio(null)
|
| 52 |
+
onChange('') // Clear input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
}
|
| 54 |
|
| 55 |
const startRecording = async () => {
|
| 56 |
try {
|
| 57 |
+
// Haptic feedback if available
|
| 58 |
+
if (window.navigator && window.navigator.vibrate) {
|
| 59 |
+
window.navigator.vibrate(10);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
const stream = await navigator.mediaDevices.getUserMedia({ audio: true })
|
| 63 |
streamRef.current = stream
|
| 64 |
const mediaRecorder = new MediaRecorder(stream)
|
|
|
|
| 66 |
chunksRef.current = []
|
| 67 |
|
| 68 |
mediaRecorder.ondataavailable = (e) => {
|
| 69 |
+
if (e.data.size > 0) chunksRef.current.push(e.data)
|
|
|
|
|
|
|
| 70 |
}
|
| 71 |
|
| 72 |
mediaRecorder.onstop = () => {
|
|
|
|
| 73 |
if (chunksRef.current.length > 0) {
|
| 74 |
const blob = new Blob(chunksRef.current, { type: 'audio/webm' })
|
| 75 |
setPendingAudio(blob)
|
| 76 |
}
|
|
|
|
| 77 |
streamRef.current?.getTracks().forEach(track => track.stop())
|
| 78 |
streamRef.current = null
|
| 79 |
}
|
|
|
|
| 82 |
setIsRecording(true)
|
| 83 |
} catch (err) {
|
| 84 |
console.error('Error accessing microphone:', err)
|
|
|
|
| 85 |
}
|
| 86 |
}
|
| 87 |
|
| 88 |
+
const stopRecording = (shouldSend = false) => {
|
| 89 |
if (mediaRecorderRef.current && isRecording) {
|
| 90 |
+
mediaRecorderRef.current.onstop = () => {
|
| 91 |
+
const blob = new Blob(chunksRef.current, { type: 'audio/webm' })
|
| 92 |
+
setPendingAudio(blob)
|
| 93 |
+
if (shouldSend) {
|
| 94 |
+
handleSendMessage(null as any, null, blob)
|
| 95 |
+
}
|
| 96 |
+
streamRef.current?.getTracks().forEach(track => track.stop())
|
| 97 |
+
streamRef.current = null
|
| 98 |
+
}
|
| 99 |
mediaRecorderRef.current.stop()
|
| 100 |
setIsRecording(false)
|
| 101 |
}
|
|
|
|
| 104 |
const cancelRecording = () => {
|
| 105 |
if (mediaRecorderRef.current && isRecording) {
|
| 106 |
chunksRef.current = []
|
| 107 |
+
mediaRecorderRef.current.onstop = null
|
| 108 |
mediaRecorderRef.current.stop()
|
| 109 |
setIsRecording(false)
|
| 110 |
}
|
|
|
|
| 111 |
streamRef.current?.getTracks().forEach(track => track.stop())
|
| 112 |
streamRef.current = null
|
| 113 |
}
|
|
|
|
| 123 |
|
| 124 |
const toggleAudioPreview = () => {
|
| 125 |
if (!pendingAudio) return
|
|
|
|
| 126 |
if (!audioPreviewRef.current) {
|
| 127 |
audioPreviewRef.current = new Audio(URL.createObjectURL(pendingAudio))
|
| 128 |
audioPreviewRef.current.onended = () => setIsPlayingPreview(false)
|
| 129 |
}
|
|
|
|
| 130 |
if (isPlayingPreview) {
|
| 131 |
audioPreviewRef.current.pause()
|
| 132 |
setIsPlayingPreview(false)
|
|
|
|
| 137 |
}
|
| 138 |
|
| 139 |
return (
|
| 140 |
+
<div className="px-2 sm:px-3 pb-[calc(env(safe-area-inset-bottom,0px)+8px)] pt-2 bg-[#050510]/80 backdrop-blur-2xl border-t border-white/10 flex-shrink-0 relative z-[110]">
|
| 141 |
<div className="max-w-4xl mx-auto relative">
|
| 142 |
{/* File Preview */}
|
| 143 |
+
<AnimatePresence>
|
| 144 |
+
{selectedFile && (
|
| 145 |
+
<motion.div
|
| 146 |
+
initial={{ opacity: 0, y: 10 }}
|
| 147 |
+
animate={{ opacity: 1, y: 0 }}
|
| 148 |
+
exit={{ opacity: 0, scale: 0.9 }}
|
| 149 |
+
className="absolute bottom-full left-0 mb-3 p-2 bg-indigo-600/90 backdrop-blur-xl rounded-xl border border-white/20 flex items-center gap-2 w-fit max-w-[calc(100%-20px)] shadow-[0_4px_20px_rgba(0,0,0,0.5)] z-50"
|
| 150 |
+
>
|
| 151 |
+
<Paperclip className="w-4 h-4 text-white shrink-0" />
|
| 152 |
+
<span className="text-xs text-white truncate font-medium">{selectedFile.name}</span>
|
| 153 |
+
<button onClick={() => setSelectedFile(null)} className="p-1 hover:bg-white/20 rounded-full transition-colors">
|
| 154 |
+
<X className="w-3.5 h-3.5 text-white/70" />
|
| 155 |
+
</button>
|
| 156 |
+
</motion.div>
|
| 157 |
+
)}
|
| 158 |
+
</AnimatePresence>
|
| 159 |
|
| 160 |
{/* Audio Preview */}
|
| 161 |
+
<AnimatePresence>
|
| 162 |
+
{pendingAudio && !isRecording && (
|
| 163 |
+
<motion.div
|
| 164 |
+
initial={{ opacity: 0, y: 10 }}
|
| 165 |
+
animate={{ opacity: 1, y: 0 }}
|
| 166 |
+
exit={{ opacity: 0, scale: 0.9 }}
|
| 167 |
+
className="absolute bottom-full left-0 mb-3 p-2 bg-indigo-600/90 backdrop-blur-xl rounded-xl border border-white/20 flex items-center gap-2 w-fit shadow-[0_4px_20px_rgba(0,0,0,0.5)] z-50"
|
|
|
|
|
|
|
| 168 |
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
<button
|
| 170 |
+
onClick={toggleAudioPreview}
|
| 171 |
+
className="w-8 h-8 rounded-full bg-white/20 flex items-center justify-center text-white hover:bg-white/30 transition-colors"
|
|
|
|
|
|
|
| 172 |
>
|
| 173 |
+
{isPlayingPreview ? <Pause className="w-4 h-4" /> : <Play className="w-4 h-4 ml-0.5" />}
|
| 174 |
</button>
|
| 175 |
+
<span className="text-xs text-white font-bold px-1">Голосовое готово</span>
|
| 176 |
+
<button onClick={clearPendingAudio} className="p-1 hover:bg-white/20 rounded-full transition-colors">
|
| 177 |
+
<X className="w-3.5 h-3.5 text-white/70" />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
</button>
|
| 179 |
+
</motion.div>
|
| 180 |
+
)}
|
| 181 |
+
</AnimatePresence>
|
| 182 |
+
|
| 183 |
+
{/* Audio Recording UI */}
|
| 184 |
+
<AnimatePresence>
|
| 185 |
+
{isRecording && (
|
| 186 |
+
<motion.div
|
| 187 |
+
initial={{ opacity: 0, scale: 0.98, y: 5 }}
|
| 188 |
+
animate={{ opacity: 1, scale: 1, y: 0 }}
|
| 189 |
+
exit={{ opacity: 0, scale: 0.98, y: 5 }}
|
| 190 |
+
className="absolute inset-0 bg-indigo-600/95 backdrop-blur-2xl rounded-[26px] border border-white/30 flex items-center justify-between px-4 z-[120] shadow-2xl"
|
| 191 |
+
>
|
| 192 |
+
<div className="flex items-center gap-3 text-white">
|
| 193 |
+
<div className="flex gap-1 items-end h-5 w-8">
|
| 194 |
+
<div className="w-1.5 bg-white/90 rounded-full animate-voice-wave" style={{ animationDelay: '0s', height: '40%' }} />
|
| 195 |
+
<div className="w-1.5 bg-white/90 rounded-full animate-voice-wave" style={{ animationDelay: '0.2s', height: '80%' }} />
|
| 196 |
+
<div className="w-1.5 bg-white/90 rounded-full animate-voice-wave" style={{ animationDelay: '0.4s', height: '50%' }} />
|
| 197 |
+
<div className="w-1.5 bg-white/90 rounded-full animate-voice-wave" style={{ animationDelay: '0.1s', height: '100%' }} />
|
| 198 |
+
</div>
|
| 199 |
+
<span className="text-[13px] font-black tracking-widest uppercase">Запись...</span>
|
| 200 |
+
</div>
|
| 201 |
+
<div className="flex items-center gap-2">
|
| 202 |
+
<button
|
| 203 |
+
type="button"
|
| 204 |
+
onClick={cancelRecording}
|
| 205 |
+
className="p-2.5 bg-white/10 text-white rounded-full hover:bg-white/20 transition-all active:scale-75"
|
| 206 |
+
>
|
| 207 |
+
<X className="w-5 h-5" />
|
| 208 |
+
</button>
|
| 209 |
+
<button
|
| 210 |
+
type="button"
|
| 211 |
+
onClick={(e) => { e.preventDefault(); stopRecording(true); }}
|
| 212 |
+
className="p-2.5 bg-white text-indigo-600 rounded-full shadow-lg transition-all active:scale-75"
|
| 213 |
+
>
|
| 214 |
+
<Send className="w-5 h-5 fill-current" />
|
| 215 |
+
</button>
|
| 216 |
+
</div>
|
| 217 |
+
</motion.div>
|
| 218 |
+
)}
|
| 219 |
+
</AnimatePresence>
|
| 220 |
|
| 221 |
<form
|
| 222 |
+
onSubmit={(e) => handleSendMessage(e)}
|
| 223 |
+
className="flex items-center gap-1.5 px-0.5"
|
| 224 |
>
|
| 225 |
<input
|
| 226 |
type="file"
|
|
|
|
| 230 |
accept="image/*,.pdf,.txt,.doc,.docx"
|
| 231 |
/>
|
| 232 |
|
| 233 |
+
<div className="flex items-center gap-0.5">
|
| 234 |
<button
|
| 235 |
type="button"
|
| 236 |
onClick={() => fileInputRef.current?.click()}
|
| 237 |
className={cn(
|
| 238 |
"p-2.5 rounded-full transition-all active:scale-90",
|
| 239 |
+
selectedFile ? "text-indigo-400 bg-indigo-500/10" : "text-slate-500 hover:text-white"
|
| 240 |
)}
|
| 241 |
>
|
| 242 |
<Paperclip className="w-5 h-5" />
|
|
|
|
| 250 |
onTouchEnd={(e) => { e.preventDefault(); stopRecording(); }}
|
| 251 |
className={cn(
|
| 252 |
"p-2.5 rounded-full transition-all active:scale-95",
|
| 253 |
+
isRecording ? "text-red-400 bg-red-500/10" : "text-slate-500 hover:text-white"
|
| 254 |
)}
|
| 255 |
disabled={!!selectedFile}
|
| 256 |
>
|
|
|
|
| 263 |
onChange={(e) => onChange(e.target.value)}
|
| 264 |
onKeyDown={handleKeyDown}
|
| 265 |
placeholder="Написать..."
|
| 266 |
+
className="flex-1 bg-white/10 border border-white/5 rounded-[22px] focus:ring-2 focus:ring-indigo-500/30 focus:border-indigo-500/30 focus:bg-white/15 resize-none max-h-32 py-2.5 px-4 text-[16px] leading-tight text-white placeholder:text-slate-500 overflow-y-auto transition-all shadow-inner"
|
| 267 |
rows={1}
|
| 268 |
style={{ minHeight: '44px' }}
|
| 269 |
disabled={disabled || isRecording}
|
|
|
|
| 273 |
type="submit"
|
| 274 |
disabled={(!value.trim() && !selectedFile && !pendingAudio) || isSending || disabled}
|
| 275 |
className={cn(
|
| 276 |
+
"p-2.5 rounded-full transition-all duration-300 flex items-center justify-center shadow-lg",
|
| 277 |
((value.trim() || selectedFile || pendingAudio) && !isSending && !disabled)
|
| 278 |
+
? "text-indigo-400 bg-indigo-500/20 active:scale-90 shadow-indigo-500/10"
|
| 279 |
+
: "text-slate-800 pointer-events-none"
|
| 280 |
)}
|
| 281 |
>
|
| 282 |
{isSending ? (
|
|
|
|
| 284 |
) : (
|
| 285 |
<Send className={cn(
|
| 286 |
"w-5 h-5",
|
| 287 |
+
((value.trim() || selectedFile || pendingAudio) && !isSending && !disabled) && "fill-indigo-400"
|
| 288 |
)} />
|
| 289 |
)}
|
| 290 |
</button>
|
| 291 |
</form>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
</div>
|
| 293 |
</div>
|
| 294 |
)
|
| 295 |
+
}
|
| 296 |
+
)
|
| 297 |
}
|
frontend/components/MobileNav.tsx
CHANGED
|
@@ -57,7 +57,7 @@ export function MobileHeader({ onOpen }: { onOpen?: () => void }) {
|
|
| 57 |
const isUnlimited = limitDialogs === null || limitDialogs === undefined
|
| 58 |
|
| 59 |
return (
|
| 60 |
-
<div className="flex flex-col fixed top-
|
| 61 |
<div className="flex items-center justify-between px-3 h-[52px] text-white w-full relative">
|
| 62 |
{/* Left: Logo + Brand Name */}
|
| 63 |
<Link href="/settings/brain" className="flex items-center gap-2.5 active:scale-95 transition-transform">
|
|
@@ -179,15 +179,12 @@ export function MobileSidebarWrapper({ children }: { children: React.ReactNode }
|
|
| 179 |
/>
|
| 180 |
|
| 181 |
{/* Sidebar Drawer */}
|
| 182 |
-
<motion.
|
| 183 |
-
initial={{
|
| 184 |
-
animate={{
|
| 185 |
-
exit={{
|
| 186 |
-
transition={{ type: 'spring', damping:
|
| 187 |
-
className="fixed
|
| 188 |
-
style={{
|
| 189 |
-
background: 'rgba(5, 5, 16, 0.85)',
|
| 190 |
-
}}
|
| 191 |
>
|
| 192 |
{/* Aurora Effect Background */}
|
| 193 |
<div className="absolute inset-0 overflow-hidden pointer-events-none z-0">
|
|
|
|
| 57 |
const isUnlimited = limitDialogs === null || limitDialogs === undefined
|
| 58 |
|
| 59 |
return (
|
| 60 |
+
<div className="flex flex-col fixed top-0 left-0 right-0 z-[60] bg-gradient-to-b from-black via-[#050510]/98 to-[#050510]/90 backdrop-blur-2xl border-b border-white/5 pt-[env(safe-area-inset-top,0px)] md:hidden shadow-2xl">
|
| 61 |
<div className="flex items-center justify-between px-3 h-[52px] text-white w-full relative">
|
| 62 |
{/* Left: Logo + Brand Name */}
|
| 63 |
<Link href="/settings/brain" className="flex items-center gap-2.5 active:scale-95 transition-transform">
|
|
|
|
| 179 |
/>
|
| 180 |
|
| 181 |
{/* Sidebar Drawer */}
|
| 182 |
+
<motion.nav
|
| 183 |
+
initial={{ y: '100%' }}
|
| 184 |
+
animate={{ y: 0 }}
|
| 185 |
+
exit={{ y: '100%' }}
|
| 186 |
+
transition={{ type: 'spring', damping: 20, stiffness: 200 }}
|
| 187 |
+
className="fixed bottom-0 left-0 right-0 z-[100] bg-gradient-to-t from-black via-[#050510]/98 to-[#050510]/90 backdrop-blur-2xl border-t border-white/5 pb-[env(safe-area-inset-bottom,0px)] md:hidden shadow-[0_-10px_40px_rgba(0,0,0,0.5)]"
|
|
|
|
|
|
|
|
|
|
| 188 |
>
|
| 189 |
{/* Aurora Effect Background */}
|
| 190 |
<div className="absolute inset-0 overflow-hidden pointer-events-none z-0">
|