From d1c623f4c3d72c859f9ad9cb985be127d6a3eb62 Mon Sep 17 00:00:00 2001
From: André Oliveira <37463445+SpecialAro@users.noreply.github.com>
Date: Sat, 2 Sep 2023 16:28:04 +0100
Subject: feat: Add Download Manager (pause, stop, delete) (#1339)

---
 .../downloadManager/DownloadManagerLayout.tsx      | 81 ++++++++++++++++++++++
 1 file changed, 81 insertions(+)
 create mode 100644 src/components/downloadManager/DownloadManagerLayout.tsx

(limited to 'src/components/downloadManager/DownloadManagerLayout.tsx')

diff --git a/src/components/downloadManager/DownloadManagerLayout.tsx b/src/components/downloadManager/DownloadManagerLayout.tsx
new file mode 100644
index 000000000..1e018cfb8
--- /dev/null
+++ b/src/components/downloadManager/DownloadManagerLayout.tsx
@@ -0,0 +1,81 @@
+import React, { Component } from 'react';
+import { inject, observer } from 'mobx-react';
+import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl';
+
+import { mdiClose } from '@mdi/js';
+import { Outlet } from 'react-router-dom';
+import { Actions } from '../../actions/lib/actions';
+import { isEscKeyPress } from '../../jsUtils';
+import Appear from '../ui/effects/Appear';
+import ErrorBoundary from '../util/ErrorBoundary';
+import Icon from '../ui/icon';
+
+const messages = defineMessages({
+  closeSettings: {
+    id: 'settings.app.closeSettings',
+    defaultMessage: 'Close settings',
+  },
+});
+
+interface IProps extends WrappedComponentProps {
+  actions?: Actions;
+  // eslint-disable-next-line react/no-unused-prop-types
+  children?: React.ReactNode;
+}
+
+@inject('stores', 'actions')
+@observer
+class DownloadManagerLayout extends Component<IProps> {
+  componentDidMount() {
+    document.addEventListener('keydown', this.handleKeyDown.bind(this), false);
+  }
+
+  componentWillUnmount() {
+    document.removeEventListener(
+      'keydown',
+      // eslint-disable-next-line unicorn/no-invalid-remove-event-listener
+      this.handleKeyDown.bind(this),
+      false,
+    );
+  }
+
+  handleKeyDown(e) {
+    if (isEscKeyPress(e.keyCode)) {
+      this.props.actions!.ui.closeSettings();
+    }
+  }
+
+  render() {
+    const { closeSettings } = this.props.actions!.ui;
+
+    const { intl } = this.props;
+
+    return (
+      <Appear transitionName="fadeIn-fast">
+        <div className="settings-wrapper">
+          <ErrorBoundary>
+            <button
+              type="button"
+              className="settings-wrapper__action"
+              onClick={closeSettings}
+              aria-label={intl.formatMessage(messages.closeSettings)}
+            />
+            <div className="settings franz-form">
+              <Outlet />
+              <button
+                type="button"
+                className="settings__close"
+                onClick={closeSettings}
+                aria-label={intl.formatMessage(messages.closeSettings)}
+              >
+                <Icon icon={mdiClose} size={1.35} />
+              </button>
+            </div>
+          </ErrorBoundary>
+        </div>
+      </Appear>
+    );
+  }
+}
+
+export default injectIntl<'intl', IProps>(DownloadManagerLayout);
-- 
cgit v1.2.3-70-g09d2

