Remove standalone /[locale]/chat page; enhance FloatingChat with fullscreen toggle via Launch icon; add global event to open chat (optionally fullscreen); wire home buttons/cards to open modal instead of routing.
This commit is contained in:
@@ -47,6 +47,7 @@ export default function FloatingChat() {
|
||||
const locale = useLocale()
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
const [isMinimized, setIsMinimized] = useState(false)
|
||||
const [isFullscreen, setIsFullscreen] = useState(false)
|
||||
const [messages, setMessages] = useState<ChatMessage[]>([
|
||||
{
|
||||
id: '1',
|
||||
@@ -69,6 +70,18 @@ export default function FloatingChat() {
|
||||
scrollToBottom()
|
||||
}, [messages])
|
||||
|
||||
// Allow external triggers to open the chat (optionally fullscreen)
|
||||
useEffect(() => {
|
||||
const handler = (e: Event) => {
|
||||
const detail = (e as CustomEvent).detail || {}
|
||||
setIsOpen(true)
|
||||
setIsMinimized(false)
|
||||
if (typeof detail.fullscreen === 'boolean') setIsFullscreen(detail.fullscreen)
|
||||
}
|
||||
window.addEventListener('floating-chat:open', handler as EventListener)
|
||||
return () => window.removeEventListener('floating-chat:open', handler as EventListener)
|
||||
}, [])
|
||||
|
||||
const handleSendMessage = async () => {
|
||||
if (!inputMessage.trim() || isLoading) return
|
||||
|
||||
@@ -151,9 +164,7 @@ export default function FloatingChat() {
|
||||
setIsMinimized(!isMinimized)
|
||||
}
|
||||
|
||||
const openFullChat = () => {
|
||||
window.open('/chat', '_blank')
|
||||
}
|
||||
const toggleFullscreen = () => setIsFullscreen(prev => !prev)
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -185,10 +196,12 @@ export default function FloatingChat() {
|
||||
position: 'fixed',
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
width: { xs: '100vw', sm: '50vw', md: '40vw' },
|
||||
top: isFullscreen ? 0 : 'auto',
|
||||
left: isFullscreen ? 0 : 'auto',
|
||||
width: isFullscreen ? '100vw' : { xs: '100vw', sm: '50vw', md: '40vw' },
|
||||
height: isMinimized ? 'auto' : '100vh',
|
||||
zIndex: 1200,
|
||||
borderRadius: { xs: 0, sm: '12px 0 0 0' },
|
||||
borderRadius: isFullscreen ? 0 : { xs: 0, sm: '12px 0 0 0' },
|
||||
overflow: 'hidden',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
@@ -229,7 +242,7 @@ export default function FloatingChat() {
|
||||
</IconButton>
|
||||
<IconButton
|
||||
size="small"
|
||||
onClick={openFullChat}
|
||||
onClick={toggleFullscreen}
|
||||
sx={{ color: 'white', mr: 0.5 }}
|
||||
>
|
||||
<Launch />
|
||||
@@ -354,7 +367,7 @@ export default function FloatingChat() {
|
||||
opacity: 0.7,
|
||||
}}
|
||||
>
|
||||
{message.timestamp.toLocaleTimeString('ro-RO', {
|
||||
{message.timestamp.toLocaleTimeString(locale === 'en' ? 'en-US' : 'ro-RO', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
})}
|
||||
@@ -428,4 +441,4 @@ export default function FloatingChat() {
|
||||
</Slide>
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user