diff --git a/shared/naturalcrit/splitPane/splitPane.jsx b/shared/naturalcrit/splitPane/splitPane.jsx index 70dd98e43..6d7d0642f 100644 --- a/shared/naturalcrit/splitPane/splitPane.jsx +++ b/shared/naturalcrit/splitPane/splitPane.jsx @@ -1,11 +1,11 @@ require('./splitPane.less'); const React = require('react'); -const { useState, useEffect, useRef } = React; -const cx = require('classnames'); +const { useState, useEffect } = React; + +const storageKey = 'naturalcrit-pane-split'; const SplitPane = (props)=>{ const { - storageKey = 'naturalcrit-pane-split', onDragFinish = ()=>{}, showDividerButtons = true } = props; @@ -17,26 +17,25 @@ const SplitPane = (props)=>{ const [showMoveArrows, setShowMoveArrows] = useState(true); const [liveScroll, setLiveScroll] = useState(false); - const dividerRef = useRef(null); - // Set initial divider position and liveScroll only after mounting useEffect(()=>{ const savedPos = window.localStorage.getItem(storageKey); setDividerPos(savedPos ? parseInt(savedPos, 10) : window.innerWidth / 2); setLiveScroll(window.localStorage.getItem('liveScroll') === 'true'); - const handleResize = ()=>{ - setDividerPos((pos)=>limitPosition(pos,0.1 * (window.innerWidth - 13), 0.9 * (window.innerWidth - 13)) - ); - }; window.addEventListener('resize', handleResize); return ()=>window.removeEventListener('resize', handleResize); - }, [storageKey]); + }, []); const limitPosition = (x, min = 1, max = window.innerWidth - 13)=>{ return Math.round(Math.min(max, Math.max(min, x))); }; + const handleResize = ()=>{ + setDividerPos((pos)=>limitPosition(pos, 0.1 * (window.innerWidth - 13), 0.9 * (window.innerWidth - 13)) + ); + }; + const handleUp =(e)=>{ e.preventDefault(); if(isDragging) { @@ -63,30 +62,26 @@ const SplitPane = (props)=>{ setLiveScroll(!liveScroll); }; - const moveArrows = showMoveArrows && ( + const renderMoveArrows = (showMoveArrows && <> - {['left', 'right'].map((direction, index) => ( -