-
-
Notifications
You must be signed in to change notification settings - Fork 927
big simplifications to the preview mocks for rendering blocks #3082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
cef3b82
bf1686f
cb47654
4d357fd
9b7af02
b94538e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright 2026, Command Line Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { globalStore } from "@/app/store/jotaiStore"; | ||
| import type { NodeModel } from "@/layout/index"; | ||
| import { atom } from "jotai"; | ||
|
|
||
| export type MockNodeModelOpts = { | ||
| nodeId: string; | ||
| blockId: string; | ||
| innerRect?: { width: string; height: string }; | ||
| numLeafs?: number; | ||
| }; | ||
|
|
||
| export function makeMockNodeModel(opts: MockNodeModelOpts): NodeModel { | ||
| const isFocusedAtom = atom(true); | ||
| const isMagnifiedAtom = atom(false); | ||
|
|
||
| return { | ||
| additionalProps: atom({} as any), | ||
| innerRect: atom(opts.innerRect ?? { width: "1000px", height: "640px" }), | ||
| blockNum: atom(1), | ||
| numLeafs: atom(opts.numLeafs ?? 1), | ||
| nodeId: opts.nodeId, | ||
| blockId: opts.blockId, | ||
| addEphemeralNodeToLayout: () => {}, | ||
| animationTimeS: atom(0), | ||
| isResizing: atom(false), | ||
| isFocused: isFocusedAtom, | ||
| isMagnified: isMagnifiedAtom, | ||
| anyMagnified: atom(false), | ||
| isEphemeral: atom(false), | ||
| ready: atom(true), | ||
| disablePointerEvents: atom(false), | ||
| toggleMagnify: () => { | ||
| globalStore.set(isMagnifiedAtom, !globalStore.get(isMagnifiedAtom)); | ||
| }, | ||
| focusNode: () => { | ||
| globalStore.set(isFocusedAtom, true); | ||
| }, | ||
| onClose: () => {}, | ||
| dragHandleRef: { current: null }, | ||
| displayContainerRef: { current: null }, | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,11 +2,9 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Block } from "@/app/block/block"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { globalStore } from "@/app/store/jotaiStore"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useWaveEnv } from "@/app/waveenv/waveenv"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { NodeModel } from "@/layout/index"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { atom } from "jotai"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import * as React from "react"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { makeMockNodeModel } from "../mock/mock-node-model"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useRpcOverride } from "../mock/use-rpc-override"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DefaultAiFileDiffChatId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -17,38 +15,6 @@ import { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const PreviewNodeId = "preview-aifilediff-node"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function makePreviewNodeModel(blockId: string): NodeModel { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const isFocusedAtom = atom(true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const isMagnifiedAtom = atom(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| additionalProps: atom({} as any), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| innerRect: atom({ width: "1000px", height: "640px" }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| blockNum: atom(1), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| numLeafs: atom(1), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nodeId: PreviewNodeId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| blockId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| addEphemeralNodeToLayout: () => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| animationTimeS: atom(0), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isResizing: atom(false), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isFocused: isFocusedAtom, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isMagnified: isMagnifiedAtom, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| anyMagnified: atom(false), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isEphemeral: atom(false), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ready: atom(true), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| disablePointerEvents: atom(false), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toggleMagnify: () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| globalStore.set(isMagnifiedAtom, !globalStore.get(isMagnifiedAtom)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| focusNode: () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| globalStore.set(isFocusedAtom, true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClose: () => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dragHandleRef: { current: null }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| displayContainerRef: { current: null }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function AiFileDiffPreview() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const env = useWaveEnv(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [blockId, setBlockId] = React.useState<string>(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -75,7 +41,10 @@ export function AiFileDiffPreview() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ).then((id) => setBlockId(id)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, []); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+29
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing error handling for If 🛡️ Add error handling React.useEffect(() => {
env.createBlock(
{
meta: {
view: "aifilediff",
file: DefaultAiFileDiffFileName,
"aifilediff:chatid": DefaultAiFileDiffChatId,
"aifilediff:toolcallid": DefaultAiFileDiffToolCallId,
},
},
false,
false
- ).then((id) => setBlockId(id));
+ ).then((id) => setBlockId(id))
+ .catch((err) => console.error("[AiFileDiffPreview] createBlock failed:", err));
}, []);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const nodeModel = React.useMemo(() => (blockId != null ? makePreviewNodeModel(blockId) : null), [blockId]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const nodeModel = React.useMemo( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| () => (blockId != null ? makeMockNodeModel({ nodeId: PreviewNodeId, blockId }) : null), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [blockId] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (blockId == null || nodeModel == null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.