From 43441f318574c15b8c85da11048ade99f7eccc25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sat, 26 Oct 2024 22:54:16 +0200 Subject: [PATCH] last changes as suggested --- shared/naturalcrit/splitPane/splitPane.jsx | 61 ++++++++++------------ 1 file changed, 28 insertions(+), 33 deletions(-) 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) => ( -
setMoveSource(!moveSource) : () => setMoveBrew(!moveBrew)} - > - -
- ))} -
- +
setMoveSource(!moveSource)} > + +
+
setMoveBrew(!moveBrew)} > + +
+
+
); - const renderDivider = ()=>( -
- {showDividerButtons && moveArrows} + const renderDivider = ( +
+ {showDividerButtons && renderMoveArrows}
@@ -100,19 +95,19 @@ const SplitPane = (props)=>{ {props.children[0]} - {renderDivider()} + {renderDivider} {props.children[1]}
); }; -const Pane = ({ width, children, isDragging, className, moveBrew, moveSource, liveScroll, setMoveArrows })=>{ +const Pane = ({ width, children, isDragging, moveBrew, moveSource, liveScroll, setMoveArrows })=>{ const styles = width ? { flex: 'none', width: `${width}px` } - : { pointerEvents: isDragging ? 'none' : 'auto' }; + : { pointerEvents: isDragging ? 'none' : 'auto' }; //Disable mouse capture in the right pane; else dragging into the iframe drops the divider return ( -
+
{React.cloneElement(children, { moveBrew, moveSource, liveScroll, setMoveArrows })}
);