MCPcopy Create free account
hub / github.com/PageAI-Pro/page-ui / BrickCodeEditor

Function BrickCodeEditor

components/bricks/brick-code-editor.tsx:16–144  ·  view source on GitHub ↗
({
  brick,
  demo,
  className = '',
}: {
  brick: string;
  demo: string;
  className?: string;
})

Source from the content-addressed store, hash-verified

14 'https://raw.githubusercontent.com/Shipixen/landing-page-bricks/main/templates/landing-page-templates/template';
15
16export const BrickCodeEditor = ({
17 brick,
18 demo,
19 className = '',
20}: {
21 brick: string;
22 demo: string;
23 className?: string;
24}) => {
25 const [copied, setCopied] = useState(false);
26 const [failed, setFailed] = useState(false);
27 const [loading, setLoading] = useState(false);
28
29 const { formattedCodeString, errorString, getCode } = useCopyBrickCode({
30 brick,
31 demo,
32 });
33
34 const loadCode = useCallback(
35 async (signal?: AbortSignal) => {
36 if (copied) {
37 return false;
38 }
39
40 setFailed(false);
41 setLoading(true);
42
43 try {
44 const code = await getCode(signal);
45
46 if (!code) {
47 setFailed(true);
48 } else {
49 setCopied(true);
50 navigator.clipboard.writeText(code);
51 }
52 } catch (error) {
53 console.error(error);
54 setFailed(true);
55 } finally {
56 setLoading(false);
57 }
58
59 setTimeout(() => {
60 setCopied(false);
61 setFailed(false);
62 }, 2000);
63 },
64 [getCode, copied],
65 );
66
67 useEffect(() => {
68 const controller = new AbortController();
69 const signal = controller.signal;
70
71 const loadCodeAsync = async () => {
72 await loadCode(signal);
73 };

Callers

nothing calls this directly

Calls 3

useCopyBrickCodeFunction · 0.90
cnFunction · 0.90
loadCodeAsyncFunction · 0.85

Tested by

no test coverage detected