Skip to content

Commit

Permalink
fix: ensure vertical split section resizes correctly (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulyadav-57 authored Nov 19, 2024
1 parent 8fb0cec commit b30ed4b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/components/workspace/WorkSpace/WorkSpace.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
flex: 0 0 70px;
width: 70px;
}
.splitHorizontal {
.splitVertical {
display: flex;
flex-direction: row;
width: calc(100% - 70px);
Expand All @@ -16,7 +16,7 @@
background-color: var(--splitter-bg);
}
}
.splitVertical {
.splitHorizontal {
display: flex;
flex-direction: column;
height: 100%;
Expand Down
22 changes: 19 additions & 3 deletions src/components/workspace/WorkSpace/WorkSpace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as TonCrypto from '@ton/crypto';
import { Blockchain } from '@ton/sandbox';
import { Buffer } from 'buffer';
import { useRouter } from 'next/router';
import { FC, useEffect, useMemo, useState } from 'react';
import { FC, useEffect, useMemo, useRef, useState } from 'react';
import Split from 'react-split';
import { useEffectOnce } from 'react-use';
import BottomPanel from '../BottomPanel/BottomPanel';
Expand All @@ -32,6 +32,8 @@ import FileTree from '../tree/FileTree';
import ItemAction from '../tree/FileTree/ItemActions';
import s from './WorkSpace.module.scss';

type SplitInstance = Split & { split: Split.Instance };

const WorkSpace: FC = () => {
const { clearLog, createLog } = useLogActivity();

Expand All @@ -40,6 +42,7 @@ const WorkSpace: FC = () => {
const [isLoaded, setIsLoaded] = useState(false);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [contract, setContract] = useState<any>('');
const splitVerticalRef = useRef<SplitInstance | null>(null);

const { tab } = router.query;
const {
Expand Down Expand Up @@ -153,6 +156,17 @@ const WorkSpace: FC = () => {
window.TonCore = TonCore;
window.TonCrypto = TonCrypto;
window.Buffer = Buffer;

const handleResize = () => {
if (!splitVerticalRef.current) return;

splitVerticalRef.current.split.setSizes([5, 95]);
};

window.addEventListener('resize', handleResize);
return () => {
window.removeEventListener('resize', handleResize);
};
});

return (
Expand All @@ -172,8 +186,10 @@ const WorkSpace: FC = () => {
/>
</div>
<Split
className={s.splitHorizontal}
ref={splitVerticalRef}
className={s.splitVertical}
minSize={250}
expandToMin={true}
gutterSize={4}
sizes={[5, 95]}
onDragEnd={() => {
Expand Down Expand Up @@ -230,7 +246,7 @@ const WorkSpace: FC = () => {
{isLoaded && (
<>
<Split
className={s.splitVertical}
className={s.splitHorizontal}
minSize={50}
gutterSize={4}
sizes={[80, 20]}
Expand Down

0 comments on commit b30ed4b

Please sign in to comment.