2021-06-03 12:06:39 +00:00
|
|
|
import Command from './command'
|
|
|
|
import history from '../history'
|
|
|
|
import { Data } from 'types'
|
2021-06-07 11:18:50 +00:00
|
|
|
import storage from 'state/storage'
|
2021-06-03 12:06:39 +00:00
|
|
|
|
2021-06-03 13:10:54 +00:00
|
|
|
export default function changePage(data: Data, pageId: string) {
|
2021-06-03 12:06:39 +00:00
|
|
|
const { currentPageId: prevPageId } = data
|
|
|
|
|
|
|
|
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-11 10:11:42 +00:00
|
|
|
storage.savePage(data, data.document.id, prevPageId)
|
2021-06-03 12:06:39 +00:00
|
|
|
data.currentPageId = pageId
|
2021-06-11 10:11:42 +00:00
|
|
|
storage.loadPage(data)
|
2021-06-03 12:06:39 +00:00
|
|
|
},
|
|
|
|
undo(data) {
|
|
|
|
data.currentPageId = prevPageId
|
2021-06-07 11:18:50 +00:00
|
|
|
storage.loadPage(data, prevPageId)
|
2021-06-03 12:06:39 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|