diff --git a/components/Code.tsx b/components/Code.tsx index 7460fa4e8..a4051ca46 100644 --- a/components/Code.tsx +++ b/components/Code.tsx @@ -1,9 +1,8 @@ -import React, { useContext } from 'react'; +import React, { useContext, ReactNode } from 'react'; import classnames from 'classnames'; import { BlockContext, BlockContextValue } from '~/context'; -export default function Code({ children }: { children: any }) { - // eslint-disable-next-line react-hooks/rules-of-hooks +export default function Code({ children }: { children: ReactNode }) { const blockContext = useContext(BlockContext); return ( { +type Frontmatter = { + Specification: string; + Published: string; + authors: string[]; + Metaschema: string; +}; + +const DocTable = ({ frontmatter }: { frontmatter: Frontmatter }) => { return ( <>
@@ -30,21 +37,21 @@ const DocTable = ({ frontmatter }: any) => { {frontmatter.Published} - + Authors - {frontmatter.authors.map((author: string, index: number) => { - return
{author}
; - })} + {frontmatter.authors.map((author, index) => ( +
{author}
+ ))} Metaschema - + data.default === true); + const defaultSchemaData = data.find((schema) => schema.default === true); + + if (!defaultSchemaData) { + throw new Error('Default schema not found'); + } const schemaResp = await fetch(defaultSchemaData.file); const schemaData = await schemaResp.json(); const defaultInstanceData = defaultSchemaData.instances.find( - (instance: any) => instance.default === true, + (instance) => instance.default === true, ); + if (!defaultInstanceData) { + throw new Error('Default instance not found'); + } + const instanceResp = await fetch(defaultInstanceData.file); const instanceData = await instanceResp.json(); @@ -29,17 +64,6 @@ async function fetchData() { }; } -interface SchemaOption { - file: string; - instances: InstanceOption[]; -} - -interface InstanceOption { - file: string; - details: string; - valid: string; -} - const GettingStarted = () => { useEffect(() => { fetchData() @@ -64,8 +88,10 @@ const GettingStarted = () => { const [options, setOptions] = useState([]); const [instances, setInstances] = useState([]); const [details, setDetails] = useState(['', '']); - const [fetchedSchema, setFetchedSchema] = useState(); - const [fetchedInstance, setFetchedInstance] = useState(); + const [fetchedSchema, setFetchedSchema] = useState(null); + const [fetchedInstance, setFetchedInstance] = useState( + null, + ); const handleSchemaChange = async ( e: React.ChangeEvent, @@ -86,7 +112,7 @@ const GettingStarted = () => { setFetchedInstance(instData); } else { setInstances([]); - setFetchedSchema(null!); + setFetchedSchema(null); } }; @@ -104,7 +130,7 @@ const GettingStarted = () => { setFetchedInstance(instanceData); setDetails([selectedInstance.details, selectedInstance.valid]); } else { - setFetchedInstance(undefined); + setFetchedInstance(null); } }; @@ -125,6 +151,7 @@ const GettingStarted = () => { return ( <>
+ {/* Schema Select and Display */}

JSON Schema

@@ -138,7 +165,7 @@ const GettingStarted = () => { id='Examples' onChange={handleSchemaChange} > - {options.map((option: any, id: number) => ( + {options.map((option, id) => ( @@ -180,6 +207,7 @@ const GettingStarted = () => {
+ {/* Instance Select and Display */}

JSON Instance

@@ -193,7 +221,7 @@ const GettingStarted = () => { id='Examples' onChange={handleInstanceChange} > - {instances.map((instance: any, id: number) => ( + {instances.map((instance, id) => ( @@ -244,6 +272,7 @@ const GettingStarted = () => {
+ {/* Download Button */}