import React, { useEffect, useMemo, useRef, useState } from 'react'; import { ipcChannels } from '../../shared/ipc/contracts'; import { buildHelpLinkCatalog, splitHelpTextWithLinks } from '../editor/help/helpLinkify'; import { HELP_SECTION_IDS, helpSectionBodyKey, helpSectionTitleKey, parseHelpSectionId, type HelpSectionId, } from '../editor/help/helpSections'; import { useEditorI18n } from '../editor/i18n/EditorI18nContext'; import { getDndApi } from '../shared/dndApi'; import styles from './InstructionsApp.module.css'; function InstructionsPanel({ initialSection }: { initialSection: HelpSectionId }) { const { t } = useEditorI18n(); const [activeId, setActiveId] = useState(initialSection); const contentRef = useRef(null); const navRef = useRef(null); useEffect(() => { setActiveId(initialSection); }, [initialSection]); useEffect(() => { contentRef.current?.scrollTo({ top: 0 }); const activeNav = navRef.current?.querySelector('[aria-current="true"]'); activeNav?.scrollIntoView({ block: 'nearest' }); }, [activeId]); const linkCatalog = useMemo( () => buildHelpLinkCatalog((id) => t(helpSectionTitleKey(id))), [t], ); const body = t(helpSectionBodyKey(activeId)); const paragraphs = body.split('\n\n').filter((p) => p.trim() !== ''); return (
{t(helpSectionTitleKey(activeId))}
{paragraphs.map((p, i) => (

{splitHelpTextWithLinks(p, linkCatalog).map((part, j) => part.type === 'text' ? ( {part.value} ) : ( ), )}

))}
); } export function InstructionsApp() { const [section, setSection] = useState('overview'); useEffect(() => { const api = getDndApi(); void api.invoke(ipcChannels.windows.getInstructionsSection, {}).then(({ section: next }) => { setSection(parseHelpSectionId(next)); }); return api.on(ipcChannels.windows.instructionsSection, ({ section: next }) => { setSection(parseHelpSectionId(next)); }); }, []); useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') window.close(); }; window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); }, []); return ; }