add undo and redo buttons

pull/5775/head
sawhney17 2022-06-17 18:54:28 +04:00
parent 5a264fad24
commit 071e01b6e0
4 changed files with 47 additions and 1 deletions

View File

@ -0,0 +1,31 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as React from 'react'
import { observer } from 'mobx-react-lite'
import type { Shape } from '~lib'
import { App, useApp } from '@tldraw/react'
import { Minimap } from '~components/Minimap'
import { RedoIcon, UndoIcon } from '~components/icons'
export const ActionBar = observer(function ToolBar(): JSX.Element {
const app = useApp<Shape>()
const undo = React.useCallback(() => {
app.api.undo()
}, [app])
const redo = React.useCallback(() => {
app.api.redo()
}, [app])
return (
<div className="action-bar">
<button onClick={undo}>
<UndoIcon></UndoIcon>
</button>
<button onClick={redo}>
<RedoIcon></RedoIcon>
</button>
</div>
)
})

View File

@ -0,0 +1 @@
export * from './ActionBar';

View File

@ -5,6 +5,7 @@ import { StatusBar } from './StatusBar'
import { PrimaryTools } from './PrimaryTools'
import { DevTools } from './Devtools'
import { Minimap } from './Minimap'
import { ActionBar } from './ActionBar'
const isDev = process.env.NODE_ENV === 'development'
@ -16,6 +17,7 @@ export const AppUI = observer(function AppUI() {
{isDev && <StatusBar />}
{isDev && <DevTools />}
<PrimaryTools />
<ActionBar></ActionBar>
</>
)
})

View File

@ -161,4 +161,16 @@ export class TLApi<S extends TLShape = TLShape, K extends TLEventMap = TLEventMa
this.app.save()
return this
}
undo = () => {
this.app.undo()
this.app.undo()
return this
}
redo = () => {
this.app.redo()
this.app.redo()
return this
}
}