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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
import * as React from 'react';
import { colors, links } from '../../config.json';
import { hasExpired, formatRemainingTime } from '../../shared/account-expiry';
import { messages } from '../../shared/gettext';
import History from '../lib/history';
import { AriaDescribed, AriaDescription, AriaDescriptionGroup } from './AriaGroup';
import * as Cell from './cell';
import { Layout } from './Layout';
import {
CloseBarItem,
NavigationBar,
NavigationContainer,
NavigationItems,
TitleBarItem,
} from './NavigationBar';
import SettingsHeader, { HeaderTitle } from './SettingsHeader';
import {
StyledCellIcon,
StyledCellSpacer,
StyledContainer,
StyledContent,
StyledNavigationScrollbars,
StyledOutOfTimeSubText,
StyledQuitButton,
} from './SettingsStyles';
import { LoginState } from '../redux/account/reducers';
export interface IProps {
preferredLocaleDisplayName: string;
loginState: LoginState;
connectedToDaemon: boolean;
accountExpiry?: string;
appVersion: string;
consistentVersion: boolean;
upToDateVersion: boolean;
suggestedIsBeta: boolean;
isOffline: boolean;
onQuit: () => void;
onClose: () => void;
onViewSelectLanguage: () => void;
onViewAccount: () => void;
onViewSupport: () => void;
onViewPreferences: () => void;
onViewAdvancedSettings: () => void;
onExternalLink: (url: string) => void;
updateAccountData: () => void;
history: History;
}
export default class Settings extends React.Component<IProps> {
public componentDidMount() {
if (this.props.history.action === 'PUSH') {
this.props.updateAccountData();
}
}
public render() {
const showLargeTitle = this.props.loginState.type !== 'ok';
return (
<Layout>
<StyledContainer>
<NavigationContainer>
<NavigationBar alwaysDisplayBarTitle={!showLargeTitle}>
<NavigationItems>
<CloseBarItem action={this.props.onClose} />
<TitleBarItem>
{
// TRANSLATORS: Title label in navigation bar
messages.pgettext('navigation-bar', 'Settings')
}
</TitleBarItem>
</NavigationItems>
</NavigationBar>
<StyledNavigationScrollbars>
<StyledContent>
{showLargeTitle && (
<SettingsHeader>
<HeaderTitle>{messages.pgettext('navigation-bar', 'Settings')}</HeaderTitle>
</SettingsHeader>
)}
{this.renderTopButtons()}
{this.renderMiddleButtons()}
{this.renderBottomButtons()}
{this.renderQuitButton()}
</StyledContent>
</StyledNavigationScrollbars>
</NavigationContainer>
</StyledContainer>
</Layout>
);
}
private openDownloadLink = () =>
this.props.onExternalLink(this.props.suggestedIsBeta ? links.betaDownload : links.download);
private openFaqLink = () => this.props.onExternalLink(links.faq);
private renderQuitButton() {
return (
<StyledQuitButton onClick={this.props.onQuit}>
{messages.pgettext('settings-view', 'Quit app')}
</StyledQuitButton>
);
}
private renderTopButtons() {
const isLoggedIn = this.props.loginState.type === 'ok';
if (!isLoggedIn || !this.props.connectedToDaemon) {
return null;
}
const isOutOfTime = this.props.accountExpiry ? hasExpired(this.props.accountExpiry) : false;
const formattedExpiry = this.props.accountExpiry
? formatRemainingTime(this.props.accountExpiry).toUpperCase()
: '';
const outOfTimeMessage = messages.pgettext('settings-view', 'OUT OF TIME');
return (
<>
<Cell.CellButton onClick={this.props.onViewAccount}>
<Cell.Label>
{
// TRANSLATORS: Navigation button to the 'Account' view
messages.pgettext('settings-view', 'Account')
}
</Cell.Label>
<StyledOutOfTimeSubText isOutOfTime={isOutOfTime}>
{isOutOfTime ? outOfTimeMessage : formattedExpiry}
</StyledOutOfTimeSubText>
<Cell.Icon height={12} width={7} source="icon-chevron" />
</Cell.CellButton>
<Cell.CellButton onClick={this.props.onViewPreferences}>
<Cell.Label>
{
// TRANSLATORS: Navigation button to the 'Preferences' view
messages.pgettext('settings-view', 'Preferences')
}
</Cell.Label>
<Cell.Icon height={12} width={7} source="icon-chevron" />
</Cell.CellButton>
<Cell.CellButton onClick={this.props.onViewAdvancedSettings}>
<Cell.Label>
{
// TRANSLATORS: Navigation button to the 'Advanced' settings view
messages.pgettext('settings-view', 'Advanced')
}
</Cell.Label>
<Cell.Icon height={12} width={7} source="icon-chevron" />
</Cell.CellButton>
<StyledCellSpacer />
</>
);
}
private renderMiddleButtons() {
let icon;
let footer;
if (!this.props.consistentVersion || !this.props.upToDateVersion) {
const inconsistentVersionMessage = messages.pgettext(
'settings-view',
'App is out of sync. Please quit and restart.',
);
const updateAvailableMessage = messages.pgettext(
'settings-view',
'Update available. Install the latest app version to stay up to date.',
);
const message = !this.props.consistentVersion
? inconsistentVersionMessage
: updateAvailableMessage;
icon = <StyledCellIcon source="icon-alert" tintColor={colors.red} />;
footer = (
<Cell.Footer>
<Cell.FooterText>{message}</Cell.FooterText>
</Cell.Footer>
);
} else {
footer = <StyledCellSpacer />;
}
return (
<AriaDescriptionGroup>
<AriaDescribed>
<Cell.CellButton disabled={this.props.isOffline} onClick={this.openDownloadLink}>
{icon}
<Cell.Label>{messages.pgettext('settings-view', 'App version')}</Cell.Label>
<Cell.SubText>{this.props.appVersion}</Cell.SubText>
<AriaDescription>
<Cell.Icon
height={16}
width={16}
source="icon-extLink"
aria-label={messages.pgettext('accessibility', 'Opens externally')}
/>
</AriaDescription>
</Cell.CellButton>
</AriaDescribed>
{footer}
</AriaDescriptionGroup>
);
}
private renderBottomButtons() {
return (
<>
<Cell.CellButton onClick={this.props.onViewSupport}>
<Cell.Label>
{
// TRANSLATORS: Navigation button to the 'Report a problem' help view
messages.pgettext('settings-view', 'Report a problem')
}
</Cell.Label>
<Cell.Icon height={12} width={7} source="icon-chevron" />
</Cell.CellButton>
<AriaDescriptionGroup>
<AriaDescribed>
<Cell.CellButton disabled={this.props.isOffline} onClick={this.openFaqLink}>
<Cell.Label>
{
// TRANSLATORS: Link to the webpage
messages.pgettext('settings-view', 'FAQs & Guides')
}
</Cell.Label>
<AriaDescription>
<Cell.Icon
height={16}
width={16}
source="icon-extLink"
aria-label={messages.pgettext('accessibility', 'Opens externally')}
/>
</AriaDescription>
</Cell.CellButton>
</AriaDescribed>
</AriaDescriptionGroup>
<Cell.CellButton onClick={this.props.onViewSelectLanguage}>
<StyledCellIcon width={24} height={24} source="icon-language" />
<Cell.Label>
{
// TRANSLATORS: Navigation button to the 'Language' settings view
messages.pgettext('settings-view', 'Language')
}
</Cell.Label>
<Cell.SubText>{this.props.preferredLocaleDisplayName}</Cell.SubText>
<Cell.Icon height={12} width={7} source="icon-chevron" />
</Cell.CellButton>
</>
);
}
}
|