summaryrefslogtreecommitdiff
path: root/src/components/ClipboardButton.tsx
blob: cf11e6e5de4b77ac1d6c63b392abf8262001f246 (plain)
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
import { useState } from "react";
import { PanelSectionRow, ButtonItem } from "@decky/ui";
import { FaClipboard, FaCheck } from "react-icons/fa";
import { getLaunchOption } from "../api/lsfgApi";

export function ClipboardButton() {
  const [copied, setCopied] = useState(false);

  const handleClipboardClick = async () => {
    try {
      // Get the launch option from the backend
      const response = await getLaunchOption();
      const launchOption = response.launch_option;
      
      // Copy to clipboard
      await navigator.clipboard.writeText(launchOption);
      setCopied(true);
      
      // Reset the copied state after 2 seconds
      setTimeout(() => setCopied(false), 2000);
    } catch (error) {
      console.error("Failed to copy launch option:", error);
    }
  };

  return (
    <PanelSectionRow>
      <ButtonItem
        layout="below"
        onClick={handleClipboardClick}
        description="Copy the launch option needed for Steam games"
      >
        <div style={{ display: "flex", alignItems: "center", gap: "8px" }}>
          {copied ? <FaCheck style={{ color: "green" }} /> : <FaClipboard />}
          <div>{copied ? "Copied!" : "Copy Launch Option"}</div>
        </div>
      </ButtonItem>
    </PanelSectionRow>
  );
}