mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
add a 'close block' button
This commit is contained in:
parent
8573a415c0
commit
91d7392c34
@ -13,12 +13,25 @@
|
|||||||
|
|
||||||
.block-header {
|
.block-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
background-color: var(--panel-bg-color);
|
background-color: var(--panel-bg-color);
|
||||||
|
|
||||||
|
.block-header-text {
|
||||||
|
padding-left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-button {
|
||||||
|
font-size: 12px;
|
||||||
|
padding-right: 5px;
|
||||||
|
&:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.block-content {
|
.block-content {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as jotai from "jotai";
|
import * as jotai from "jotai";
|
||||||
import { atoms, blockDataMap } from "@/store/global";
|
import { atoms, blockDataMap, removeBlockFromTab } from "@/store/global";
|
||||||
|
|
||||||
import { TerminalView } from "@/app/view/term";
|
import { TerminalView } from "@/app/view/term";
|
||||||
import { PreviewView } from "@/app/view/preview";
|
import { PreviewView } from "@/app/view/preview";
|
||||||
@ -11,9 +11,14 @@ import { CenteredLoadingDiv } from "@/element/quickelems";
|
|||||||
|
|
||||||
import "./block.less";
|
import "./block.less";
|
||||||
|
|
||||||
const Block = ({ blockId }: { blockId: string }) => {
|
const Block = ({ tabId, blockId }: { tabId: string; blockId: string }) => {
|
||||||
const blockRef = React.useRef<HTMLDivElement>(null);
|
const blockRef = React.useRef<HTMLDivElement>(null);
|
||||||
const [dims, setDims] = React.useState({ width: 0, height: 0 });
|
const [dims, setDims] = React.useState({ width: 0, height: 0 });
|
||||||
|
|
||||||
|
function handleClose() {
|
||||||
|
removeBlockFromTab(tabId, blockId);
|
||||||
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!blockRef.current) {
|
if (!blockRef.current) {
|
||||||
return;
|
return;
|
||||||
@ -36,9 +41,13 @@ const Block = ({ blockId }: { blockId: string }) => {
|
|||||||
return (
|
return (
|
||||||
<div className="block" ref={blockRef}>
|
<div className="block" ref={blockRef}>
|
||||||
<div key="header" className="block-header">
|
<div key="header" className="block-header">
|
||||||
<div className="text-fixed">
|
<div className="block-header-text text-fixed">
|
||||||
Block [{blockId.substring(0, 8)}] {dims.width}x{dims.height}
|
Block [{blockId.substring(0, 8)}] {dims.width}x{dims.height}
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex-spacer" />
|
||||||
|
<div className="close-button" onClick={() => handleClose()}>
|
||||||
|
<i className="fa fa-solid fa-xmark-large" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div key="content" className="block-content">
|
<div key="content" className="block-content">
|
||||||
<React.Suspense fallback={<CenteredLoadingDiv />}>{blockElem}</React.Suspense>
|
<React.Suspense fallback={<CenteredLoadingDiv />}>{blockElem}</React.Suspense>
|
||||||
|
@ -87,4 +87,14 @@ function useBlockAtom<T>(blockId: string, name: string, makeFn: () => jotai.Atom
|
|||||||
return atom as jotai.Atom<T>;
|
return atom as jotai.Atom<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { globalStore, atoms, getBlockSubject, addBlockIdToTab, blockDataMap, useBlockAtom };
|
function removeBlockFromTab(tabId: string, blockId: string) {
|
||||||
|
let tabArr = globalStore.get(atoms.tabsAtom);
|
||||||
|
const newTabArr = produce(tabArr, (draft) => {
|
||||||
|
const tab = draft.find((tab) => tab.tabid == tabId);
|
||||||
|
tab.blockIds = tab.blockIds.filter((id) => id !== blockId);
|
||||||
|
});
|
||||||
|
globalStore.set(atoms.tabsAtom, newTabArr);
|
||||||
|
removeBlock(blockId);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { globalStore, atoms, getBlockSubject, addBlockIdToTab, blockDataMap, useBlockAtom, removeBlockFromTab };
|
||||||
|
@ -19,7 +19,7 @@ const TabContent = ({ tabId }: { tabId: string }) => {
|
|||||||
{tabData.blockIds.map((blockId: string) => {
|
{tabData.blockIds.map((blockId: string) => {
|
||||||
return (
|
return (
|
||||||
<div key={blockId} className="block-container">
|
<div key={blockId} className="block-container">
|
||||||
<Block blockId={blockId} />
|
<Block tabId={tabId} blockId={blockId} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
@ -102,7 +102,7 @@ function Workspace() {
|
|||||||
<div className="workspace">
|
<div className="workspace">
|
||||||
<TabBar />
|
<TabBar />
|
||||||
<div className="workspace-tabcontent">
|
<div className="workspace-tabcontent">
|
||||||
<TabContent tabId={activeTabId} />
|
<TabContent key={activeTabId} tabId={activeTabId} />
|
||||||
<Widgets />
|
<Widgets />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user