default block icon/title/name in the same way. use blockName atom from viewmodel

This commit is contained in:
sawka 2024-07-25 18:05:32 -07:00
parent 875fbb87c4
commit 127b2bb9bf
2 changed files with 15 additions and 29 deletions

View File

@ -257,7 +257,8 @@ const BlockFrame_Default_Component = ({
});
});
let isFocused = jotai.useAtomValue(isFocusedAtom);
const viewIconUnion = util.useAtomValueSafe(viewModel.viewIcon) ?? "square";
const viewIconUnion = util.useAtomValueSafe(viewModel.viewIcon) ?? blockViewToIcon(blockData?.view);
const viewName = util.useAtomValueSafe(viewModel.viewName) ?? blockViewToName(blockData?.view);
const headerTextUnion = util.useAtomValueSafe(viewModel.viewText);
const preIconButton = util.useAtomValueSafe(viewModel.preIconButton);
const endIconButtons = util.useAtomValueSafe(viewModel.endIconButtons);
@ -398,7 +399,7 @@ const BlockFrame_Default_Component = ({
{preIconButtonElem}
<div className="block-frame-default-header-iconview">
{viewIconElem}
<div className="block-frame-view-type">{blockViewToName(blockData?.view)}</div>
<div className="block-frame-view-type">{viewName}</div>
{settingsConfig?.blockheader?.showblockids && (
<div className="block-frame-blockid">[{blockId.substring(0, 8)}]</div>
)}
@ -440,7 +441,7 @@ function blockViewToIcon(view: string): string {
if (view == "waveai") {
return "sparkles";
}
return null;
return "square";
}
function blockViewToName(view: string): string {
@ -459,31 +460,6 @@ function blockViewToName(view: string): string {
return view;
}
function useBlockIcon(blockId: string): string {
const blockIconOverrideAtom = useBlockAtom<string>(blockId, "blockicon:override", () => {
return jotai.atom<string>(null);
});
const blockIconAtom = useBlockAtom<string>(blockId, "blockicon", () => {
return jotai.atom((get) => {
console.log("atom-blockicon", blockId);
const blockAtom = WOS.getWaveObjectAtom<Block>(WOS.makeORef("block", blockId));
const blockData = get(blockAtom);
const metaIcon = blockData?.meta?.icon;
if (!util.isBlank(metaIcon)) {
console.log("atom-blockicon-meta", metaIcon);
return metaIcon;
}
const overrideVal = get(blockIconOverrideAtom);
if (overrideVal != null) {
return overrideVal;
}
return blockViewToIcon(blockData?.view);
});
});
const blockIcon = jotai.useAtomValue(blockIconAtom);
return blockIcon;
}
function getViewElemAndModel(
blockId: string,
blockView: string,

View File

@ -129,6 +129,7 @@ class TermViewModel {
blockId: string;
viewIcon: jotai.Atom<string>;
viewText: jotai.Atom<string>;
viewName: jotai.Atom<string>;
constructor(blockId: string) {
this.blockId = blockId;
@ -137,7 +138,16 @@ class TermViewModel {
const blockData = get(this.blockAtom);
return blockData?.meta?.["term:mode"] ?? "term";
});
this.viewIcon = jotai.atom("terminal");
this.viewIcon = jotai.atom((get) => {
return "terminal";
});
this.viewName = jotai.atom((get) => {
const blockData = get(this.blockAtom);
if (blockData.controller == "cmd") {
return "Command";
}
return "Terminal";
});
this.viewText = jotai.atom((get) => {
const blockData = get(this.blockAtom);
return blockData?.meta?.title ?? "";