fix resize end behavior
Some checks failed
Build / windows (arm64) (push) Has been cancelled
Build / windows (ia32) (push) Has been cancelled
Build / windows (x64) (push) Has been cancelled
Build / windows7 (ia32) (push) Has been cancelled
Build / windows7 (x64) (push) Has been cancelled
Build / linux (arm64) (push) Has been cancelled
Build / linux (x64) (push) Has been cancelled
Build / macos (arm64) (push) Has been cancelled
Build / macos (x64) (push) Has been cancelled
Build / macos10 (arm64) (push) Has been cancelled
Build / macos10 (x64) (push) Has been cancelled
Build / aur-git-updater (push) Has been cancelled
Build / artifact (push) Has been cancelled
Build / updater (push) Has been cancelled
Build / aur-release-updater (mihomo-party) (push) Has been cancelled
Build / aur-release-updater (mihomo-party-bin) (push) Has been cancelled
Build / aur-release-updater (mihomo-party-electron) (push) Has been cancelled
Build / aur-release-updater (mihomo-party-electron-bin) (push) Has been cancelled
Build / Update WinGet Package (push) Has been cancelled
Build / Update Homebrew cask (push) Has been cancelled

This commit is contained in:
pompurin404 2024-10-20 13:58:53 +08:00
parent e0612344d7
commit cebece3748
No known key found for this signature in database

View File

@ -1,5 +1,5 @@
import { useTheme } from 'next-themes' 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 { NavigateFunction, useLocation, useNavigate, useRoutes } from 'react-router-dom'
import OutboundModeSwitcher from '@renderer/components/sider/outbound-mode-switcher' import OutboundModeSwitcher from '@renderer/components/sider/outbound-mode-switcher'
import SysproxySwitcher from '@renderer/components/sider/sysproxy-switcher' import SysproxySwitcher from '@renderer/components/sider/sysproxy-switcher'
@ -64,7 +64,9 @@ const App: React.FC = () => {
} = appConfig || {} } = appConfig || {}
const [order, setOrder] = useState(siderOrder) const [order, setOrder] = useState(siderOrder)
const [siderWidthValue, setSiderWidthValue] = useState(siderWidth) const [siderWidthValue, setSiderWidthValue] = useState(siderWidth)
const siderWidthValueRef = useRef(siderWidthValue)
const [resizing, setResizing] = useState(false) const [resizing, setResizing] = useState(false)
const resizingRef = useRef(resizing)
const sensors = useSensors(useSensor(PointerSensor)) const sensors = useSensors(useSensor(PointerSensor))
const { setTheme, systemTheme } = useTheme() const { setTheme, systemTheme } = useTheme()
navigate = useNavigate() navigate = useNavigate()
@ -84,11 +86,17 @@ const App: React.FC = () => {
} }
} }
} }
useEffect(() => { useEffect(() => {
setOrder(siderOrder) setOrder(siderOrder)
setSiderWidthValue(siderWidth) setSiderWidthValue(siderWidth)
}, [siderOrder, siderWidth]) }, [siderOrder, siderWidth])
useEffect(() => {
siderWidthValueRef.current = siderWidthValue
resizingRef.current = resizing
}, [siderWidthValue, resizing])
useEffect(() => { useEffect(() => {
const tourShown = window.localStorage.getItem('tourShown') const tourShown = window.localStorage.getItem('tourShown')
if (!tourShown) { if (!tourShown) {
@ -109,6 +117,18 @@ const App: React.FC = () => {
}) })
}, [customTheme]) }, [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 onDragEnd = async (event: DragEndEvent): Promise<void> => {
const { active, over } = event const { active, over } = event
if (over) { if (over) {
@ -160,12 +180,6 @@ const App: React.FC = () => {
return ( return (
<div <div
onMouseUp={() => {
if (resizing) {
setResizing(false)
patchAppConfig({ siderWidth: siderWidthValue })
}
}}
onMouseMove={(e) => { onMouseMove={(e) => {
if (!resizing) return if (!resizing) return
if (e.clientX <= 150) { if (e.clientX <= 150) {