From 7fb78eeb2ade9a0327f4c7878d2bed6151bc1998 Mon Sep 17 00:00:00 2001 From: DCCONSTRUCTIONS Date: Sat, 5 Dec 2026 14:52:01 +0300 Subject: [PATCH] Filter Mission Core events with the shared header switch and acknowledge on close --- .../notifications/NotificationHost.tsx | 13 +++++++++---- .../notifications/useNotificationHistory.ts | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/apps/control-station/src/components/notifications/NotificationHost.tsx b/apps/control-station/src/components/notifications/NotificationHost.tsx index db63a5b3..698bf348 100644 --- a/apps/control-station/src/components/notifications/NotificationHost.tsx +++ b/apps/control-station/src/components/notifications/NotificationHost.tsx @@ -1,5 +1,5 @@ import {useEffect, useRef, useState, type ReactNode} from 'react'; -import {ApplicationSidePanel, Button, Description, Icon, IconButton, ResourceList, ResourceRow, StatusBadge, ToastStack} from '@nodedc/ui-react'; +import {ApplicationSidePanel, Button, Description, Icon, IconButton, ResourceList, ResourceRow, StatusBadge, Switch, Tooltip, ToastStack} from '@nodedc/ui-react'; import {NotificationContext, useNotificationHistory, useNotifications} from '../../core/notifications/useNotificationHistory'; import type {NotificationTone} from '../../core/notifications/history'; import {EventSettings} from './EventSettings'; @@ -27,15 +27,20 @@ export function EventPanel() { if (!state.open) return; gear.current?.focus({preventScroll: true}); }, [state.open]); - return { if (event.key === 'Escape' && !settings) { event.stopPropagation(); close(); } }} - headerActions={ setSettings(true)}>}> + headerActions={<> setSettings(true)}> + + + + }> {state.error && {state.error}} {!state.items.length && {state.loading ? 'Получаем события…' : 'Событий пока нет.'}} - {state.items.map(item =>
  • + {state.onlyNew && state.items.length>0 && state.items.every(i=>i.read) && Новых событий нет.} + {state.items.filter(item=>!state.onlyNew || !item.read).map(item =>
  • {live=false;stream?.close();clearTimeout(retry);}; },[]); - const maximum=items[0]?.sequence??0; + const [onlyNew,setOnlyNew]=useState(false); + // Capture the journal boundary while visible. New arrivals after close + // must not be acknowledged together with the preceding page. + const shown=useRef(0); + const [maximum,setMaximum]=useState(0); + const latest=items[0]?.sequence??0; useEffect(()=>{ - if(!open||!unread||maximum<=readThrough.current)return; + if(open)shown.current=latest; + else setMaximum(shown.current); + },[open,latest]); + useEffect(()=>{ + if(maximum<=readThrough.current)return; let active=true,timer:ReturnType|undefined; async function markRead(){ try{ @@ -44,13 +53,13 @@ export function useNotificationHistory(){ } void markRead(); return()=>{active=false;clearTimeout(timer);}; - },[open,maximum,unread]); + },[maximum]); const loadMore=async()=>{ if(loading||!items.length)return;setLoading(true); try{const page=await notificationRequest('?before='+items[items.length-1].sequence);setItems(old=>mergeNotifications(old,page.items));setMore(page.items.length===100);setError('');} catch(e){setError(e instanceof Error?e.message:'История недоступна.');}finally{setLoading(false);} }; - return {items,unread,open,setOpen,error,loading,more,loadMore,toasts,dismiss:(id:string)=>setToasts(old=>old.filter(item=>item.id!==id))}; + return {items,unread,open,setOpen,onlyNew,setOnlyNew,error,loading,more,loadMore,toasts,dismiss:(id:string)=>setToasts(old=>old.filter(item=>item.id!==id))}; } export const NotificationContext=createContext|null>(null); export function useNotifications(){const context=useContext(NotificationContext);if(!context)throw new Error('Notification host missing');return context;}