aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/layout/AppLayout.js
blob: fa83842a4297a0470a1c7d2f7849fb9bed56c791 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { observer, PropTypes as MobxPropTypes } from 'mobx-react';
import { defineMessages, intlShape } from 'react-intl';
import { TitleBar } from 'electron-react-titlebar';
import injectSheet from 'react-jss';

import InfoBar from '../ui/InfoBar';
import { Component as DelayApp } from '../../features/delayApp';
import { Component as BasicAuth } from '../../features/basicAuth';
import { Component as ShareFranz } from '../../features/shareFranz';
import ErrorBoundary from '../util/ErrorBoundary';

// import globalMessages from '../../i18n/globalMessages';

import { isWindows } from '../../environment';
import AnnouncementScreen from '../../features/announcements/components/AnnouncementScreen';
import WorkspaceSwitchingIndicator from '../../features/workspaces/components/WorkspaceSwitchingIndicator';
import { workspaceStore } from '../../features/workspaces';
import { announcementActions } from '../../features/announcements/actions';

function createMarkup(HTMLString) {
  return { __html: HTMLString };
}

const messages = defineMessages({
  servicesUpdated: {
    id: 'infobar.servicesUpdated',
    defaultMessage: '!!!Your services have been updated.',
  },
  updateAvailable: {
    id: 'infobar.updateAvailable',
    defaultMessage: '!!!A new update for Franz is available.',
  },
  buttonReloadServices: {
    id: 'infobar.buttonReloadServices',
    defaultMessage: '!!!Reload services',
  },
  changelog: {
    id: 'infobar.buttonChangelog',
    defaultMessage: '!!!Changelog',
  },
  buttonInstallUpdate: {
    id: 'infobar.buttonInstallUpdate',
    defaultMessage: '!!!Restart & install update',
  },
  requiredRequestsFailed: {
    id: 'infobar.requiredRequestsFailed',
    defaultMessage: '!!!Could not load services and user information',
  },
});

const styles = theme => ({
  appContent: {
    width: `calc(100% + ${theme.workspaces.drawer.width}px)`,
    transition: 'transform 0.5s ease',
    transform() {
      return workspaceStore.isWorkspaceDrawerOpen ? 'translateX(0)' : `translateX(-${theme.workspaces.drawer.width}px)`;
    },
  },
});

@injectSheet(styles) @observer
class AppLayout extends Component {
  static propTypes = {
    classes: PropTypes.object.isRequired,
    isFullScreen: PropTypes.bool.isRequired,
    sidebar: PropTypes.element.isRequired,
    workspacesDrawer: PropTypes.element.isRequired,
    services: PropTypes.element.isRequired,
    children: PropTypes.element,
    news: MobxPropTypes.arrayOrObservableArray.isRequired,
    // isOnline: PropTypes.bool.isRequired,
    showServicesUpdatedInfoBar: PropTypes.bool.isRequired,
    appUpdateIsDownloaded: PropTypes.bool.isRequired,
    nextAppReleaseVersion: PropTypes.string,
    removeNewsItem: PropTypes.func.isRequired,
    reloadServicesAfterUpdate: PropTypes.func.isRequired,
    installAppUpdate: PropTypes.func.isRequired,
    showRequiredRequestsError: PropTypes.bool.isRequired,
    areRequiredRequestsSuccessful: PropTypes.bool.isRequired,
    retryRequiredRequests: PropTypes.func.isRequired,
    areRequiredRequestsLoading: PropTypes.bool.isRequired,
    darkMode: PropTypes.bool.isRequired,
    isDelayAppScreenVisible: PropTypes.bool.isRequired,
  };

  static defaultProps = {
    children: [],
    nextAppReleaseVersion: null,
  };

  static contextTypes = {
    intl: intlShape,
  };

  render() {
    const {
      classes,
      isFullScreen,
      workspacesDrawer,
      sidebar,
      services,
      children,
      // isOnline,
      news,
      showServicesUpdatedInfoBar,
      appUpdateIsDownloaded,
      nextAppReleaseVersion,
      removeNewsItem,
      reloadServicesAfterUpdate,
      installAppUpdate,
      showRequiredRequestsError,
      areRequiredRequestsSuccessful,
      retryRequiredRequests,
      areRequiredRequestsLoading,
      darkMode,
      isDelayAppScreenVisible,
    } = this.props;

    const { intl } = this.context;

    return (
      <ErrorBoundary>
        <div className={(darkMode ? 'theme__dark' : '')}>
          <div className="app">
            {isWindows && !isFullScreen && <TitleBar menu={window.franz.menu.template} icon="assets/images/logo.svg" />}
            <div className={`app__content ${classes.appContent}`}>
              {workspacesDrawer}
              {sidebar}
              <div className="app__service">
                <WorkspaceSwitchingIndicator />
                {news.length > 0 && news.map(item => (
                  <InfoBar
                    key={item.id}
                    position="top"
                    type={item.type}
                    sticky={item.sticky}
                    onHide={() => removeNewsItem({ newsId: item.id })}
                  >
                    <span dangerouslySetInnerHTML={createMarkup(item.message)} />
                  </InfoBar>
                ))}
                {/* {!isOnline && (
                  <InfoBar
                    type="danger"
                    sticky
                  >
                    <span className="mdi mdi-flash" />
                    {intl.formatMessage(globalMessages.notConnectedToTheInternet)}
                  </InfoBar>
                )} */}
                {!areRequiredRequestsSuccessful && showRequiredRequestsError && (
                  <InfoBar
                    type="danger"
                    ctaLabel="Try again"
                    ctaLoading={areRequiredRequestsLoading}
                    sticky
                    onClick={retryRequiredRequests}
                  >
                    <span className="mdi mdi-flash" />
                    {intl.formatMessage(messages.requiredRequestsFailed)}
                  </InfoBar>
                )}
                {showServicesUpdatedInfoBar && (
                  <InfoBar
                    type="primary"
                    ctaLabel={intl.formatMessage(messages.buttonReloadServices)}
                    onClick={reloadServicesAfterUpdate}
                    sticky
                  >
                    <span className="mdi mdi-power-plug" />
                    {intl.formatMessage(messages.servicesUpdated)}
                  </InfoBar>
                )}
                {appUpdateIsDownloaded && (
                  <InfoBar
                    type="primary"
                    ctaLabel={intl.formatMessage(messages.buttonInstallUpdate)}
                    onClick={installAppUpdate}
                    sticky
                  >
                    <span className="mdi mdi-information" />
                    {intl.formatMessage(messages.updateAvailable)}
                    {' '}
                    <button
                      className="info-bar__inline-button"
                      type="button"
                      onClick={() => announcementActions.show({ targetVersion: nextAppReleaseVersion })}
                    >
                      <u>{intl.formatMessage(messages.changelog)}</u>
                    </button>
                  </InfoBar>
                )}
                {isDelayAppScreenVisible && (<DelayApp />)}
                <BasicAuth />
                <ShareFranz />
                {services}
                {children}
              </div>
            </div>
          </div>
        </div>
      </ErrorBoundary>
    );
  }
}

export default AppLayout;