aboutsummaryrefslogtreecommitdiffstats
path: root/src/containers/auth/AuthReleaseNotesScreen.tsx
blob: c9d2286e19819c5cdcbb3a879e0ab13e06e80925 (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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { Component } from 'react';
import { inject, observer } from 'mobx-react';

import { IntlShape, defineMessages, injectIntl } from 'react-intl';
import Markdown from 'markdown-to-jsx';
import { mdiArrowLeftCircle } from '@mdi/js';
import { openExternalUrl } from '../../helpers/url-helpers';
import Icon from '../../components/ui/icon';
import { ferdiumVersion } from '../../environment-remote';
import {
  getFerdiumVersion,
  getUpdateInfoFromGH,
} from '../../helpers/update-helpers';

const messages = defineMessages({
  headline: {
    id: 'settings.releasenotes.headline',
    defaultMessage: 'Release Notes',
  },
});

interface IProps {
  intl: IntlShape;
}

interface IState {
  data: string;
}

class AuthReleaseNotesScreen extends Component<IProps, IState> {
  constructor(props) {
    super(props);

    this.state = { data: '' };
  }

  async componentDidMount() {
    const { intl } = this.props;

    const data = await getUpdateInfoFromGH(
      window.location.href,
      ferdiumVersion,
      intl,
    );

    this.setState({
      data,
    });

    for (const link of document.querySelectorAll('.releasenotes__body a')) {
      link.addEventListener('click', this.handleClick.bind(this), false);
    }
  }

  handleClick(e) {
    e.preventDefault();
    openExternalUrl(e.target.href);
  }

  componentWillUnmount() {
    document.removeEventListener(
      'click',
      // eslint-disable-next-line unicorn/no-invalid-remove-event-listener
      this.handleClick.bind(this),
      false,
    );
  }

  render() {
    const { intl } = this.props;

    const { data } = this.state;
    return (
      <div className="auth__container auth__container--releasenotes">
        <div className="auth__main--releasenotes">
          <div className="auth__header">
            <span className="auth__header-item">
              Ferdium {getFerdiumVersion(window.location.href, ferdiumVersion)}{' '}
              {' | '}
            </span>
            <span className="auth__header-item__secondary">
              {intl.formatMessage(messages.headline)}
            </span>
          </div>
          <div className="auth__body releasenotes__body">
            <Markdown options={{ wrapper: 'article' }}>{data}</Markdown>
          </div>
          <div className="auth__help">
            <button
              type="button"
              onClick={() => {
                // For some reason <Link> doesn't work here. So we hard code the path to take us to the Welcome Screen
                window.location.href = '#/auth/welcome';
              }}
            >
              <Icon icon={mdiArrowLeftCircle} size={1.5} />
            </button>
          </div>
        </div>
      </div>
    );
  }
}

export default injectIntl<'intl', IProps>(
  inject('stores', 'actions')(observer(AuthReleaseNotesScreen)),
);