fix(ws): не показывать replay-уведомления при подключении
Refs EventHub/EventHubFrontAdmin#9 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -67,6 +67,7 @@ export const useAdminWebSocket = () => {
|
||||
|
||||
shouldReconnectRef.current = true;
|
||||
let isMounted = true;
|
||||
const sessionStartSecondsRef = { current: 0 };
|
||||
|
||||
const connect = () => {
|
||||
if (!isMounted || !shouldReconnectRef.current) return;
|
||||
@@ -82,6 +83,7 @@ export const useAdminWebSocket = () => {
|
||||
|
||||
ws.onopen = () => {
|
||||
if (!isMounted || !shouldReconnectRef.current) return;
|
||||
sessionStartSecondsRef.current = Math.floor(Date.now() / 1000);
|
||||
wsLog('[WS] Connected');
|
||||
if (canAccessRoute('/reports', role)) {
|
||||
ws.send(JSON.stringify({ action: 'subscribe', channel: 'reports' }));
|
||||
@@ -115,9 +117,14 @@ export const useAdminWebSocket = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('admin-ws-message', { detail: msg })
|
||||
);
|
||||
const isLiveEvent =
|
||||
!msg.timestamp || msg.timestamp >= sessionStartSecondsRef.current;
|
||||
|
||||
if (isLiveEvent) {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('admin-ws-message', { detail: msg })
|
||||
);
|
||||
}
|
||||
|
||||
if (msg.type === 'report_created') {
|
||||
queryClient.invalidateQueries({ queryKey: ['reports'] });
|
||||
|
||||
Reference in New Issue
Block a user