Add storage for openscad code
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { useContext, useEffect, Suspense, lazy } from 'react'
|
import { useContext, useEffect, Suspense, lazy } from 'react'
|
||||||
import { isBrowser } from '@redwoodjs/prerender/browserUtils'
|
import { isBrowser } from '@redwoodjs/prerender/browserUtils'
|
||||||
import { IdeContext } from 'src/components/IdeToolbarNew'
|
import { IdeContext } from 'src/components/IdeToolbarNew'
|
||||||
|
import { codeStorageKey } from 'src/helpers/hooks/useIdeState'
|
||||||
const Editor = lazy(() => import('@monaco-editor/react'))
|
const Editor = lazy(() => import('@monaco-editor/react'))
|
||||||
|
|
||||||
const IdeEditor = () => {
|
const IdeEditor = () => {
|
||||||
@@ -34,6 +35,7 @@ const IdeEditor = () => {
|
|||||||
if (key === 's' && (ctrlKey || metaKey)) {
|
if (key === 's' && (ctrlKey || metaKey)) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
dispatch({ type: 'render', payload: { code: state.code } })
|
dispatch({ type: 'render', payload: { code: state.code } })
|
||||||
|
localStorage.setItem(codeStorageKey, state.code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createContext } from 'react'
|
import { createContext } from 'react'
|
||||||
import IdeContainer from 'src/components/IdeContainer'
|
import IdeContainer from 'src/components/IdeContainer'
|
||||||
import { isBrowser } from '@redwoodjs/prerender/browserUtils'
|
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'
|
import { copyTextToClipboard } from 'src/helpers/clipboard'
|
||||||
|
|
||||||
export const IdeContext = createContext()
|
export const IdeContext = createContext()
|
||||||
@@ -12,6 +12,7 @@ const IdeToolbarNew = () => {
|
|||||||
}
|
}
|
||||||
function handleRender() {
|
function handleRender() {
|
||||||
dispatch({ type: 'render', payload: { code: state.code } })
|
dispatch({ type: 'render', payload: { code: state.code } })
|
||||||
|
localStorage.setItem(codeStorageKey, state.code)
|
||||||
}
|
}
|
||||||
function handleMakeLink() {
|
function handleMakeLink() {
|
||||||
if (isBrowser) {
|
if (isBrowser) {
|
||||||
|
|||||||
@@ -16,11 +16,14 @@ module stick(basewid, angl){
|
|||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
|
|
||||||
|
export const codeStorageKey = 'Last-openscad-code'
|
||||||
|
|
||||||
export const useIdeState = () => {
|
export const useIdeState = () => {
|
||||||
|
const code = localStorage.getItem(codeStorageKey) || donutInitCode
|
||||||
const initialState = {
|
const initialState = {
|
||||||
ideType: 'openScad',
|
ideType: 'openScad',
|
||||||
consoleMessages: [{ type: 'message', message: 'Initialising OpenSCAD' }],
|
consoleMessages: [{ type: 'message', message: 'Initialising OpenSCAD' }],
|
||||||
code: donutInitCode,
|
code,
|
||||||
objectData: {
|
objectData: {
|
||||||
type: 'stl',
|
type: 'stl',
|
||||||
data: 'some binary',
|
data: 'some binary',
|
||||||
|
|||||||
Reference in New Issue
Block a user