Add storage for openscad code
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -16,11 +16,14 @@ module stick(basewid, angl){
|
||||
}
|
||||
}`
|
||||
|
||||
export const codeStorageKey = 'Last-openscad-code'
|
||||
|
||||
export const useIdeState = () => {
|
||||
const code = localStorage.getItem(codeStorageKey) || donutInitCode
|
||||
const initialState = {
|
||||
ideType: 'openScad',
|
||||
consoleMessages: [{ type: 'message', message: 'Initialising OpenSCAD' }],
|
||||
code: donutInitCode,
|
||||
code,
|
||||
objectData: {
|
||||
type: 'stl',
|
||||
data: 'some binary',
|
||||
|
||||
Reference in New Issue
Block a user