MCPcopy Create free account
hub / github.com/cosscom/coss / loadCode

Function loadCode

apps/origin/components/component-details.tsx:46–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44 };
45
46 const loadCode = async () => {
47 try {
48 const response = await fetch(`/origin/r/${component.name}.json`);
49 if (!response.ok) {
50 handleEmptyCode();
51 return;
52 }
53
54 const contentType = response.headers.get("content-type");
55 if (!contentType || !contentType.includes("application/json")) {
56 handleEmptyCode();
57 return;
58 }
59
60 const data = await response.json();
61 const codeContent = convertRegistryPaths(data.files[0].content) || "";
62 setCode(codeContent);
63
64 // Pre-highlight the code
65 const highlighted = await highlight(codeContent, "tsx");
66 setHighlightedCode(highlighted);
67 } catch (error) {
68 console.error("Failed to load code:", error);
69 handleEmptyCode();
70 }
71 };
72
73 loadCode();
74 }, [component.name]);

Callers 1

ComponentDetailsFunction · 0.85

Calls 3

convertRegistryPathsFunction · 0.90
highlightFunction · 0.90
handleEmptyCodeFunction · 0.85

Tested by

no test coverage detected