feat: Added chat when MySQL is in use

This commit is contained in:
2026-06-21 02:30:01 +02:00
parent a9f2e515e1
commit 0e2ef317c3
10 changed files with 120 additions and 19 deletions
+15 -4
View File
@@ -630,6 +630,7 @@ export default function App() {
const [chatMsgs, setChatMsgs] = useState<ChatMsg[]>([]);
const [chatOnline, setChatOnline] = useState<ChatPresence[]>([]);
const [chatUnread, setChatUnread] = useState(0);
const [chatEpoch, setChatEpoch] = useState(0); // bumped on profile switch to reload the chat for the new logbook
const chatOpenRef = useRef(chatOpen); chatOpenRef.current = chatOpen;
const chatSeen = useRef<Set<number>>(new Set());
// Availability (only on a shared MySQL logbook; re-checked as profiles switch).
@@ -667,7 +668,7 @@ export default function App() {
lo();
const id = window.setInterval(lo, 15000);
return () => window.clearInterval(id);
}, [chatOpen]);
}, [chatOpen, chatEpoch]);
async function chatSend(t: string) {
try {
const m = (await SendChatMessage(t)) as any as ChatMsg;
@@ -1455,6 +1456,11 @@ export default function App() {
useEffect(() => {
const off = EventsOn('profile:changed', () => {
loadStation(); loadLists(); loadCATCfg(); reloadWk(); loadMainPanes();
// The chat is per shared logbook — clear the previous profile's messages
// and reload for the new logbook (or hide if it isn't a MySQL log).
setChatMsgs([]); chatSeen.current.clear(); setChatOnline([]); setChatUnread(0);
ChatAvailable().then((v: any) => setChatAvailable(!!v)).catch(() => setChatAvailable(false));
setChatEpoch((e) => e + 1);
});
return () => { off(); };
}, [loadStation, loadLists, loadCATCfg, reloadWk, loadMainPanes]);
@@ -3209,9 +3215,14 @@ export default function App() {
{!compact && (chatShown || wkEnabled || dvkEnabled || lookupResult?.image_url || (showRotor && (rotatorHeading.enabled || dxPath))) && (
<div className="flex-1 min-w-0 min-h-0 flex gap-2.5 items-stretch">
{chatShown && (
<div className="w-[280px] shrink-0 min-h-0">
<ChatPanel msgs={chatMsgs} online={chatOnline} myCall={station.callsign}
onSend={chatSend} onClose={() => setChatOpen(false)} />
// relative + absolute inner: the chat takes the row height (set by the
// entry strip) WITHOUT its message list growing the row, like the
// Stats panel. The list scrolls inside this fixed height.
<div className="w-[280px] shrink-0 min-h-0 relative">
<div className="absolute inset-0 flex flex-col min-h-0">
<ChatPanel msgs={chatMsgs} online={chatOnline} myCall={station.callsign}
onSend={chatSend} onClose={() => setChatOpen(false)} />
</div>
</div>
)}
{/* Rotor compass: azimuth dial + needles + click-to-turn. Shows when a