summaryrefslogtreecommitdiff
path: root/frontend/src/components/PluginView.tsx
blob: 78bb22c2a9a1c8565991436444aceba9080ed60c (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
import { ButtonItem, DialogButton, PanelSection, PanelSectionRow, Router } from 'decky-frontend-lib';
import { VFC } from 'react';
import { FaArrowLeft, FaStore } from 'react-icons/fa';

import { useDeckyState } from './DeckyState';

const PluginView: VFC = () => {
  const { plugins, activePlugin, setActivePlugin, closeActivePlugin } = useDeckyState();

  const onStoreClick = () => {
    Router.CloseSideMenus();
    Router.NavigateToExternalWeb('http://127.0.0.1:1337/browser/redirect');
  };

  if (activePlugin) {
    return (
      <div style={{ height: '100%' }}>
        <div style={{ position: 'absolute', top: '3px', left: '16px', zIndex: 20 }}>
          <DialogButton style={{ minWidth: 0, padding: '10px 12px' }} onClick={closeActivePlugin}>
            <FaArrowLeft style={{ display: 'block' }} />
          </DialogButton>
        </div>
        {activePlugin.content}
      </div>
    );
  }

  return (
    <PanelSection>
      <div style={{ position: 'absolute', top: '3px', right: '16px', zIndex: 20 }}>
        <DialogButton style={{ minWidth: 0, padding: '10px 12px' }} onClick={onStoreClick}>
          <FaStore style={{ display: 'block' }} />
        </DialogButton>
      </div>
      {plugins.map(({ name, icon }) => (
        <PanelSectionRow key={name}>
          <ButtonItem layout="below" onClick={() => setActivePlugin(name)}>
            <div style={{ display: 'flex', justifyContent: 'space-between' }}>
              <div>{icon}</div>
              <div>{name}</div>
            </div>
          </ButtonItem>
        </PanelSectionRow>
      ))}
    </PanelSection>
  );
};

export default PluginView;