/** * "What's New" modal — shows the next pending product-news post when the * user enters the editor. At most one per day, each post only ever once; * the queue/seen logic lives in lib/newsSource.ts (OSS: localStorage over * the local /api/news/feed proxy; pro overlay: server-backed per-user). * * The fetch is delayed a few seconds so it never competes with editor * startup, and every failure path resolves to "no modal". */ import { useEffect, useState } from 'react'; import { createPortal } from 'react-dom'; import { getNextNews, type NewsPost } from '../../lib/newsSource'; import { NewsMarkdown } from './NewsMarkdown'; import './NewsModal.css'; const FETCH_DELAY_MS = 4000; export function NewsModal() { const [post, setPost] = useState(null); useEffect(() => { let cancelled = false; const timer = setTimeout(() => { void getNextNews().then((p) => { if (!cancelled && p) setPost(p); }); }, FETCH_DELAY_MS); return () => { cancelled = true; clearTimeout(timer); }; }, []); if (!post) return null; return createPortal(
setPost(null)}>
e.stopPropagation()} >
What's new

{post.title}

{post.body_md}
, document.body, ); }