diff --git a/packages/primer-app/src/App.tsx b/packages/primer-app/src/App.tsx index b67309d8..666285d7 100644 --- a/packages/primer-app/src/App.tsx +++ b/packages/primer-app/src/App.tsx @@ -1,20 +1,56 @@ -// TODO this is very much a placeholder -import { TreeReactFlow, tree1, tree4 } from "@hackworthltd/primer-components"; +import { TreeReactFlow, Error } from "@hackworthltd/primer-components"; import "@hackworthltd/primer-components/style.css"; import { useParams } from "react-router-dom"; +import { useGetApiProgram } from "./primer-api"; const App = (): JSX.Element => { const params = useParams(); + const session = params["sessionId"]; + + if (!session) { + return ( + + ); + } + // This hook is *technically* conditional. + // But if the condition above fails, then the app is broken anyway. + // eslint-disable-next-line react-hooks/rules-of-hooks + const queryRes = useGetApiProgram({ session }); + + if (!queryRes.isSuccess) { + return ( + + ); + } + const prog = queryRes.data; + + const editableModules = prog.modules.filter((m) => m.editable); + if (editableModules.length > 1) { + return ( + + ); + } + const module = editableModules[0]; + if (!module) { + return ; + } + const trees = module.defs.flatMap((def) => def.term || []); return (
- {"Session: " + params["sessionId"]}
); diff --git a/packages/primer-components/src/Error/Error.stories.tsx b/packages/primer-components/src/Error/Error.stories.tsx new file mode 100644 index 00000000..38b9411a --- /dev/null +++ b/packages/primer-components/src/Error/Error.stories.tsx @@ -0,0 +1,13 @@ +import { ComponentStory, ComponentMeta } from "@storybook/react"; +import { Error } from "./Error"; + +export default { + title: "Application/Component Library/Error", + component: Error, +} as ComponentMeta; + +const Template: ComponentStory = () => ( + +); + +export const Default = Template.bind({}); diff --git a/packages/primer-components/src/Error/Error.tsx b/packages/primer-components/src/Error/Error.tsx new file mode 100644 index 00000000..7ae27f31 --- /dev/null +++ b/packages/primer-components/src/Error/Error.tsx @@ -0,0 +1,9 @@ +import "@/index.css"; + +export type ErrorProps = { + string: string; +}; + +export const Error = (p: ErrorProps): JSX.Element => ( +

Error: {p.string}

+); diff --git a/packages/primer-components/src/Error/index.tsx b/packages/primer-components/src/Error/index.tsx new file mode 100644 index 00000000..f1e20a2f --- /dev/null +++ b/packages/primer-components/src/Error/index.tsx @@ -0,0 +1,3 @@ +import { Error } from "./Error"; + +export default Error; diff --git a/packages/primer-components/src/index.ts b/packages/primer-components/src/index.ts index d1096d70..3d7c4c03 100644 --- a/packages/primer-components/src/index.ts +++ b/packages/primer-components/src/index.ts @@ -2,6 +2,7 @@ export { default as ActionButton } from "@/ActionButton"; export { default as ActionButtonList } from "@/ActionButtonList"; export { default as Avatar } from "@/Avatar"; export { default as BinaryTreePlaceholder } from "@/BinaryTreePlaceholder"; +export { default as Error } from "@/Error"; export { default as FloatingToolbar } from "@/FloatingToolbar"; export { default as GroupedButtonList } from "@/GroupedButtonList"; export { default as NoMatch } from "@/NoMatch";