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;
|
shouldReconnectRef.current = true;
|
||||||
let isMounted = true;
|
let isMounted = true;
|
||||||
|
const sessionStartSecondsRef = { current: 0 };
|
||||||
|
|
||||||
const connect = () => {
|
const connect = () => {
|
||||||
if (!isMounted || !shouldReconnectRef.current) return;
|
if (!isMounted || !shouldReconnectRef.current) return;
|
||||||
@@ -82,6 +83,7 @@ export const useAdminWebSocket = () => {
|
|||||||
|
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
if (!isMounted || !shouldReconnectRef.current) return;
|
if (!isMounted || !shouldReconnectRef.current) return;
|
||||||
|
sessionStartSecondsRef.current = Math.floor(Date.now() / 1000);
|
||||||
wsLog('[WS] Connected');
|
wsLog('[WS] Connected');
|
||||||
if (canAccessRoute('/reports', role)) {
|
if (canAccessRoute('/reports', role)) {
|
||||||
ws.send(JSON.stringify({ action: 'subscribe', channel: 'reports' }));
|
ws.send(JSON.stringify({ action: 'subscribe', channel: 'reports' }));
|
||||||
@@ -115,9 +117,14 @@ export const useAdminWebSocket = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isLiveEvent =
|
||||||
|
!msg.timestamp || msg.timestamp >= sessionStartSecondsRef.current;
|
||||||
|
|
||||||
|
if (isLiveEvent) {
|
||||||
window.dispatchEvent(
|
window.dispatchEvent(
|
||||||
new CustomEvent('admin-ws-message', { detail: msg })
|
new CustomEvent('admin-ws-message', { detail: msg })
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (msg.type === 'report_created') {
|
if (msg.type === 'report_created') {
|
||||||
queryClient.invalidateQueries({ queryKey: ['reports'] });
|
queryClient.invalidateQueries({ queryKey: ['reports'] });
|
||||||
|
|||||||
Reference in New Issue
Block a user