aboutsummaryrefslogtreecommitdiffstats
path: root/src/containers/settings/SettingsWindow.tsx
blob: 2192a6f69b3d367ed5c186ca4f0973ea32f0bf3d (plain) (blame)
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
import { Component, ReactNode, ReactPortal } from 'react';
import ReactDOM from 'react-dom';
import { observer, inject } from 'mobx-react';

import { StoresProps } from '../../@types/ferdium-components.types';
import Layout from '../../components/settings/SettingsLayout';
import Navigation from '../../components/settings/navigation/SettingsNavigation';
import ErrorBoundary from '../../components/util/ErrorBoundary';
import { workspaceStore } from '../../features/workspaces';

interface SettingsContainerProps extends StoresProps {
  children: ReactNode;
}

class SettingsContainer extends Component<SettingsContainerProps> {
  portalRoot: any;

  el: HTMLDivElement;

  constructor(props: SettingsContainerProps) {
    super(props);

    this.portalRoot = document.querySelector('#portalContainer');
    this.el = document.createElement('div');
  }

  componentDidMount(): void {
    this.portalRoot.append(this.el);
  }

  componentWillUnmount(): void {
    this.el.remove();
  }

  render(): ReactPortal {
    const { children, stores } = this.props;
    const { closeSettings } = this.props.actions.ui;

    const navigation = (
      <Navigation
        serviceCount={stores.services.all.length}
        workspaceCount={workspaceStore.workspaces.length}
      />
    );

    return ReactDOM.createPortal(
      <ErrorBoundary>
        <Layout navigation={navigation} closeSettings={closeSettings}>
          {children}
        </Layout>
      </ErrorBoundary>,
      this.el,
    );
  }
}

export default inject('stores', 'actions')(observer(SettingsContainer));