MCPcopy
hub / github.com/wavetermdev/waveterm / PreviewView

Function PreviewView

frontend/app/view/preview/preview.tsx:99–168  ·  view source on GitHub ↗
({
    blockRef,
    contentRef,
    model,
}: {
    blockId: string;
    blockRef: React.RefObject<HTMLDivElement>;
    contentRef: React.RefObject<HTMLDivElement>;
    model: PreviewModel;
})

Source from the content-addressed store, hash-verified

97};
98
99function PreviewView({
100 blockRef,
101 contentRef,
102 model,
103}: {
104 blockId: string;
105 blockRef: React.RefObject<HTMLDivElement>;
106 contentRef: React.RefObject<HTMLDivElement>;
107 model: PreviewModel;
108}) {
109 const env = useWaveEnv<PreviewEnv>();
110 const connStatus = useAtomValue(model.connStatus);
111 const [errorMsg, setErrorMsg] = useAtom(model.errorMsgAtom);
112 const connection = useAtomValue(model.connectionImmediate);
113 const fileInfo = useAtomValue(model.statFile);
114
115 useEffect(() => {
116 console.log("fileInfo or connection changed", fileInfo, connection);
117 if (!fileInfo) {
118 return;
119 }
120 setErrorMsg(null);
121 }, [connection, fileInfo]);
122
123 if (connStatus?.status != "connected") {
124 return null;
125 }
126 const handleSelect = (s: SuggestionType, queryStr: string): boolean => {
127 if (s == null) {
128 if (isBlank(queryStr)) {
129 globalStore.set(model.openFileModal, false);
130 return true;
131 }
132 model.handleOpenFile(queryStr);
133 return true;
134 }
135 model.handleOpenFile(s["file:path"]);
136 return true;
137 };
138 const handleTab = (s: SuggestionType, query: string): string => {
139 if (s["file:mimetype"] == "directory") {
140 return s["file:name"] + "/";
141 } else {
142 return s["file:name"];
143 }
144 };
145 const fetchSuggestionsFn = async (query, ctx) => {
146 return await fetchSuggestions(env, model, query, ctx);
147 };
148
149 return (
150 <>
151 <div key="fullpreview" className="flex flex-col w-full overflow-hidden scrollbar-hide-until-hover">
152 {errorMsg && <ErrorOverlay errorMsg={errorMsg} resetOverlay={() => setErrorMsg(null)} />}
153 <div ref={contentRef} className="flex-grow overflow-hidden">
154 <SpecializedView parentRef={contentRef} model={model} />
155 </div>
156 </div>

Callers

nothing calls this directly

Calls 2

useWaveEnvFunction · 0.90

Tested by

no test coverage detected