diff --git a/src/app/components/generator/FileView.tsx b/src/app/components/generator/FileView.tsx new file mode 100644 index 00000000..e5fe3fae --- /dev/null +++ b/src/app/components/generator/FileView.tsx @@ -0,0 +1,37 @@ +import type { DocAndNode } from '@spyglassmc/core' +import { JsonFileNode } from '@spyglassmc/json' +import { useErrorBoundary } from 'preact/hooks' +import { useDocAndNode, useSpyglass } from '../../contexts/Spyglass.jsx' +import { message } from '../../Utils.js' +import { ErrorPanel } from '../ErrorPanel.jsx' +import { JsonFileView } from './JsonFileView.jsx' + +type FileViewProps = { + docAndNode: DocAndNode | undefined, +} +export function FileView({ docAndNode: original }: FileViewProps) { + const { serviceLoading } = useSpyglass() + + const [error, errorRetry] = useErrorBoundary() + if (error) { + return + } + + const docAndNode = useDocAndNode(original) + if (!docAndNode || serviceLoading) { + return
+
+
+
+
+
+
+ } + + const fileNode = docAndNode?.node.children[0] + if (JsonFileNode.is(fileNode)) { + return + } + + return +} diff --git a/src/app/components/generator/Tree.tsx b/src/app/components/generator/JsonFileView.tsx similarity index 65% rename from src/app/components/generator/Tree.tsx rename to src/app/components/generator/JsonFileView.tsx index 2717ac79..19114bee 100644 --- a/src/app/components/generator/Tree.tsx +++ b/src/app/components/generator/JsonFileView.tsx @@ -2,35 +2,19 @@ import type { DocAndNode, Range } from '@spyglassmc/core' import { dissectUri } from '@spyglassmc/java-edition/lib/binder/index.js' import type { JsonNode } from '@spyglassmc/json' import { JsonFileNode } from '@spyglassmc/json' -import { useCallback, useErrorBoundary, useMemo } from 'preact/hooks' -import { useLocale } from '../../contexts/index.js' -import { useDocAndNode, useSpyglass } from '../../contexts/Spyglass.jsx' +import { useCallback, useMemo } from 'preact/hooks' +import { useSpyglass } from '../../contexts/Spyglass.jsx' import { getRootType, simplifyType } from './McdocHelpers.js' import type { McdocContext } from './McdocRenderer.jsx' import { McdocRoot } from './McdocRenderer.jsx' -type TreePanelProps = { +type JsonFileViewProps = { docAndNode: DocAndNode, - onError: (message: string) => unknown, + node: JsonNode, } -export function Tree({ docAndNode: original, onError }: TreePanelProps) { - const { lang } = useLocale() +export function JsonFileView({ docAndNode, node }: JsonFileViewProps) { const { service } = useSpyglass() - if (lang === 'none') return <> - - const docAndNode = useDocAndNode(original) - const fileChild = docAndNode.node.children[0] - if (!JsonFileNode.is(fileChild)) { - return <> - } - - const [error] = useErrorBoundary(e => { - onError(`Error rendering the tree: ${e.message}`) - console.error(e) - }) - if (error) return <> - const makeEdit = useCallback((edit: (range: Range) => JsonNode | undefined) => { if (!service) { return @@ -62,15 +46,15 @@ export function Tree({ docAndNode: original, onError }: TreePanelProps) { }, [docAndNode, service, makeEdit]) const resourceType = useMemo(() => { - if (original.doc.uri.endsWith('/pack.mcmeta')) { + if (docAndNode.doc.uri.endsWith('/pack.mcmeta')) { return 'pack_mcmeta' } if (ctx === undefined) { return undefined } - const res = dissectUri(original.doc.uri, ctx) + const res = dissectUri(docAndNode.doc.uri, ctx) return res?.category - }, [original, ctx]) + }, [docAndNode, ctx]) const mcdocType = useMemo(() => { if (!ctx || !resourceType) { @@ -81,8 +65,8 @@ export function Tree({ docAndNode: original, onError }: TreePanelProps) { return type }, [resourceType, ctx]) - return
- {(ctx && mcdocType) && } + return
+ {(ctx && mcdocType) && }
} diff --git a/src/app/components/generator/ProjectPanel.tsx b/src/app/components/generator/ProjectPanel.tsx index 3b76c59d..c893545a 100644 --- a/src/app/components/generator/ProjectPanel.tsx +++ b/src/app/components/generator/ProjectPanel.tsx @@ -144,9 +144,15 @@ export function ProjectPanel() { {project.name !== DRAFT_PROJECT.name && }
-
+
{entries === undefined - ? <> + ?
+
+
+
+
+
+
: entries.length === 0 ? {locale('project.no_files')} : path.split('/')} group={FolderEntry} leaf={FileEntry} />} diff --git a/src/app/components/generator/SchemaGenerator.tsx b/src/app/components/generator/SchemaGenerator.tsx index bc9abd41..fea47e1c 100644 --- a/src/app/components/generator/SchemaGenerator.tsx +++ b/src/app/components/generator/SchemaGenerator.tsx @@ -13,7 +13,7 @@ import { checkVersion, fetchDependencyMcdoc, fetchPreset, fetchRegistries, getSn import { DEPENDENCY_URI } from '../../services/Spyglass.js' import { Store } from '../../Store.js' import { cleanUrl, genPath } from '../../Utils.js' -import { Ad, Btn, BtnMenu, ErrorPanel, FileCreation, Footer, HasPreview, Octicon, PreviewPanel, ProjectPanel, SearchList, SourcePanel, TextInput, Tree, VersionSwitcher } from '../index.js' +import { Ad, Btn, BtnMenu, ErrorPanel, FileCreation, FileView, Footer, HasPreview, Octicon, PreviewPanel, ProjectPanel, SearchList, SourcePanel, TextInput, VersionSwitcher } from '../index.js' import { getRootDefault } from './McdocHelpers.js' export const SHARE_KEY = 'share' @@ -59,7 +59,7 @@ export function SchemaGenerator({ gen, allowedVersions }: Props) { const [sharedSnippetId, setSharedSnippetId] = useSearchParam(SHARE_KEY) const ignoreChange = useRef(false) - const { value: docAndNode } = useAsync(async () => { + const { value: docAndNode, loading: docLoading } = useAsync(async () => { let text: string | undefined = undefined if (currentPreset && sharedSnippetId) { setSharedSnippetId(undefined) @@ -386,7 +386,7 @@ export function SchemaGenerator({ gen, allowedVersions }: Props) {
{error && setError(null)} />} - {docAndNode && } +