MCPcopy
hub / github.com/dataelement/Clawith / NotificationBar

Function NotificationBar

frontend/src/App.tsx:58–209  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

56 `notification_bar_dismissed_persistent_${notificationBarRevisionKey(config)}`;
57
58function NotificationBar() {
59 const { i18n } = useTranslation();
60 const isChinese = i18n.language?.startsWith('zh');
61 const [config, setConfig] = useState<NotificationBarConfig | null>(null);
62 const [dismissed, setDismissed] = useState(false);
63 const [showDismissMenu, setShowDismissMenu] = useState(false);
64
65 const textRef = useRef<HTMLSpanElement>(null);
66 const containerRef = useRef<HTMLDivElement>(null);
67 const dismissMenuRef = useRef<HTMLDivElement>(null);
68 const [isMarquee, setIsMarquee] = useState(false);
69
70 useEffect(() => {
71 fetch('/api/enterprise/system-settings/notification_bar/public')
72 .then(r => r.ok ? r.json() : null)
73 .then(d => { if (d) setConfig(d); })
74 .catch(() => { });
75 }, []);
76
77 useEffect(() => {
78 const handleUpdate = (event: Event) => {
79 const next = (event as NotificationBarUpdateEvent).detail;
80 if (!next) return;
81 setConfig(next);
82 setShowDismissMenu(false);
83 if (next.text) {
84 const persistentKey = notificationBarPersistentDismissKey(next);
85 const sessionKey = notificationBarSessionDismissKey(next);
86 setDismissed(!!localStorage.getItem(persistentKey) || !!sessionStorage.getItem(sessionKey));
87 } else {
88 setDismissed(false);
89 }
90 if (!next.enabled || !next.text) {
91 document.body.classList.remove(notificationBarClass);
92 }
93 };
94
95 window.addEventListener('notification-bar-updated', handleUpdate);
96 return () => window.removeEventListener('notification-bar-updated', handleUpdate);
97 }, []);
98
99 // Check sessionStorage for dismissal (keyed by text so new messages re-show)
100 useEffect(() => {
101 if (config?.text) {
102 const persistentKey = notificationBarPersistentDismissKey(config);
103 const sessionKey = notificationBarSessionDismissKey(config);
104 setDismissed(!!localStorage.getItem(persistentKey) || !!sessionStorage.getItem(sessionKey));
105 }
106 }, [config?.text, config?.updated_at]);
107
108 useEffect(() => {
109 if (!showDismissMenu) return;
110 const handleClickOutside = (event: MouseEvent) => {
111 const target = event.target as Node;
112 if (dismissMenuRef.current?.contains(target)) return;
113 setShowDismissMenu(false);
114 };
115 document.addEventListener('mousedown', handleClickOutside);

Callers

nothing calls this directly

Calls 4

jsonMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected