Improves file saving / page saving and loading

This commit is contained in:
Steve Ruiz 2021-06-16 13:09:45 +01:00
parent 7e03adcd52
commit 4ce2b8cc6b
68 changed files with 1166 additions and 997 deletions

View file

@ -1,9 +1,8 @@
import Command from './command'
import history from '../history'
import { Data, Page, PageState } from 'types'
import { v4 as uuid } from 'uuid'
import { uniqueId } from 'utils/utils'
import { current } from 'immer'
import { getSelectedIds } from 'utils/utils'
import storage from 'state/storage'
export default function createPage(data: Data) {
@ -20,12 +19,14 @@ export default function createPage(data: Data) {
data.pageStates[page.id] = pageState
data.currentPageId = page.id
storage.savePage(data, data.document.id, page.id)
storage.saveDocumentToLocalStorage(data)
},
undo(data) {
const { page, currentPageId } = snapshot
delete data.document.pages[page.id]
delete data.pageStates[page.id]
data.currentPageId = currentPageId
storage.saveDocumentToLocalStorage(data)
},
})
)
@ -36,7 +37,7 @@ function getSnapshot(data: Data) {
const pages = Object.values(data.document.pages)
const unchanged = pages.filter((page) => page.name.startsWith('Page '))
const id = uuid()
const id = uniqueId()
const page: Page = {
type: 'page',
@ -46,7 +47,8 @@ function getSnapshot(data: Data) {
shapes: {},
}
const pageState: PageState = {
selectedIds: new Set<string>(),
id,
selectedIds: new Set([]),
camera: {
point: [0, 0],
zoom: 1,