Skip to content

Commit

Permalink
fix: updated the layout logic for contract-viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
RutvikGhaskataEalf committed Oct 4, 2024
1 parent 180f633 commit 76b8668
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 39 deletions.
16 changes: 12 additions & 4 deletions app/workspace/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@ import Cli from "@/components/workspace/cli";
import Editor from "@/components/workspace/editor";
import FileExplorer from "@/components/file-explorer";
import ContractViewer from "@/components/contract-viewer";

import { Fragment } from "react";

export default function Page() {
return (
<ResizablePanelGroup direction="horizontal" className="border">
<ResizablePanel defaultSize={25} className="flex flex-col">
<BuildDeployPanel />
<FileExplorer />
<ContractViewer />
<TopBottom
top={
<Fragment>
<BuildDeployPanel />
<FileExplorer />
</Fragment>
}
bottom={<ContractViewer />}
topDefaultSize={30}
bottomDefaultSize={70}
/>
</ResizablePanel>
<ResizableHandle />
<ResizablePanel defaultSize={75}>
Expand Down
41 changes: 8 additions & 33 deletions components/contract-viewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,21 @@ const ContractViewer = () => {
const contractName = pathName.split("/")[2];

const wallet = useWallet();
const [treeHeight, setTreeHeight] = useState(0);

const aelfWallet =
wallet?.privateKey && AElf.wallet.getWalletByPrivateKey(wallet.privateKey);
const aelfWallet = wallet?.privateKey && AElf.wallet.getWalletByPrivateKey(wallet.privateKey);
const contractViewerAddress = searchParams.get("contract-viewer-address");

const setFileContainerHeight = () => {
const treeElement = document.querySelector(".file-tree");
if (treeElement) {
setTreeHeight(treeElement.clientHeight);
const resizeObserver = new ResizeObserver((entries) => {
setTreeHeight(treeElement.clientHeight);
});
resizeObserver.observe(treeElement);
return () => {
resizeObserver.disconnect();
};
}
};

useEffect(() => {
if (typeof document !== "undefined") {
setTimeout(() => setFileContainerHeight(), 500);
}
}, []);

if (!contractViewerAddress || !aelfWallet) {
return;
}

return (
<div style={{height: `calc(100% - ${treeHeight + 134}px)`}} className="border-t-2 mt-[20px]">
<ContractView
wallet={aelfWallet}
address={contractViewerAddress}
headerTitle={"Contract View"}
rpcUrl="https://explorer-test-side02.aelf.io/chain"
contractName={contractName}
/>
</div>
<ContractView
wallet={aelfWallet}
address={contractViewerAddress}
headerTitle={"Contract View"}
rpcUrl="https://explorer-test-side02.aelf.io/chain"
contractName={contractName}
/>
);
};

Expand Down
13 changes: 11 additions & 2 deletions components/top-bottom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@ import { ReactNode } from "react";
export default function TopBottom({
top,
bottom,
topDefaultSize = 70,
bottomDefaultSize = 30,
}: {
top: ReactNode;
bottom: ReactNode;
topDefaultSize?: number;
bottomDefaultSize?: number;
}) {
return (
<div className="h-[calc(100vh-40px)]">
<ResizablePanelGroup direction="vertical">
<ResizablePanel defaultSize={70} className="overflow-y-auto">
<ResizablePanel
defaultSize={topDefaultSize}
className="overflow-y-auto"
>
{top}
</ResizablePanel>
<ResizableHandle />
<ResizablePanel defaultSize={30}>{bottom}</ResizablePanel>
<ResizablePanel defaultSize={bottomDefaultSize}>
{bottom}
</ResizablePanel>
</ResizablePanelGroup>
</div>
);
Expand Down

0 comments on commit 76b8668

Please sign in to comment.