MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / ExportNoteWindow

Function ExportNoteWindow

apps/web/src/export-window.tsx:109–251  ·  view source on GitHub ↗
({ notePath }: { notePath: string })

Source from the content-addressed store, hash-verified

107}
108
109function ExportNoteWindow({ notePath }: { notePath: string }): JSX.Element {
110 const [note, setNote] = useState<NoteContent | null>(null)
111 const [error, setError] = useState<string | null>(null)
112 const didTriggerPrint = useRef(false)
113
114 useEffect(() => {
115 applyExportPrefs(loadExportPrefs())
116
117 let cancelled = false
118
119 const load = async (): Promise<void> => {
120 try {
121 const [vault, notes, assetFiles, noteContent] = await Promise.all([
122 window.zen.getCurrentVault(),
123 window.zen.listNotes(),
124 window.zen.listAssets(),
125 window.zen.readNote(notePath)
126 ])
127 if (cancelled) return
128 if (!vault) {
129 throw new Error('No active vault was available for PDF export.')
130 }
131
132 useStore.setState({
133 vault: vault as VaultInfo,
134 notes: notes as NoteMeta[],
135 assetFiles: assetFiles as AssetMeta[],
136 selectedPath: noteContent.path,
137 activeNote: noteContent
138 })
139 document.title = `${noteContent.title}.pdf`
140 setNote(noteContent)
141 } catch (err) {
142 if (cancelled) return
143 setError(err instanceof Error ? err.message : String(err))
144 }
145 }
146
147 void load()
148
149 return () => {
150 cancelled = true
151 }
152 }, [notePath])
153
154 const triggerPrint = async (): Promise<void> => {
155 if (didTriggerPrint.current) return
156 didTriggerPrint.current = true
157 try {
158 if ('fonts' in document && document.fonts?.ready) {
159 await document.fonts.ready
160 }
161 } catch {
162 // Ignore font readiness failures and continue to print.
163 }
164 requestAnimationFrame(() => {
165 requestAnimationFrame(() => {
166 window.print()

Callers

nothing calls this directly

Calls 4

triggerPrintFunction · 0.85
applyExportPrefsFunction · 0.70
loadExportPrefsFunction · 0.70
loadFunction · 0.70

Tested by

no test coverage detected