summaryrefslogtreecommitdiff
path: root/frontend/src/components/settings/pages/testing/index.tsx
blob: a32ce80e57ca100668eb2aac333ba6f7a40b3d6e (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
import { DialogBody, DialogButton, DialogControlsSection, Focusable, Navigation } from 'decky-frontend-lib';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { FaDownload, FaInfo } from 'react-icons/fa';

import { callUpdaterMethod } from '../../../../updater';
import { setSetting } from '../../../../utils/settings';
import { UpdateBranch } from '../general/BranchSelect';

interface TestingVersion {
  id: number;
  name: string;
  link: string;
  head_sha: string;
}

export default function TestingVersionList() {
  const { t } = useTranslation();
  const [testingVersions, setTestingVersions] = useState<TestingVersion[]>([]);

  useEffect(() => {
    (async () => {
      setTestingVersions((await callUpdaterMethod('get_testing_versions')).result);
    })();
  }, []);

  if (testingVersions.length === 0) {
    return (
      <div>
        <p>No open PRs found</p>
      </div>
    );
  }

  return (
    <DialogBody>
      <DialogControlsSection>
        <ul style={{ listStyleType: 'none', padding: '0' }}>
          {testingVersions.map((version) => {
            return (
              <li style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', paddingBottom: '10px' }}>
                <span>
                  {version.name} <span style={{ opacity: '50%' }}>{'#' + version.id}</span>
                </span>
                <Focusable style={{ height: '40px', marginLeft: 'auto', display: 'flex' }}>
                  <DialogButton
                    style={{ height: '40px', minWidth: '60px', marginRight: '10px' }}
                    onClick={() => {
                      callUpdaterMethod('download_testing_version', { pr_id: version.id, sha_id: version.head_sha });
                      setSetting('branch', UpdateBranch.Testing);
                    }}
                  >
                    <div
                      style={{
                        display: 'flex',
                        minWidth: '150px',
                        justifyContent: 'space-between',
                        alignItems: 'center',
                      }}
                    >
                      {t('Testing.download')}
                      <FaDownload style={{ paddingLeft: '1rem' }} />
                    </div>
                  </DialogButton>
                  <DialogButton
                    style={{
                      height: '40px',
                      width: '40px',
                      padding: '10px 12px',
                      minWidth: '40px',
                      display: 'flex',
                      flexDirection: 'column',
                      justifyContent: 'center',
                    }}
                    onClick={() => Navigation.NavigateToExternalWeb(version.link)}
                  >
                    <FaInfo />
                  </DialogButton>
                </Focusable>
              </li>
            );
          })}
        </ul>
      </DialogControlsSection>
    </DialogBody>
  );
}