import { ButtonGroup, Flex } from '@chakra-ui/react'; import { createSelector } from '@reduxjs/toolkit'; import { setBrushColor, setBrushSize, setTool, } from 'features/canvas/store/canvasSlice'; import { useAppDispatch, useAppSelector } from 'app/store'; import _ from 'lodash'; import IAIIconButton from 'common/components/IAIIconButton'; import { FaEraser, FaPaintBrush, FaSlidersH } from 'react-icons/fa'; import { canvasSelector, isStagingSelector, } from 'features/canvas/store/canvasSelectors'; import { systemSelector } from 'features/system/store/systemSelectors'; import { useHotkeys } from 'react-hotkeys-hook'; import IAIPopover from 'common/components/IAIPopover'; import IAISlider from 'common/components/IAISlider'; import IAIColorPicker from 'common/components/IAIColorPicker'; import { rgbaColorToString } from 'features/canvas/util/colorToString'; export const selector = createSelector( [canvasSelector, isStagingSelector, systemSelector], (canvas, isStaging, system) => { const { isProcessing } = system; const { tool, brushColor, brushSize } = canvas; return { tool, isStaging, isProcessing, brushColor, brushColorString: rgbaColorToString(brushColor), brushSize, }; }, { memoizeOptions: { resultEqualityCheck: _.isEqual, }, } ); const IAICanvasToolChooserOptions = () => { const dispatch = useAppDispatch(); const { tool, brushColor, brushSize, brushColorString, isStaging } = useAppSelector(selector); useHotkeys( ['b'], () => { handleSelectBrushTool(); }, { enabled: () => true, preventDefault: true, }, [] ); useHotkeys( ['e'], () => { handleSelectEraserTool(); }, { enabled: () => true, preventDefault: true, }, [tool] ); useHotkeys( ['['], () => { dispatch(setBrushSize(Math.max(brushSize - 5, 5))); }, { enabled: () => true, preventDefault: true, }, [brushSize] ); useHotkeys( [']'], () => { dispatch(setBrushSize(Math.min(brushSize + 5, 500))); }, { enabled: () => true, preventDefault: true, }, [brushSize] ); const handleSelectBrushTool = () => dispatch(setTool('brush')); const handleSelectEraserTool = () => dispatch(setTool('eraser')); return ( } data-selected={tool === 'brush' && !isStaging} onClick={handleSelectBrushTool} isDisabled={isStaging} /> } data-selected={tool === 'eraser' && !isStaging} isDisabled={isStaging} onClick={() => dispatch(setTool('eraser'))} /> } /> } > dispatch(setBrushSize(newSize))} sliderNumberInputProps={{ max: 500 }} inputReadOnly={false} /> dispatch(setBrushColor(newColor))} /> ); }; export default IAICanvasToolChooserOptions;