bb650ac2a0
Backend: - DB: reactions table, invites table, reply_to column on messages - gateway/events.go: added REACTION_ADD, REACTION_REMOVE events - internal/reaction/handlers.go: reaction CRUD with WebSocket broadcast - internal/invite/handlers.go: invite creation, info, join with code - gateway/hub.go: presence tracking with idle detection - gateway/client.go: idle timeout support Frontend - Social: - TypingIndicator: real-time 'user is typing...' display - ReactionBar: emoji reactions on messages with counts - EmojiPicker: searchable emoji grid for reactions - ReplyBar: quoted reply display above messages - MentionPopup: @mention autocomplete with user list Frontend - PWA: - manifest.json: PWA manifest with theme color and icons - sw.js: service worker with cache-first strategy and push support - stores/push.ts: push notification subscription management - InstallPrompt: 'Add to Home Screen' banner Frontend - Mobile: - MobileNav: bottom nav bar for mobile (servers/channels/chat/members) - MobileDrawer: slide-out drawer with server bar + channel list - index.html: PWA meta tags, safe area viewport Frontend - Polish: - ThemeToggle: dark/light mode switch with localStorage persistence - InviteModal: generate invite links with expiry and max uses - JoinServer: /invite/:code join flow - stores/typing.ts: typing indicator state management - stores/presence.ts: real-time presence tracking - tailwind.config.js: darkMode: 'class', light mode color tokens - styles/index.css: light mode CSS variable overrides
87 lines
2.6 KiB
TypeScript
87 lines
2.6 KiB
TypeScript
import { useState, useEffect, useRef } from 'react';
|
|
|
|
interface User {
|
|
id: string;
|
|
username: string;
|
|
display_name: string;
|
|
}
|
|
|
|
interface MentionPopupProps {
|
|
users: User[];
|
|
filter: string;
|
|
onSelect: (user: User) => void;
|
|
position: { top: number; left: number };
|
|
}
|
|
|
|
export function MentionPopup({ users, filter, onSelect, position }: MentionPopupProps) {
|
|
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
const listRef = useRef<HTMLDivElement>(null);
|
|
|
|
const filtered = users.filter(u =>
|
|
u.username.toLowerCase().includes(filter.toLowerCase()) ||
|
|
u.display_name?.toLowerCase().includes(filter.toLowerCase())
|
|
).slice(0, 8);
|
|
|
|
useEffect(() => {
|
|
setSelectedIndex(0);
|
|
}, [filter]);
|
|
|
|
useEffect(() => {
|
|
const handleKeyDown = (e: KeyboardEvent) => {
|
|
if (e.key === 'ArrowDown') {
|
|
e.preventDefault();
|
|
setSelectedIndex(prev => Math.min(prev + 1, filtered.length - 1));
|
|
} else if (e.key === 'ArrowUp') {
|
|
e.preventDefault();
|
|
setSelectedIndex(prev => Math.max(prev - 1, 0));
|
|
} else if (e.key === 'Enter' || e.key === 'Tab') {
|
|
e.preventDefault();
|
|
if (filtered[selectedIndex]) {
|
|
onSelect(filtered[selectedIndex]);
|
|
}
|
|
} else if (e.key === 'Escape') {
|
|
e.preventDefault();
|
|
onSelect(null as any);
|
|
}
|
|
};
|
|
|
|
window.addEventListener('keydown', handleKeyDown);
|
|
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
}, [filtered, selectedIndex, onSelect]);
|
|
|
|
if (filtered.length === 0) return null;
|
|
|
|
return (
|
|
<div
|
|
ref={listRef}
|
|
className="absolute bg-gb-bg border border-gb-bg-t shadow-lg z-50 min-w-[200px] max-h-[200px] overflow-y-auto"
|
|
style={{ bottom: '100%', left: position.left, marginBottom: 4 }}
|
|
>
|
|
<div className="px-2 py-1 text-xs text-gb-fg-f font-mono border-b border-gb-bg-t">
|
|
MEMBERS
|
|
</div>
|
|
{filtered.map((user, index) => (
|
|
<button
|
|
key={user.id}
|
|
onClick={() => onSelect(user)}
|
|
onMouseEnter={() => setSelectedIndex(index)}
|
|
className={`
|
|
w-full px-2 py-1 text-left text-xs font-mono flex items-center gap-2
|
|
transition-colors
|
|
${index === selectedIndex
|
|
? 'bg-gb-orange text-gb-bg'
|
|
: 'text-gb-fg hover:bg-gb-bg-s'
|
|
}
|
|
`}
|
|
>
|
|
<span className="text-gb-green">●</span>
|
|
<span>{user.display_name || user.username}</span>
|
|
{user.display_name && user.display_name !== user.username && (
|
|
<span className="text-gb-fg-f">({user.username})</span>
|
|
)}
|
|
</button>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|