Skip to content

Commit 9ce3028

Browse files
committed
🎈 perf(视频列表): 分割线修改
1 parent d4316cc commit 9ce3028

File tree

4 files changed

+61
-51
lines changed

4 files changed

+61
-51
lines changed

‎package.json

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"ramda": "^0.30.0",
3131
"react": "^18.2.0",
3232
"react-dom": "^18.2.0",
33-
"react-resizable-panels": "^2.1.7",
3433
"react-router-dom": "^6.23.1",
3534
"tailwind-merge": "^2.3.0"
3635
},

‎pnpm-lock.yaml

-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/main.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const client = new QueryClient({
1313
queries: {
1414
refetchOnWindowFocus: false,
1515
gcTime: 5 * 60 * 1000,
16-
staleTime: 1 * 60 * 1000
16+
staleTime: 10 * 60 * 1000
1717
}
1818
}
1919
})

‎src/pages/root/home/space/index.tsx

+60-35
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import { useRootDirPath } from '@/hooks/use-root-dir-path'
99
import { useAllBVData } from '@/queries/useAllBVData'
1010
import { cls } from '@/utils/cls'
1111
import { Avatar } from 'antd'
12-
import { Suspense, useState } from 'react'
12+
import { Suspense, useCallback, useRef, useState } from 'react'
1313
import { NavLink, Outlet, useParams } from 'react-router-dom'
1414

15-
import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels'
16-
1715
export default function Space() {
1816
const rootDirPath = useRootDirPath()
1917
const { data: allData } = useAllBVData(rootDirPath)
@@ -22,41 +20,68 @@ export default function Space() {
2220
const isAll = !mid
2321

2422
// UI
25-
const [isDragging, setIsDragging] = useState(false)
23+
const [leftWidth, setLeftWidth] = useState(128)
24+
const handleRef = useRef<HTMLElement>(null)
25+
26+
const handleMouseDown = useCallback(
27+
(e: React.MouseEvent) => {
28+
e.preventDefault()
29+
const startX = e.clientX
30+
const startWidth = leftWidth
31+
32+
const onMouseMove = (e: MouseEvent) => {
33+
const dx = e.clientX - startX
34+
const newWidth = startWidth + dx
35+
const minWidth = 100
36+
const maxWidth = 400
37+
if (newWidth >= minWidth && newWidth <= maxWidth) {
38+
setLeftWidth(newWidth)
39+
}
40+
}
41+
42+
const onMouseUp = () => {
43+
document.removeEventListener('mousemove', onMouseMove)
44+
document.removeEventListener('mouseup', onMouseUp)
45+
}
46+
47+
document.addEventListener('mousemove', onMouseMove)
48+
document.addEventListener('mouseup', onMouseUp)
49+
},
50+
[leftWidth]
51+
)
2652

2753
return (
2854
<>
29-
<PanelGroup direction='horizontal' className='flex h-full flex-1'>
30-
<Panel id='sidebar' defaultSize={15} minSize={10} maxSize={30} order={1}>
31-
<aside className='h-full overflow-auto'>
32-
<NavLink
33-
className={cls(
34-
'm-2 flex items-center space-x-2 rounded-md p-2 transition-all',
35-
isAll ? 'bg-slate-100 text-primary' : '!text-gray-500 hover:!bg-slate-50'
36-
)}
37-
to=''
38-
>
39-
<Avatar className='h-8 w-8 flex-shrink-0'>all</Avatar>
40-
<span className='truncate text-sm'>全部UP主</span>
41-
</NavLink>
42-
43-
{allData?.ups.map((v) => <OwnerListItem key={v.mid} mid={v.mid} path={v.path} />)}
44-
</aside>
45-
</Panel>
46-
47-
<PanelResizeHandle
48-
onDragging={setIsDragging}
49-
className={cls('w-[1px] bg-gray-200 transition-all', isDragging ? 'cursor-move bg-primary' : '')}
50-
/>
51-
52-
<Panel minSize={25} order={2}>
53-
<main className='h-full overflow-auto'>
54-
<Suspense fallback={null}>
55-
<Outlet />
56-
</Suspense>
57-
</main>
58-
</Panel>
59-
</PanelGroup>
55+
<section className='flex h-full flex-1'>
56+
<aside className='flex-shrink-0 overflow-auto' style={{ width: leftWidth }}>
57+
<NavLink
58+
className={cls(
59+
'm-2 flex items-center space-x-2 rounded-md p-2 transition-all',
60+
isAll ? 'bg-slate-100 text-primary' : '!text-gray-500 hover:!bg-slate-50'
61+
)}
62+
to=''
63+
>
64+
<Avatar className='h-8 w-8 flex-shrink-0'>all</Avatar>
65+
<span className='truncate text-sm'>全部UP主</span>
66+
</NavLink>
67+
68+
{allData?.ups.map((v) => <OwnerListItem key={v.mid} mid={v.mid} path={v.path} />)}
69+
</aside>
70+
71+
<div className='relative w-[1px] bg-gray-200 transition-all hover:bg-primary'>
72+
<i
73+
ref={handleRef}
74+
onMouseDown={handleMouseDown}
75+
className='absolute bottom-0 left-0 top-0 w-3 -translate-x-1/2 transform cursor-ew-resize'
76+
></i>
77+
</div>
78+
79+
<main className='flex-1 overflow-auto'>
80+
<Suspense fallback={null}>
81+
<Outlet />
82+
</Suspense>
83+
</main>
84+
</section>
6085
</>
6186
)
6287
}

0 commit comments

Comments
 (0)