Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
fix resize end behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Oct 20, 2024
1 parent e061234 commit cebece3
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/renderer/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useTheme } from 'next-themes'
import { useEffect, useState } from 'react'
import { useEffect, useRef, useState } from 'react'
import { NavigateFunction, useLocation, useNavigate, useRoutes } from 'react-router-dom'
import OutboundModeSwitcher from '@renderer/components/sider/outbound-mode-switcher'
import SysproxySwitcher from '@renderer/components/sider/sysproxy-switcher'
Expand Down Expand Up @@ -64,7 +64,9 @@ const App: React.FC = () => {
} = appConfig || {}
const [order, setOrder] = useState(siderOrder)
const [siderWidthValue, setSiderWidthValue] = useState(siderWidth)
const siderWidthValueRef = useRef(siderWidthValue)
const [resizing, setResizing] = useState(false)
const resizingRef = useRef(resizing)
const sensors = useSensors(useSensor(PointerSensor))
const { setTheme, systemTheme } = useTheme()
navigate = useNavigate()
Expand All @@ -84,11 +86,17 @@ const App: React.FC = () => {
}
}
}

useEffect(() => {
setOrder(siderOrder)
setSiderWidthValue(siderWidth)
}, [siderOrder, siderWidth])

useEffect(() => {
siderWidthValueRef.current = siderWidthValue
resizingRef.current = resizing
}, [siderWidthValue, resizing])

useEffect(() => {
const tourShown = window.localStorage.getItem('tourShown')
if (!tourShown) {
Expand All @@ -109,6 +117,18 @@ const App: React.FC = () => {
})
}, [customTheme])

useEffect(() => {
window.addEventListener('mouseup', onResizeEnd)
return (): void => window.removeEventListener('mouseup', onResizeEnd)
}, [])

const onResizeEnd = (): void => {
if (resizingRef.current) {
setResizing(false)
patchAppConfig({ siderWidth: siderWidthValueRef.current })
}
}

const onDragEnd = async (event: DragEndEvent): Promise<void> => {
const { active, over } = event
if (over) {
Expand Down Expand Up @@ -160,12 +180,6 @@ const App: React.FC = () => {

return (
<div
onMouseUp={() => {
if (resizing) {
setResizing(false)
patchAppConfig({ siderWidth: siderWidthValue })
}
}}
onMouseMove={(e) => {
if (!resizing) return
if (e.clientX <= 150) {
Expand Down

0 comments on commit cebece3

Please sign in to comment.