Skip to content

Commit

Permalink
Persist SlidePanel panelWidth to localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
platypii committed Dec 16, 2024
1 parent 392af92 commit 89923ba
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/components/src/components/viewers/SlidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,20 @@ export default function SlidePanel({
return undefined
}
const defaultWidth = validWidth(config?.slidePanel?.defaultWidth) ?? WIDTH.DEFAULT
const [panelWidth, setPanelWidth] = useState(defaultWidth)
const [resizingClientX, setResizingClientX] = useState(-1)
const panelRef = React.createRef<HTMLDivElement>()

// Load initial panel width from localStorage if available
const [panelWidth, setPanelWidth] = useState<number>(() => {
const savedWidth = typeof window !== 'undefined' ? localStorage.getItem('panelWidth') : null
return savedWidth ? parseInt(savedWidth, 10) : defaultWidth
})

useEffect(() => {
// Persist panelWidth to localStorage
localStorage.setItem('panelWidth', panelWidth.toString())
}, [panelWidth])

useEffect(() => {
function handleMouseMove(e: MouseEvent) {
if (resizingClientX === -1) return
Expand Down

0 comments on commit 89923ba

Please sign in to comment.