summaryrefslogtreecommitdiff
path: root/frontend/src/components/logviewer/LogViewModal.tsx
blob: 111717f6fa2e38e3067bcf03b076ae8425e760bc (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
import { ConfirmModal, Focusable, showModal } from "decky-frontend-lib";
import { VFC, useEffect, useState } from "react";
import { ScrollableWindowRelative } from "./ScrollableWindow";
import { t } from "i18next";

interface LogFileProps {
  plugin: string;
  name: string;
  closeModal?: () => void;
}

const uploadConfirmation = (name: string, plugin: string) => {
  const confirmModal = <ConfirmModal onOK={() => {
    window.DeckyPluginLoader.callServerMethod("upload_log", { plugin_name: plugin, log_name: name }).then((res) => {
      console.log(res)
      showModal(<ConfirmModal><h2>{res.result}</h2></ConfirmModal>)
    })
  }} strTitle={t("LogViewer.uploadConfirm")}>{t("LogViewer.uploadDisclaimer")}</ConfirmModal>
  showModal(confirmModal);
}

const LogViewModal: VFC<LogFileProps> = ({ name, plugin, closeModal }) => {
  const [logText, setLogText] = useState("");
  useEffect(() => {
    window.DeckyPluginLoader.callServerMethod("get_plugin_log_text", {
      plugin_name: plugin,
      log_name: name,
    }).then((text) => {
      setLogText(text.result || t("LogViewer.textError"));
    });
  }, []);

  return (
    <Focusable
      style={{
        padding: "0 15px",
        display: "flex",
        position: "absolute",
        top: "var(--basicui-header-height)",
        bottom: "var(--gamepadui-current-footer-height)",
        left: 0,
        right: 0,
      }}
      onSecondaryActionDescription={t("LogViewer.uploadLog")}
      onSecondaryButton={() => uploadConfirmation(name, plugin)}
    >
      <ScrollableWindowRelative alwaysFocus={true} onCancel={closeModal}>
        <div style={{ whiteSpace: "pre-wrap", padding: "12px 0" }}>
          {logText}
        </div>
      </ScrollableWindowRelative>
    </Focusable>
  );
};

export default LogViewModal;