diff --git a/frontend/src/features/options/AdvancedOptions/Inpainting/ClearBrushHistory.tsx b/frontend/src/features/options/AdvancedOptions/Inpainting/ClearBrushHistory.tsx new file mode 100644 index 0000000000..9d5b1acc14 --- /dev/null +++ b/frontend/src/features/options/AdvancedOptions/Inpainting/ClearBrushHistory.tsx @@ -0,0 +1,56 @@ +import { useToast } from '@chakra-ui/react'; +import { createSelector } from '@reduxjs/toolkit'; +import React from 'react'; +import { + RootState, + useAppDispatch, + useAppSelector, +} from '../../../../app/store'; +import IAIButton from '../../../../common/components/IAIButton'; +import { + InpaintingState, + setClearBrushHistory, +} from '../../../tabs/Inpainting/inpaintingSlice'; +import _ from 'lodash'; + +const clearBrushHistorySelector = createSelector( + (state: RootState) => state.inpainting, + (inpainting: InpaintingState) => { + const { pastLines, futureLines } = inpainting; + return { + pastLines, + futureLines, + }; + }, + { + memoizeOptions: { + resultEqualityCheck: _.isEqual, + }, + } +); + +export default function ClearBrushHistory() { + const dispatch = useAppDispatch(); + const toast = useToast(); + + const { pastLines, futureLines } = useAppSelector(clearBrushHistorySelector); + + const handleClearBrushHistory = () => { + dispatch(setClearBrushHistory()); + toast({ + title: 'Brush Stroke History Cleared', + status: 'success', + duration: 2500, + isClosable: true, + }); + }; + return ( + 0 || pastLines.length > 0 ? false : true} + styleClass="inpainting-options-btn" + /> + ); +} diff --git a/frontend/src/features/options/AdvancedOptions/Inpainting/InpaintReplace.tsx b/frontend/src/features/options/AdvancedOptions/Inpainting/InpaintReplace.tsx new file mode 100644 index 0000000000..5333f7b8ab --- /dev/null +++ b/frontend/src/features/options/AdvancedOptions/Inpainting/InpaintReplace.tsx @@ -0,0 +1,70 @@ +import React, { ChangeEvent } from 'react'; +import { + RootState, + useAppDispatch, + useAppSelector, +} from '../../../../app/store'; +import IAINumberInput from '../../../../common/components/IAINumberInput'; +import _ from 'lodash'; +import { createSelector } from '@reduxjs/toolkit'; +import { + InpaintingState, + setInpaintReplace, + setShouldUseInpaintReplace, +} from '../../../tabs/Inpainting/inpaintingSlice'; +import IAISwitch from '../../../../common/components/IAISwitch'; + +const inpaintReplaceSelector = createSelector( + (state: RootState) => state.inpainting, + (inpainting: InpaintingState) => { + const { inpaintReplace, shouldUseInpaintReplace } = inpainting; + return { + inpaintReplace, + shouldUseInpaintReplace, + }; + }, + { + memoizeOptions: { + resultEqualityCheck: _.isEqual, + }, + } +); + +export default function InpaintReplace() { + const { inpaintReplace, shouldUseInpaintReplace } = useAppSelector( + inpaintReplaceSelector + ); + + const dispatch = useAppDispatch(); + + return ( +
+ { + dispatch(setInpaintReplace(v)); + }} + /> + ) => + dispatch(setShouldUseInpaintReplace(e.target.checked)) + } + /> +
+ ); +} diff --git a/frontend/src/features/options/AdvancedOptions/Inpainting/InpaintingSettings.tsx b/frontend/src/features/options/AdvancedOptions/Inpainting/InpaintingSettings.tsx index 7624c655f8..6d230a8b2a 100644 --- a/frontend/src/features/options/AdvancedOptions/Inpainting/InpaintingSettings.tsx +++ b/frontend/src/features/options/AdvancedOptions/Inpainting/InpaintingSettings.tsx @@ -1,96 +1,13 @@ -import { useToast } from '@chakra-ui/react'; -import { createSelector } from '@reduxjs/toolkit'; -import React, { ChangeEvent } from 'react'; -import { - RootState, - useAppDispatch, - useAppSelector, -} from '../../../../app/store'; -import IAIButton from '../../../../common/components/IAIButton'; -import { - InpaintingState, - setClearBrushHistory, - setInpaintReplace, - setShouldUseInpaintReplace, -} from '../../../tabs/Inpainting/inpaintingSlice'; import BoundingBoxSettings from './BoundingBoxSettings'; -import _ from 'lodash'; -import IAINumberInput from '../../../../common/components/IAINumberInput'; -import IAISwitch from '../../../../common/components/IAISwitch'; - -const inpaintingSelector = createSelector( - (state: RootState) => state.inpainting, - (inpainting: InpaintingState) => { - const { pastLines, futureLines, inpaintReplace, shouldUseInpaintReplace } = - inpainting; - return { - pastLines, - futureLines, - inpaintReplace, - shouldUseInpaintReplace, - }; - }, - { - memoizeOptions: { - resultEqualityCheck: _.isEqual, - }, - } -); +import InpaintReplace from './InpaintReplace'; +import ClearBrushHistory from './ClearBrushHistory'; export default function InpaintingSettings() { - const dispatch = useAppDispatch(); - const toast = useToast(); - - const { pastLines, futureLines, inpaintReplace, shouldUseInpaintReplace } = - useAppSelector(inpaintingSelector); - - const handleClearBrushHistory = () => { - dispatch(setClearBrushHistory()); - toast({ - title: 'Brush Stroke History Cleared', - status: 'success', - duration: 2500, - isClosable: true, - }); - }; return ( <> -
- { - dispatch(setInpaintReplace(v)); - }} - /> - ) => - dispatch(setShouldUseInpaintReplace(e.target.checked)) - } - /> -
+ - 0 || pastLines.length > 0 ? false : true} - styleClass="inpainting-options-btn" - /> + ); }