summaryrefslogtreecommitdiff
path: root/src/components/NerdStuffModal.tsx
blob: f075ccb445caed27046e53f6700f7a9244620e11 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { useState, useEffect } from "react";
import { 
  ModalRoot, 
  Field,
  Focusable,
  DialogControlsSection,
  PanelSectionRow,
  ButtonItem
} from "@decky/ui";
import {
  getConfigFileContent,
  getLaunchScriptContent,
  FileContentResult,
} from "../api/lsfgApi";
import t from '../i18n/i18n';

interface NerdStuffModalProps {
  closeModal?: () => void;
}

export function NerdStuffModal({ closeModal }: NerdStuffModalProps) {
  const [configContent, setConfigContent] = useState<FileContentResult | null>(null);
  const [scriptContent, setScriptContent] = useState<FileContentResult | null>(null);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState<string | null>(null);

  useEffect(() => {
    const loadData = async () => {
      try {
        setLoading(true);
        setError(null);
        
        // Load all data in parallel
        const [configResult, scriptResult] = await Promise.all([
          getConfigFileContent(),
          getLaunchScriptContent(),
        ]);
        
        setConfigContent(configResult);
        setScriptContent(scriptResult);
      } catch (err) {
        setError(err instanceof Error ? err.message : "Failed to load data");
      } finally {
        setLoading(false);
      }
    };

    loadData();
  }, []);

  const copyToClipboard = async (text: string) => {
    try {
      await navigator.clipboard.writeText(text);
      // Could add a toast notification here if desired
    } catch (err) {
      console.error("Failed to copy to clipboard:", err);
    }
  };

  return (
    <ModalRoot onCancel={closeModal} onOK={closeModal}>
      {loading && (
        <div>{t('NERD_LOADING', 'Loading information...')}</div>
      )}
      
      {error && (
        <div>Error: {error}</div>
      )}
      
      {!loading && !error && (
        <>
          {/* Launch Script Section */}
          {scriptContent && (
            <Field label={t('NERD_LAUNCH_SCRIPT', 'Launch Script')}>
              {!scriptContent.success ? (
                <div>{t('NERD_SCRIPT_NOT_FOUND_PREFIX', 'Script not found:')} {scriptContent.error}</div>
              ) : (
                <div>
                  <div style={{ marginBottom: "8px", fontSize: "0.9em", opacity: 0.8 }}>
                    {t('NERD_PATH_PREFIX', 'Path:')} {scriptContent.path}
                  </div>
                  <Focusable
                    onClick={() => scriptContent.content && copyToClipboard(scriptContent.content)}
                    onActivate={() => scriptContent.content && copyToClipboard(scriptContent.content)}
                  >
                    <pre style={{ 
                      background: "rgba(255, 255, 255, 0.1)", 
                      padding: "8px", 
                      borderRadius: "4px", 
                      fontSize: "0.8em",
                      whiteSpace: "pre-wrap",
                      overflow: "auto",
                      maxHeight: "150px"
                    }}>
                      {scriptContent.content || t('NERD_NO_CONTENT', 'No content')}
                    </pre>
                  </Focusable>
                </div>
              )}
            </Field>
          )}

          {/* Config File Section */}
          {configContent && (
            <Field label={t('NERD_CONFIG_FILE', 'Configuration File')}>
              {!configContent.success ? (
                <div>{t('NERD_CONFIG_NOT_FOUND_PREFIX', 'Config not found:')} {configContent.error}</div>
              ) : (
                <div>
                  <div style={{ marginBottom: "8px", fontSize: "0.9em", opacity: 0.8 }}>
                    {t('NERD_PATH_PREFIX', 'Path:')} {configContent.path}
                  </div>
                  <Focusable
                    onClick={() => configContent.content && copyToClipboard(configContent.content)}
                    onActivate={() => configContent.content && copyToClipboard(configContent.content)}
                  >
                    <pre style={{ 
                      background: "rgba(255, 255, 255, 0.1)", 
                      padding: "8px", 
                      borderRadius: "4px", 
                      fontSize: "0.8em",
                      whiteSpace: "pre-wrap",
                      overflow: "auto"
                    }}>
                      {configContent.content || t('NERD_NO_CONTENT', 'No content')}
                    </pre>
                  </Focusable>
                </div>
              )}
            </Field>
          )}

          {/* Close Button */}
          <DialogControlsSection>
            <PanelSectionRow>
              <ButtonItem
                layout="below"
                onClick={closeModal}
              >
                {t('NERD_CLOSE', 'Close')}
              </ButtonItem>
            </PanelSectionRow>
          </DialogControlsSection>
        </>
      )}
    </ModalRoot>
  );
}