diff --git a/src/index.tsx b/src/index.tsx index 3ffa138c9..3de10137e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -13,6 +13,8 @@ type ExcaliburTextElement = ExcaliburElement & { actualBoundingBoxAscent: number; }; +const LOCAL_STORAGE_KEY = "excalibur"; + var elements = Array.of(); // https://stackoverflow.com/a/6853926/232122 @@ -348,6 +350,31 @@ function deleteSelectedElements() { } } +function save() { + if (elements && elements.length > 0) { + const items = [...elements]; + for (const item of items) { + item.isSelected = false; + } + + localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(items)); + } +} + +function restore() { + const el = localStorage.getItem(LOCAL_STORAGE_KEY); + + if (el) { + const items = JSON.parse(el); + for (let item of items) { + item = generateDraw(item); + } + elements = [...items]; + + drawScene(); + } +} + type AppState = { draggingElement: ExcaliburElement | null; elementType: string; @@ -436,50 +463,62 @@ class App extends React.Component<{}, AppState> { } public render() { + const hasSavedItems = !!localStorage.getItem(LOCAL_STORAGE_KEY); + return ( <> -
- -