support resize sidebar

This commit is contained in:
pompurin404 2024-10-18 21:07:33 +08:00
parent 82d7cf05bd
commit b6dc50b7ae
No known key found for this signature in database
5 changed files with 46 additions and 8 deletions

View File

@ -3,7 +3,7 @@
<img height='48px' src='./images/icon-black.png#gh-light-mode-only'> <img height='48px' src='./images/icon-black.png#gh-light-mode-only'>
</h3> </h3>
<h3 align="center">Another Mihomo GUI</h3> <h3 align="center">Another <a href="https://github.com/MetaCubeX/mihomo">Mihomo</a> GUI</h3>
<p align="center"> <p align="center">
<a href="https://github.com/mihomo-party-org/mihomo-party/releases"> <a href="https://github.com/mihomo-party-org/mihomo-party/releases">

View File

@ -32,6 +32,7 @@ export const defaultConfig: IAppConfig = {
'log', 'log',
'substore' 'substore'
], ],
siderWidth: 250,
sysProxy: { enable: false, mode: 'manual' } sysProxy: { enable: false, mode: 'manual' }
} }

View File

@ -44,6 +44,7 @@ const App: React.FC = () => {
appTheme = 'system', appTheme = 'system',
customTheme, customTheme,
useWindowFrame = false, useWindowFrame = false,
siderWidth = 250,
siderOrder = [ siderOrder = [
'sysproxy', 'sysproxy',
'tun', 'tun',
@ -61,6 +62,8 @@ const App: React.FC = () => {
] ]
} = appConfig || {} } = appConfig || {}
const [order, setOrder] = useState(siderOrder) const [order, setOrder] = useState(siderOrder)
const [siderWidthValue, setSiderWidthValue] = useState(siderWidth)
const [resizing, setResizing] = useState(false)
const sensors = useSensors(useSensor(PointerSensor)) const sensors = useSensors(useSensor(PointerSensor))
const { setTheme, systemTheme } = useTheme() const { setTheme, systemTheme } = useTheme()
navigate = useNavigate() navigate = useNavigate()
@ -82,7 +85,8 @@ const App: React.FC = () => {
} }
useEffect(() => { useEffect(() => {
setOrder(siderOrder) setOrder(siderOrder)
}, [siderOrder]) setSiderWidthValue(siderWidth)
}, [siderOrder, siderWidth])
useEffect(() => { useEffect(() => {
const tourShown = window.localStorage.getItem('tourShown') const tourShown = window.localStorage.getItem('tourShown')
@ -154,8 +158,29 @@ const App: React.FC = () => {
} }
return ( return (
<div className="w-full h-[100vh] flex"> <div
<div className="side w-[250px] h-full overflow-y-auto no-scrollbar"> onMouseUp={() => {
if (resizing) {
setResizing(false)
patchAppConfig({ siderWidth: siderWidthValue })
}
}}
onMouseMove={(e) => {
if (!resizing) return
if (e.clientX <= 250) {
setSiderWidthValue(250)
} else if (e.clientX >= 400) {
setSiderWidthValue(400)
} else {
setSiderWidthValue(e.clientX)
}
}}
className={`w-full h-[100vh] flex ${resizing ? 'cursor-ew-resize' : ''}`}
>
<div
style={{ width: `${siderWidthValue}px` }}
className="side h-full overflow-y-auto no-scrollbar"
>
<div className="app-drag sticky top-0 z-40 backdrop-blur bg-transparent h-[49px]"> <div className="app-drag sticky top-0 z-40 backdrop-blur bg-transparent h-[49px]">
<div <div
className={`flex justify-between p-2 ${!useWindowFrame && platform === 'darwin' ? 'ml-[60px]' : ''}`} className={`flex justify-between p-2 ${!useWindowFrame && platform === 'darwin' ? 'ml-[60px]' : ''}`}
@ -191,8 +216,22 @@ const App: React.FC = () => {
</div> </div>
</DndContext> </DndContext>
</div> </div>
<div
onMouseDown={() => {
setResizing(true)
}}
style={{
position: 'fixed',
zIndex: 100,
left: `${siderWidthValue - 2}px`,
width: '5px',
height: '100vh',
cursor: 'ew-resize'
}}
className={resizing ? 'bg-primary' : ''}
/>
<Divider orientation="vertical" /> <Divider orientation="vertical" />
<div className="main w-[calc(100%-251px)] h-full overflow-y-auto">{page}</div> <div className="main grow h-full overflow-y-auto">{page}</div>
</div> </div>
) )
} }

View File

@ -136,7 +136,6 @@ const SubStoreConfig: React.FC = () => {
)} )}
<Input <Input
size="sm" size="sm"
className="flex-grown"
value={subStoreBackendSyncCronValue} value={subStoreBackendSyncCronValue}
placeholder="Cron 表达式" placeholder="Cron 表达式"
onValueChange={(v: string) => { onValueChange={(v: string) => {
@ -170,7 +169,6 @@ const SubStoreConfig: React.FC = () => {
)} )}
<Input <Input
size="sm" size="sm"
className="flex-grown"
value={subStoreBackendDownloadCronValue} value={subStoreBackendDownloadCronValue}
placeholder="Cron 表达式" placeholder="Cron 表达式"
onValueChange={(v: string) => { onValueChange={(v: string) => {
@ -204,7 +202,6 @@ const SubStoreConfig: React.FC = () => {
)} )}
<Input <Input
size="sm" size="sm"
className="flex-grown"
value={subStoreBackendUploadCronValue} value={subStoreBackendUploadCronValue}
placeholder="Cron 表达式" placeholder="Cron 表达式"
onValueChange={(v: string) => { onValueChange={(v: string) => {

View File

@ -245,6 +245,7 @@ interface IAppConfig {
useWindowFrame: boolean useWindowFrame: boolean
proxyInTray: boolean proxyInTray: boolean
siderOrder: string[] siderOrder: string[]
siderWidth: number
appTheme: AppTheme appTheme: AppTheme
customTheme?: string customTheme?: string
autoCheckUpdate: boolean autoCheckUpdate: boolean