File size: 1,448 Bytes
84702bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ac847eb
84702bc
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { useState } from "preact/hooks";
import { signal } from "@preact/signals";
import { config } from "../state";
import { composeCode, highlightPython } from "../content/code";

export const codeModalOpen = signal<boolean>(false);

export function PyTorchCodeModal() {
  if (!codeModalOpen.value) return null;
  const cfg = config.value;
  const code = composeCode(cfg);
  const html = highlightPython(code);
  const [copied, setCopied] = useState(false);

  async function copy() {
    try {
      await navigator.clipboard.writeText(code);
      setCopied(true);
      setTimeout(() => setCopied(false), 1200);
    } catch {
      setCopied(false);
    }
  }

  return (
    <div class="modal-backdrop" onClick={() => (codeModalOpen.value = false)}>
      <div class="modal pytorch-modal" onClick={(e) => e.stopPropagation()}>
        <div class="modal-head">
          <div>
            <div class="meta">pytorch</div>
            <h3>Architecture in code</h3>
            <p class="short">Your configured architecture as a self-contained PyTorch script.</p>
          </div>
          <div class="modal-actions">
            <button class="ghost" onClick={copy}>{copied ? "copied" : "copy"}</button>
            <button class="close" onClick={() => (codeModalOpen.value = false)}>×</button>
          </div>
        </div>
        <pre class="code"><code dangerouslySetInnerHTML={{ __html: html }} /></pre>
      </div>
    </div>
  );
}