Add storage for openscad code

This commit is contained in:
Kurt Hutten
2021-03-21 14:59:47 +11:00
parent f9f35183af
commit fef69917f5
3 changed files with 8 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
import { useContext, useEffect, Suspense, lazy } from 'react'
import { isBrowser } from '@redwoodjs/prerender/browserUtils'
import { IdeContext } from 'src/components/IdeToolbarNew'
import { codeStorageKey } from 'src/helpers/hooks/useIdeState'
const Editor = lazy(() => import('@monaco-editor/react'))
const IdeEditor = () => {
@@ -34,6 +35,7 @@ const IdeEditor = () => {
if (key === 's' && (ctrlKey || metaKey)) {
event.preventDefault()
dispatch({ type: 'render', payload: { code: state.code } })
localStorage.setItem(codeStorageKey, state.code)
}
}

View File

@@ -1,7 +1,7 @@
import { createContext } from 'react'
import IdeContainer from 'src/components/IdeContainer'
import { isBrowser } from '@redwoodjs/prerender/browserUtils'
import { useIdeState } from 'src/helpers/hooks/useIdeState'
import { useIdeState, codeStorageKey } from 'src/helpers/hooks/useIdeState'
import { copyTextToClipboard } from 'src/helpers/clipboard'
export const IdeContext = createContext()
@@ -12,6 +12,7 @@ const IdeToolbarNew = () => {
}
function handleRender() {
dispatch({ type: 'render', payload: { code: state.code } })
localStorage.setItem(codeStorageKey, state.code)
}
function handleMakeLink() {
if (isBrowser) {