Spaces:
Running
Running
axeronis commited on
Commit ·
8e132dd
1
Parent(s): d4172a5
fix(ux): rebuild mobile scrolling, toggle shape, and image viewer logic
Browse files
frontend/components/ChatWindow.tsx
CHANGED
|
@@ -17,6 +17,7 @@ import { MessageBubble } from './ChatWindow/MessageBubble'
|
|
| 17 |
import { MessageInput } from './ChatWindow/MessageInput'
|
| 18 |
import { TypingIndicator } from './ChatWindow/TypingIndicator'
|
| 19 |
import { ConfirmModal } from '@/components/ui/ConfirmModal'
|
|
|
|
| 20 |
|
| 21 |
// ============================================================================
|
| 22 |
// Types
|
|
@@ -104,6 +105,11 @@ export function ChatWindow({
|
|
| 104 |
const [isBookingModalOpen, setIsBookingModalOpen] = useState(false)
|
| 105 |
const [isTraining, setIsTraining] = useState(false)
|
| 106 |
const [isTrainConfirmOpen, setIsTrainConfirmOpen] = useState(false)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
const toast = useToast()
|
| 108 |
|
| 109 |
const messagesEndRef = useRef<HTMLDivElement>(null)
|
|
@@ -451,6 +457,7 @@ export function ChatWindow({
|
|
| 451 |
showDate={showDate}
|
| 452 |
dateLabel={getDateLabel(msg.created_at)}
|
| 453 |
onDelete={handleDeleteMessage}
|
|
|
|
| 454 |
/>
|
| 455 |
)
|
| 456 |
})}
|
|
|
|
| 17 |
import { MessageInput } from './ChatWindow/MessageInput'
|
| 18 |
import { TypingIndicator } from './ChatWindow/TypingIndicator'
|
| 19 |
import { ConfirmModal } from '@/components/ui/ConfirmModal'
|
| 20 |
+
import { ImageViewer } from '@/components/ui/ImageViewer'
|
| 21 |
|
| 22 |
// ============================================================================
|
| 23 |
// Types
|
|
|
|
| 105 |
const [isBookingModalOpen, setIsBookingModalOpen] = useState(false)
|
| 106 |
const [isTraining, setIsTraining] = useState(false)
|
| 107 |
const [isTrainConfirmOpen, setIsTrainConfirmOpen] = useState(false)
|
| 108 |
+
const [viewerData, setViewerData] = useState<{ src: string; alt: string; isOpen: boolean }>({
|
| 109 |
+
src: '',
|
| 110 |
+
alt: '',
|
| 111 |
+
isOpen: false
|
| 112 |
+
})
|
| 113 |
const toast = useToast()
|
| 114 |
|
| 115 |
const messagesEndRef = useRef<HTMLDivElement>(null)
|
|
|
|
| 457 |
showDate={showDate}
|
| 458 |
dateLabel={getDateLabel(msg.created_at)}
|
| 459 |
onDelete={handleDeleteMessage}
|
| 460 |
+
onImageClick={(src, alt) => setViewerData({ src, alt, isOpen: true })}
|
| 461 |
/>
|
| 462 |
)
|
| 463 |
})}
|
frontend/components/ChatWindow/ChatHeader.tsx
CHANGED
|
@@ -32,6 +32,8 @@ export function ChatHeader({
|
|
| 32 |
onOpenBookingModal,
|
| 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]/60 backdrop-blur-xl border-b border-white/5">
|
| 37 |
{/* Aurora Background Atmosphere - Synced */}
|
|
@@ -100,27 +102,36 @@ export function ChatHeader({
|
|
| 100 |
)}
|
| 101 |
title={isAIActive ? 'AI Активен' : 'AI Отключен'}
|
| 102 |
>
|
| 103 |
-
{/* AI Toggle Switch - FIXED UI Phase
|
| 104 |
-
<div className="flex items-center gap-2">
|
| 105 |
<button
|
| 106 |
-
onClick={
|
|
|
|
|
|
|
|
|
|
| 107 |
disabled={isTogglingAI}
|
| 108 |
className={cn(
|
| 109 |
-
"relative
|
| 110 |
isAIActive
|
| 111 |
? "bg-indigo-600 border-indigo-500 shadow-[0_0_15px_rgba(99,102,241,0.3)]"
|
| 112 |
-
: "bg-
|
| 113 |
isTogglingAI && "opacity-80"
|
| 114 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
title={isAIActive ? 'AI Активен' : 'AI Отключен'}
|
| 116 |
>
|
| 117 |
{/* Thumb */}
|
| 118 |
<motion.div
|
| 119 |
animate={{
|
| 120 |
-
x: isAIActive ?
|
| 121 |
scale: isTogglingAI ? 0.85 : 1,
|
| 122 |
}}
|
| 123 |
-
transition={{ type: "spring", stiffness: 500, damping:
|
| 124 |
className="absolute top-[3px] w-[20px] h-[20px] rounded-full bg-white shadow-md flex items-center justify-center z-10"
|
| 125 |
>
|
| 126 |
{isTogglingAI && (
|
|
|
|
| 32 |
onOpenBookingModal,
|
| 33 |
onTrainAI,
|
| 34 |
}: ChatHeaderProps) {
|
| 35 |
+
if (!mounted) return null
|
| 36 |
+
|
| 37 |
return (
|
| 38 |
<div className="h-[52px] md:h-16 shrink-0 flex items-center justify-between px-3 md:px-6 relative z-[50] bg-[#050510]/60 backdrop-blur-xl border-b border-white/5">
|
| 39 |
{/* Aurora Background Atmosphere - Synced */}
|
|
|
|
| 102 |
)}
|
| 103 |
title={isAIActive ? 'AI Активен' : 'AI Отключен'}
|
| 104 |
>
|
| 105 |
+
{/* AI Toggle Switch - FIXED UI Phase 5 (Forced Pill) */}
|
| 106 |
+
<div className="flex items-center gap-2 flex-shrink-0">
|
| 107 |
<button
|
| 108 |
+
onClick={(e) => {
|
| 109 |
+
e.stopPropagation();
|
| 110 |
+
onToggleAI();
|
| 111 |
+
}}
|
| 112 |
disabled={isTogglingAI}
|
| 113 |
className={cn(
|
| 114 |
+
"relative flex-shrink-0 transition-all duration-300 border",
|
| 115 |
isAIActive
|
| 116 |
? "bg-indigo-600 border-indigo-500 shadow-[0_0_15px_rgba(99,102,241,0.3)]"
|
| 117 |
+
: "bg-white/10 border-white/10 hover:bg-white/20",
|
| 118 |
isTogglingAI && "opacity-80"
|
| 119 |
)}
|
| 120 |
+
style={{
|
| 121 |
+
width: '56px',
|
| 122 |
+
minWidth: '56px',
|
| 123 |
+
height: '28px',
|
| 124 |
+
borderRadius: '999px',
|
| 125 |
+
}}
|
| 126 |
title={isAIActive ? 'AI Активен' : 'AI Отключен'}
|
| 127 |
>
|
| 128 |
{/* Thumb */}
|
| 129 |
<motion.div
|
| 130 |
animate={{
|
| 131 |
+
x: isAIActive ? 30 : 4,
|
| 132 |
scale: isTogglingAI ? 0.85 : 1,
|
| 133 |
}}
|
| 134 |
+
transition={{ type: "spring", stiffness: 500, damping: 30 }}
|
| 135 |
className="absolute top-[3px] w-[20px] h-[20px] rounded-full bg-white shadow-md flex items-center justify-center z-10"
|
| 136 |
>
|
| 137 |
{isTogglingAI && (
|
frontend/components/ChatWindow/MessageBubble.tsx
CHANGED
|
@@ -15,6 +15,7 @@ interface MessageBubbleProps {
|
|
| 15 |
showDate: boolean
|
| 16 |
dateLabel: string
|
| 17 |
onDelete?: (messageId: string) => void
|
|
|
|
| 18 |
}
|
| 19 |
|
| 20 |
// ImageModal removed in favor of global ImageViewer
|
|
@@ -22,9 +23,8 @@ interface MessageBubbleProps {
|
|
| 22 |
/**
|
| 23 |
* Renders media content (audio, image, video, file) in message bubble
|
| 24 |
*/
|
| 25 |
-
function MediaContent({ message, isMe }: { message: Message; isMe: boolean }) {
|
| 26 |
const [isPlaying, setIsPlaying] = useState(false)
|
| 27 |
-
const [isImageModalOpen, setIsImageModalOpen] = useState(false)
|
| 28 |
const audioRef = useRef<HTMLAudioElement>(null)
|
| 29 |
|
| 30 |
if (!message.media_url) return null
|
|
@@ -99,22 +99,14 @@ function MediaContent({ message, isMe }: { message: Message; isMe: boolean }) {
|
|
| 99 |
// Image
|
| 100 |
if (mediaType.includes('image')) {
|
| 101 |
return (
|
| 102 |
-
<>
|
| 103 |
-
<
|
| 104 |
-
|
| 105 |
-
src={message.media_url}
|
| 106 |
-
alt={message.media_name || 'Image'}
|
| 107 |
-
className="rounded-xl max-w-full max-h-64 object-cover cursor-pointer hover:opacity-90 transition-opacity"
|
| 108 |
-
onClick={() => setIsImageModalOpen(true)}
|
| 109 |
-
/>
|
| 110 |
-
</div>
|
| 111 |
-
<ImageViewer
|
| 112 |
-
src={message.media_url!}
|
| 113 |
alt={message.media_name || 'Image'}
|
| 114 |
-
|
| 115 |
-
|
| 116 |
/>
|
| 117 |
-
</>
|
| 118 |
)
|
| 119 |
}
|
| 120 |
|
|
|
|
| 15 |
showDate: boolean
|
| 16 |
dateLabel: string
|
| 17 |
onDelete?: (messageId: string) => void
|
| 18 |
+
onImageClick?: (src: string, alt: string) => void
|
| 19 |
}
|
| 20 |
|
| 21 |
// ImageModal removed in favor of global ImageViewer
|
|
|
|
| 23 |
/**
|
| 24 |
* Renders media content (audio, image, video, file) in message bubble
|
| 25 |
*/
|
| 26 |
+
function MediaContent({ message, isMe, onImageClick }: { message: Message; isMe: boolean; onImageClick?: (src: string, alt: string) => void }) {
|
| 27 |
const [isPlaying, setIsPlaying] = useState(false)
|
|
|
|
| 28 |
const audioRef = useRef<HTMLAudioElement>(null)
|
| 29 |
|
| 30 |
if (!message.media_url) return null
|
|
|
|
| 99 |
// Image
|
| 100 |
if (mediaType.includes('image')) {
|
| 101 |
return (
|
| 102 |
+
<div className="mt-2">
|
| 103 |
+
<img
|
| 104 |
+
src={message.media_url}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
alt={message.media_name || 'Image'}
|
| 106 |
+
className="rounded-xl max-w-full max-h-64 object-cover cursor-pointer hover:opacity-90 transition-opacity"
|
| 107 |
+
onClick={() => onImageClick?.(message.media_url!, message.media_name || 'Image')}
|
| 108 |
/>
|
| 109 |
+
</div>
|
| 110 |
)
|
| 111 |
}
|
| 112 |
|
frontend/components/layout/LayoutClient.tsx
CHANGED
|
@@ -83,8 +83,8 @@ export function LayoutClient({ children }: { children: React.ReactNode }) {
|
|
| 83 |
<main
|
| 84 |
className={cn(
|
| 85 |
"flex-1 w-full md:pt-0 md:pb-0 overflow-x-hidden",
|
| 86 |
-
//
|
| 87 |
-
"overflow-y-auto min-h-0"
|
| 88 |
)}
|
| 89 |
style={{
|
| 90 |
// paddingTop: pathname?.startsWith('/chats') ? '0px' : 'var(--header-height-mobile)',
|
|
|
|
| 83 |
<main
|
| 84 |
className={cn(
|
| 85 |
"flex-1 w-full md:pt-0 md:pb-0 overflow-x-hidden",
|
| 86 |
+
// Disable global scroll on mobile chats to fix "stuck" state
|
| 87 |
+
pathname?.startsWith('/chats') ? "overflow-y-hidden" : "overflow-y-auto min-h-0"
|
| 88 |
)}
|
| 89 |
style={{
|
| 90 |
// paddingTop: pathname?.startsWith('/chats') ? '0px' : 'var(--header-height-mobile)',
|
frontend/components/ui/ImageViewer.tsx
CHANGED
|
@@ -15,11 +15,16 @@ interface ImageViewerProps {
|
|
| 15 |
}
|
| 16 |
|
| 17 |
export function ImageViewer({ src, alt, isOpen, onClose }: ImageViewerProps) {
|
|
|
|
| 18 |
const [scale, setScale] = useState(1)
|
| 19 |
const [position, setPosition] = useState({ x: 0, y: 0 })
|
| 20 |
const [isDragging, setIsDragging] = useState(false)
|
| 21 |
const containerRef = useRef<HTMLDivElement>(null)
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
// Reset zoom on close
|
| 24 |
useEffect(() => {
|
| 25 |
if (!isOpen) {
|
|
@@ -50,6 +55,8 @@ export function ImageViewer({ src, alt, isOpen, onClose }: ImageViewerProps) {
|
|
| 50 |
}
|
| 51 |
|
| 52 |
|
|
|
|
|
|
|
| 53 |
return (
|
| 54 |
<AnimatePresence>
|
| 55 |
{isOpen && createPortal(
|
|
|
|
| 15 |
}
|
| 16 |
|
| 17 |
export function ImageViewer({ src, alt, isOpen, onClose }: ImageViewerProps) {
|
| 18 |
+
const [mounted, setMounted] = useState(false)
|
| 19 |
const [scale, setScale] = useState(1)
|
| 20 |
const [position, setPosition] = useState({ x: 0, y: 0 })
|
| 21 |
const [isDragging, setIsDragging] = useState(false)
|
| 22 |
const containerRef = useRef<HTMLDivElement>(null)
|
| 23 |
|
| 24 |
+
useEffect(() => {
|
| 25 |
+
setMounted(true)
|
| 26 |
+
}, [])
|
| 27 |
+
|
| 28 |
// Reset zoom on close
|
| 29 |
useEffect(() => {
|
| 30 |
if (!isOpen) {
|
|
|
|
| 55 |
}
|
| 56 |
|
| 57 |
|
| 58 |
+
if (!mounted) return null
|
| 59 |
+
|
| 60 |
return (
|
| 61 |
<AnimatePresence>
|
| 62 |
{isOpen && createPortal(
|