Commit d231ac00 authored by Michael Vrána's avatar Michael Vrána

Redo/Undo buttons disabled when history/future is empty

parent 155b97b6
Pipeline #80159 passed with stages
in 4 minutes
......@@ -35,7 +35,7 @@ const useStyles = makeStyles({
* @param {Props} props
* @returns
*/
function ElementButton(props: Props) {
const ElementButton = (props: Props) => {
const { Icon, label, onAction, event, className, isDisabled } = props
const classes = useStyles()
......@@ -73,8 +73,4 @@ function ElementButton(props: Props) {
)
}
export default React.memo(
ElementButton,
(prev, next) =>
prev.selected === next.selected && prev.onAction === next.onAction
)
export default ElementButton
\ No newline at end of file
......@@ -53,13 +53,15 @@ const useStyles = makeStyles((theme) => ({
export const AlgorithmCanvasToolbar = () => {
const dispatch = useDispatch()
const classes = useStyles()
const { cursorMode, gridOn, elementSelected } = useSelector(
const { cursorMode, gridOn, elementSelected, pastEmpty, futureEmpty } = useSelector(
(state: ReduxState) => ({
cursorMode: state.algorithmCanvas.cursorMode,
gridOn: state.algorithmCanvas.gridOn,
elementSelected:
state.algorithmCanvas.selectedNode ||
state.algorithmCanvas.selectedEdge
state.algorithmCanvas.selectedEdge,
pastEmpty: state.algorithmData.past.length === 0,
futureEmpty: state.algorithmData.future.length === 0
})
)
......@@ -119,11 +121,13 @@ export const AlgorithmCanvasToolbar = () => {
Icon={UndoIcon}
label="Undo"
onAction={handleUndo}
isDisabled={pastEmpty}
/>
<ElementButton
Icon={RedoIcon}
label="Redo"
onAction={handleRedo}
isDisabled={futureEmpty}
/>
<ElementButton
Icon={CloseIcon}
......
import React, { useCallback } from 'react'
import { useDispatch, useSelector, batch } from 'react-redux'
import { useDispatch, useSelector } from 'react-redux'
import { algorithmDataActions } from '../reducers/algorithmData'
import { ReduxState } from '../reducers'
import { Actions } from '../reducers'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment