Skip to content
This repository was archived by the owner on Nov 11, 2025. It is now read-only.

Commit 73a1ddf

Browse files
committed
copy embed code on publish
1 parent 3da54d1 commit 73a1ddf

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

blocks/scrimba-block.tsx

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
import { tw } from "twind";
2-
import { FolderBlockProps } from "@githubnext/blocks";
2+
import { FileBlockProps, FolderBlockProps } from "@githubnext/blocks";
33
import { useCallback, useEffect, useRef, useState } from "react";
4-
import "./style.css";
5-
import { Button, Text, Link } from "@primer/react";
4+
import { Button, Flash } from "@primer/react";
65

7-
const isDev = import.meta?.url
6+
const isDev = import.meta?.url;
87
const SCRIMBA_BASE_URL = isDev
98
? "https://dev.scrimba.com:3000"
109
: "https://scrimba.com";
1110
const SCRIMBA_URL = `${SCRIMBA_BASE_URL}/new/htmlblocks`;
1211

13-
export default function (props: FolderBlockProps) {
12+
function copyToClipboard(text) {
13+
const textArea = document.createElement("textarea");
14+
textArea.value = text;
15+
document.body.appendChild(textArea);
16+
textArea.focus();
17+
textArea.select();
18+
try {
19+
document.execCommand("copy");
20+
} catch (err) {
21+
console.error("Unable to copy to clipboard", err);
22+
}
23+
document.body.removeChild(textArea);
24+
}
25+
26+
export default function (props: FolderBlockProps | FileBlockProps) {
1427
const { tree, context, onRequestGitHubData, files } = props;
1528
const [scrimMounted, setScrimMounted] = useState(false);
16-
const [scrimRecorded, setScrimRecorded] = useState("");
29+
const [scrimRecorded, setScrimRecorded] = useState(false);
30+
const [scrimEmbedCopied, setScrimEmbedCopied] = useState(false);
1731

1832
const frame = useRef(null);
1933

@@ -128,32 +142,35 @@ export default function (props: FolderBlockProps) {
128142
listenToRecorded();
129143
}
130144
}, [frame]);
131-
const publish = useCallback(() => {
145+
const embed = () => {
146+
copyToClipboard(
147+
`<iframe src="${url}" width="100%" height="700px"></iframe>`
148+
);
149+
setScrimEmbedCopied(true);
150+
};
151+
const publish = () => {
132152
sendData({ action: "publish" }, true);
133-
}, [sendData]);
153+
embed();
154+
};
134155

156+
const url = `${SCRIMBA_BASE_URL}/scrim/${scrimRecorded}`;
135157
return (
136158
<div className={tw(`w-full h-full`)} id="example-block-code-block">
137159
<div className={tw(`flex w-full h-full overflow-x-hidden flex-col`)}>
160+
{scrimEmbedCopied ? (
161+
<Flash variant="success">Scrim embed code copied to clipboard</Flash>
162+
) : null}
138163
<div className={tw(`flex ai-center jc-between flex-row`)}>
139164
{scrimMounted ? null : (
140165
<Button onClick={reload}>Not working? Reload</Button>
141166
)}
142167
<Button onClick={loadFiles}>Load all files</Button>
143168
</div>
144169
{scrimRecorded ? (
145-
<Text>
146-
<Button onClick={publish} className={tw("inline-block")}>
147-
Publish the scrim{" "}
148-
</Button>
149-
to make it available for everyone at{" "}
150-
<Link
151-
href={`${SCRIMBA_BASE_URL}/scrim/${scrimRecorded}`}
152-
>{`${SCRIMBA_BASE_URL}/scrim/${scrimRecorded}`}</Link>
153-
</Text>
170+
<Button onClick={publish}>Publish and copy embed</Button>
154171
) : null}
155172
<iframe
156-
allow="microphone;"
173+
allow="microphone;fullscreen;"
157174
ref={frame}
158175
src={SCRIMBA_URL}
159176
className={tw`my-2 h-full w-full`}

0 commit comments

Comments
 (0)