This repository was archived by the owner on Feb 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
Added an embed mode which works via the URL, not any data in our db #323
Open
mattpocock
wants to merge
10
commits into
dev
Choose a base branch
from
matt/added-an-embed-mode-which-works-via-the-url-not-any-data-in-our-db
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+232
−40
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fab734d
Added an embed mode which works via the URL, not any data in our db
mattpocock 8697c33
Completed work
mattpocock 3ec5dbc
Update src/pages/view-only.tsx
mattpocock 170610b
Update src/pages/view-only.tsx
mattpocock bddbdca
Update src/pages/view-only.tsx
mattpocock f8eab8e
Update src/pages/view-only.tsx
mattpocock 29e3bcb
Update src/withReadyRouter.tsx
mattpocock 38f1959
Empty commit for visualisation
mattpocock 850025f
Respond to feedback
mattpocock 317bb3e
Empty commit for visualisation
mattpocock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| import { createContext, useContext } from 'react'; | ||
| import { EmbedContext } from './types'; | ||
| import { createRequiredContext } from './utils'; | ||
|
|
||
| export const [EmbedProvider, useEmbed] = createRequiredContext< | ||
| EmbedContext | undefined | ||
| >('Embed'); | ||
| const EmbedReactContext = createContext(null as EmbedContext); | ||
|
|
||
| export const EmbedProvider = EmbedReactContext.Provider; | ||
|
|
||
| export const useEmbed = () => useContext(EmbedReactContext); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { Box, ChakraProvider } from '@chakra-ui/react'; | ||
| import { useInterpret } from '@xstate/react'; | ||
| import Head from 'next/head'; | ||
| import { useRouter } from 'next/router'; | ||
| import React, { useEffect, useMemo } from 'react'; | ||
| import { createMachine } from 'xstate'; | ||
| import { CanvasProvider } from '../CanvasContext'; | ||
| import { CanvasView } from '../CanvasView'; | ||
| import { EmbedProvider } from '../embedContext'; | ||
| import { SimulationProvider } from '../SimulationContext'; | ||
| import { simulationMachine } from '../simulationMachine'; | ||
| import { theme } from '../theme'; | ||
| import { NextComponentWithMeta } from '../types'; | ||
| import { useInterpretCanvas } from '../useInterpretCanvas'; | ||
| import { parseEmbedQuery, withoutEmbedQueryParams } from '../utils'; | ||
|
|
||
| const machine = createMachine({ | ||
| initial: 'wow', | ||
| states: { | ||
| wow: { | ||
| on: { | ||
| NEXT: { | ||
| target: 'new', | ||
| }, | ||
| }, | ||
| }, | ||
| new: {}, | ||
| }, | ||
| }); | ||
|
|
||
| const ViewOnlyPage: NextComponentWithMeta = () => { | ||
| const canvasService = useInterpretCanvas({ | ||
| sourceID: null, | ||
| }); | ||
| const simulationService = useInterpret(simulationMachine); | ||
| const router = useRouter(); | ||
|
|
||
| useEffect(() => { | ||
| simulationService.send({ | ||
| type: 'MACHINES.REGISTER', | ||
| machines: [machine], | ||
| }); | ||
| }, []); | ||
|
|
||
| const embed = useMemo( | ||
| () => ({ | ||
| ...parseEmbedQuery(router.query), | ||
| isEmbedded: true, | ||
| originalUrl: withoutEmbedQueryParams(router.query), | ||
| }), | ||
| [router.query], | ||
| ); | ||
| return ( | ||
| <> | ||
mattpocock marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <Head> | ||
| <script src="https://unpkg.com/elkjs@0.7.1/lib/elk.bundled.js"></script> | ||
| </Head> | ||
mattpocock marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <EmbedProvider value={embed}> | ||
| <ChakraProvider theme={theme}> | ||
| <CanvasProvider value={canvasService}> | ||
| <SimulationProvider value={simulationService}> | ||
| <Box | ||
| data-testid="app" | ||
| data-viz-theme="dark" | ||
| as="main" | ||
| display="grid" | ||
| gridTemplateColumns="1fr auto" | ||
mattpocock marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| gridTemplateAreas={`"canvas"`} | ||
| height="100vh" | ||
| > | ||
| <CanvasView | ||
| hideHeader | ||
| showControls | ||
| isEmbedded | ||
| shouldEnableZoomInButton | ||
| shouldEnableZoomOutButton | ||
| showPanButtonInEmbed | ||
| showZoomButtonsInEmbed | ||
| /> | ||
| </Box> | ||
| </SimulationProvider> | ||
| </CanvasProvider> | ||
| </ChakraProvider> | ||
| </EmbedProvider> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| ViewOnlyPage.preventAuth = true; | ||
|
|
||
| export default ViewOnlyPage; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.