Fix bug with Shortcuts Modal & added missing useEffect dependencies

This commit is contained in:
blessedcoolant 2022-04-08 17:04:55 +12:00
parent c3315a2d2b
commit 4d118698b4
3 changed files with 14 additions and 14 deletions

View File

@ -240,17 +240,6 @@ export default function Editor(props: EditorProps) {
} }
}, [context?.canvas, draw, original, isOriginalLoaded, windowSize]) }, [context?.canvas, draw, original, isOriginalLoaded, windowSize])
useEffect(() => {
window.addEventListener('resize', () => {
resetZoom()
})
return () => {
window.removeEventListener('resize', () => {
resetZoom()
})
}
}, [windowSize])
// Zoom reset // Zoom reset
const resetZoom = useCallback(() => { const resetZoom = useCallback(() => {
if (!minScale || !original || !windowSize) { if (!minScale || !original || !windowSize) {
@ -267,6 +256,17 @@ export default function Editor(props: EditorProps) {
setScale(minScale) setScale(minScale)
}, [viewportRef, minScale, original, windowSize]) }, [viewportRef, minScale, original, windowSize])
useEffect(() => {
window.addEventListener('resize', () => {
resetZoom()
})
return () => {
window.removeEventListener('resize', () => {
resetZoom()
})
}
}, [windowSize, resetZoom])
const handleEscPressed = () => { const handleEscPressed = () => {
if (isInpaintingLoading) { if (isInpaintingLoading) {
return return

View File

@ -17,7 +17,7 @@ export const ThemeChanger = () => {
} else { } else {
setTheme('light') setTheme('light')
} }
}, []) }, [setTheme])
const themeSwitchHandler = () => { const themeSwitchHandler = () => {
const newTheme = theme === 'light' ? 'dark' : 'light' const newTheme = theme === 'light' ? 'dark' : 'light'

View File

@ -1,7 +1,7 @@
import React, { ReactNode } from 'react' import React, { ReactNode } from 'react'
import { useSetRecoilState } from 'recoil' import { useSetRecoilState } from 'recoil'
import { shortcutsState } from '../../store/Atoms' import { shortcutsState } from '../../store/Atoms'
import Modal, { ModalProps } from '../shared/Modal' import Modal from '../shared/Modal'
interface Shortcut { interface Shortcut {
children: ReactNode children: ReactNode
@ -28,7 +28,7 @@ export default function ShortcutsModal(props: ShortcutsModalProps) {
const setShortcutState = useSetRecoilState(shortcutsState) const setShortcutState = useSetRecoilState(shortcutsState)
const shortcutStateHandler = () => { const shortcutStateHandler = () => {
setShortcutState(prevShortcutState => !prevShortcutState) setShortcutState(false)
} }
return ( return (