Add spyglass context and file watcher

This commit is contained in:
Misode
2024-10-16 15:46:17 +02:00
parent 77d6323219
commit 7ed34a61e7
10 changed files with 136 additions and 54 deletions

View File

@@ -1,10 +1,10 @@
import type { ComponentChildren } from 'preact'
import { getCurrentUrl } from 'preact-router'
import { useEffect, useMemo, useState } from 'preact/hooks'
import { Store } from '../Store.js'
import { getGenerator } from '../Utils.js'
import { useSpyglass } from '../contexts/Spyglass.jsx'
import { useVersion } from '../contexts/Version.jsx'
import { latestVersion } from '../services/DataFetcher.js'
import { getGenerator } from '../Utils.js'
import { Octicon } from './index.js'
type ErrorPanelProps = {
@@ -17,11 +17,12 @@ type ErrorPanelProps = {
}
export function ErrorPanel({ error, prefix, reportable, onDismiss, body: body_, children }: ErrorPanelProps) {
const { version } = useVersion()
const { spyglass } = useSpyglass()
const [stackVisible, setStackVisible] = useState(false)
const [stack, setStack] = useState<string | undefined>(undefined)
const gen = getGenerator(getCurrentUrl())
const source = gen ? Store.getBackup(gen.id) : undefined
const source = gen ? spyglass?.getFile(spyglass.getUnsavedFileUri(gen)).doc?.getText() : undefined
const name = (prefix ?? '') + (error instanceof Error ? error.message : error)
useEffect(() => {