mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Add hover close button to FloatingChatButton and hide on settings pages
- Added "x" button that appears when hovering over the chat button - Clicking "x" temporarily hides the button until page navigation or refresh - Button no longer appears on /settings/* pages - Reset hidden state when navigating to a different page
This commit is contained in:
1 parent
e9a6177c5b
commit
1b287b90aa
1 file changed
+65
-18
@@ -1,4 +1,6 @@
|
||||
import { MessageCircle } from 'lucide-react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { MessageCircle, X } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useGlobalChat } from '@/hooks/useGlobalChat';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
@@ -7,30 +9,75 @@ import { cn } from '@/lib/utils';
|
||||
export function FloatingChatButton() {
|
||||
const { isOpen, setIsOpen, hasUnread } = useGlobalChat();
|
||||
const { config } = useAppContext();
|
||||
const location = useLocation();
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
const [isHiddenTemporarily, setIsHiddenTemporarily] = useState(false);
|
||||
|
||||
// Reset hidden state when navigating to a different page
|
||||
useEffect(() => {
|
||||
setIsHiddenTemporarily(false);
|
||||
}, [location.pathname]);
|
||||
|
||||
// Don't render if disabled in settings
|
||||
if (config.globalChatEnabled === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Don't render on settings pages
|
||||
if (location.pathname.startsWith('/settings')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Don't render if temporarily hidden
|
||||
if (isHiddenTemporarily) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const handleClose = (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
setIsHiddenTemporarily(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<Button
|
||||
onClick={() => setIsOpen(!isOpen)}
|
||||
size="lg"
|
||||
className={cn(
|
||||
'fixed bottom-6 right-6 z-40 h-14 w-14 rounded-full shadow-lg',
|
||||
'bg-primary hover:bg-primary/90 text-primary-foreground',
|
||||
'transition-all duration-200 hover:scale-105',
|
||||
'flex items-center justify-center p-0',
|
||||
isOpen && 'ring-2 ring-ring ring-offset-2'
|
||||
)}
|
||||
aria-label={isOpen ? 'Close chat' : 'Open chat'}
|
||||
<div
|
||||
className="fixed bottom-6 right-6 z-40"
|
||||
onMouseEnter={() => setIsHovered(true)}
|
||||
onMouseLeave={() => setIsHovered(false)}
|
||||
>
|
||||
<MessageCircle className="h-6 w-6" />
|
||||
{/* Unread indicator - small dot when there are unread messages */}
|
||||
{!isOpen && hasUnread && (
|
||||
<span className="absolute top-0 right-0 h-3 w-3 rounded-full bg-destructive ring-2 ring-background" />
|
||||
)}
|
||||
</Button>
|
||||
{/* Close button - appears on hover */}
|
||||
<Button
|
||||
onClick={handleClose}
|
||||
size="icon"
|
||||
variant="secondary"
|
||||
className={cn(
|
||||
'absolute -top-2 -right-2 h-6 w-6 rounded-full shadow-md border',
|
||||
'transition-all duration-200',
|
||||
isHovered ? 'opacity-100 scale-100' : 'opacity-0 scale-75 pointer-events-none'
|
||||
)}
|
||||
aria-label="Hide chat button"
|
||||
>
|
||||
<X className="h-3 w-3" />
|
||||
</Button>
|
||||
|
||||
{/* Main chat button */}
|
||||
<Button
|
||||
onClick={() => setIsOpen(!isOpen)}
|
||||
size="lg"
|
||||
className={cn(
|
||||
'h-14 w-14 rounded-full shadow-lg',
|
||||
'bg-primary hover:bg-primary/90 text-primary-foreground',
|
||||
'transition-all duration-200 hover:scale-105',
|
||||
'flex items-center justify-center p-0',
|
||||
isOpen && 'ring-2 ring-ring ring-offset-2'
|
||||
)}
|
||||
aria-label={isOpen ? 'Close chat' : 'Open chat'}
|
||||
>
|
||||
<MessageCircle className="h-6 w-6" />
|
||||
{/* Unread indicator - small dot when there are unread messages */}
|
||||
{!isOpen && hasUnread && (
|
||||
<span className="absolute top-0 right-0 h-3 w-3 rounded-full bg-destructive ring-2 ring-background" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user