2021-06-03 12:06:39 +00:00
|
|
|
import Command from './command'
|
|
|
|
import history from '../history'
|
|
|
|
import { Data } from 'types'
|
2021-07-09 18:42:43 +00:00
|
|
|
import tld from 'utils/tld'
|
2021-06-07 11:18:50 +00:00
|
|
|
import storage from 'state/storage'
|
2021-06-03 12:06:39 +00:00
|
|
|
|
2021-06-21 21:35:28 +00:00
|
|
|
export default function changePage(data: Data, toPageId: string): void {
|
2021-06-16 12:09:45 +00:00
|
|
|
const { currentPageId: fromPageId } = data
|
2021-06-03 12:06:39 +00:00
|
|
|
|
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
|
|
|
name: 'change_page',
|
|
|
|
category: 'canvas',
|
2021-06-07 11:18:50 +00:00
|
|
|
manualSelection: true,
|
2021-06-03 12:06:39 +00:00
|
|
|
do(data) {
|
2021-06-16 12:09:45 +00:00
|
|
|
storage.savePage(data, data.document.id, fromPageId)
|
|
|
|
storage.loadPage(data, data.document.id, toPageId)
|
|
|
|
data.currentPageId = toPageId
|
2021-07-01 14:03:02 +00:00
|
|
|
data.currentParentId = toPageId
|
2021-07-09 18:42:43 +00:00
|
|
|
|
|
|
|
tld.setZoomCSS(tld.getPageState(data).camera.zoom)
|
2021-06-03 12:06:39 +00:00
|
|
|
},
|
|
|
|
undo(data) {
|
2021-06-16 12:09:45 +00:00
|
|
|
storage.loadPage(data, data.document.id, fromPageId)
|
|
|
|
data.currentPageId = fromPageId
|
2021-07-01 14:03:02 +00:00
|
|
|
data.currentParentId = fromPageId
|
2021-07-09 18:42:43 +00:00
|
|
|
|
|
|
|
tld.setZoomCSS(tld.getPageState(data).camera.zoom)
|
2021-06-03 12:06:39 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|