Skip to content

Commit dd82c76

Browse files
Update local backups visibility
Co-authored-by: trevor-signal <[email protected]>
1 parent dde3d95 commit dd82c76

File tree

3 files changed

+168
-111
lines changed

3 files changed

+168
-111
lines changed

ts/components/Preferences.stories.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,16 @@ BackupsFree.args = {
858858
mediaIncludedInBackupDurationDays: 30,
859859
},
860860
};
861+
export const BackupsFreeNoLocal = Template.bind({});
862+
BackupsFreeNoLocal.args = {
863+
page: SettingsPage.Backups,
864+
backupFeatureEnabled: true,
865+
backupLocalBackupsEnabled: false,
866+
backupSubscriptionStatus: {
867+
status: 'free',
868+
mediaIncludedInBackupDurationDays: 30,
869+
},
870+
};
861871

862872
export const BackupsOff = Template.bind({});
863873
BackupsOff.args = {
@@ -873,6 +883,13 @@ BackupsLocalBackups.args = {
873883
backupLocalBackupsEnabled: true,
874884
};
875885

886+
export const BackupsRemoteEnabledLocalDisabled = Template.bind({});
887+
BackupsRemoteEnabledLocalDisabled.args = {
888+
page: SettingsPage.Backups,
889+
backupFeatureEnabled: true,
890+
backupLocalBackupsEnabled: false,
891+
};
892+
876893
export const BackupsSubscriptionNotFound = Template.bind({});
877894
BackupsSubscriptionNotFound.args = {
878895
page: SettingsPage.Backups,

ts/components/Preferences.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,8 @@ export function Preferences({
21032103
resumeBackupMediaDownload={resumeBackupMediaDownload}
21042104
cloudBackupStatus={cloudBackupStatus}
21052105
i18n={i18n}
2106+
isLocalBackupsEnabled={backupLocalBackupsEnabled}
2107+
isRemoteBackupsEnabled={backupFeatureEnabled}
21062108
locale={resolvedLocale}
21072109
localBackupFolder={localBackupFolder}
21082110
onBackupKeyViewedChange={onBackupKeyViewedChange}

ts/components/PreferencesBackups.tsx

Lines changed: 149 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,28 @@ import { BackupMediaDownloadProgressSettings } from './BackupMediaDownloadProgre
3434
export const SIGNAL_BACKUPS_LEARN_MORE_URL =
3535
'https://support.signal.org/hc/articles/360007059752-Backup-and-Restore-Messages';
3636

37+
const LOCAL_BACKUPS_PAGES = new Set([
38+
SettingsPage.LocalBackups,
39+
SettingsPage.LocalBackupsKeyReference,
40+
SettingsPage.LocalBackupsSetupFolder,
41+
SettingsPage.LocalBackupsSetupKey,
42+
]);
43+
const REMOTE_BACKUPS_PAGES = new Set([SettingsPage.BackupsDetails]);
44+
45+
function isLocalBackupsPage(page: SettingsPage) {
46+
return LOCAL_BACKUPS_PAGES.has(page);
47+
}
48+
function isRemoteBackupsPage(page: SettingsPage) {
49+
return REMOTE_BACKUPS_PAGES.has(page);
50+
}
3751
export function PreferencesBackups({
3852
accountEntropyPool,
3953
backupKeyViewed,
4054
backupSubscriptionStatus,
4155
cloudBackupStatus,
4256
i18n,
57+
isLocalBackupsEnabled,
58+
isRemoteBackupsEnabled,
4359
locale,
4460
localBackupFolder,
4561
onBackupKeyViewedChange,
@@ -61,6 +77,8 @@ export function PreferencesBackups({
6177
cloudBackupStatus?: BackupStatusType;
6278
localBackupFolder: string | undefined;
6379
i18n: LocalizerType;
80+
isLocalBackupsEnabled: boolean;
81+
isRemoteBackupsEnabled: boolean;
6482
locale: string;
6583
onBackupKeyViewedChange: (keyViewed: boolean) => void;
6684
page: PreferencesBackupPage;
@@ -90,6 +108,16 @@ export function PreferencesBackups({
90108
}
91109
}, [page, refreshBackupSubscriptionStatus, refreshCloudBackupStatus]);
92110

111+
if (!isRemoteBackupsEnabled && isRemoteBackupsPage(page)) {
112+
setPage(SettingsPage.Backups);
113+
return null;
114+
}
115+
116+
if (!isLocalBackupsEnabled && isLocalBackupsPage(page)) {
117+
setPage(SettingsPage.Backups);
118+
return null;
119+
}
120+
93121
if (page === SettingsPage.BackupsDetails) {
94122
if (backupSubscriptionStatus.status === 'off') {
95123
setPage(SettingsPage.Backups);
@@ -109,12 +137,7 @@ export function PreferencesBackups({
109137
);
110138
}
111139

112-
if (
113-
page === SettingsPage.LocalBackups ||
114-
page === SettingsPage.LocalBackupsKeyReference ||
115-
page === SettingsPage.LocalBackupsSetupFolder ||
116-
page === SettingsPage.LocalBackupsSetupKey
117-
) {
140+
if (isLocalBackupsPage(page)) {
118141
return (
119142
<PreferencesLocalBackups
120143
accountEntropyPool={accountEntropyPool}
@@ -139,48 +162,84 @@ export function PreferencesBackups({
139162

140163
const isLocalBackupsSetup = localBackupFolder && backupKeyViewed;
141164

142-
return (
143-
<>
144-
<div className="Preferences__padding">
145-
<div className="Preferences__description Preferences__description--medium">
146-
{i18n('icu:Preferences--backup-section-description')}
147-
</div>
148-
</div>
165+
function renderRemoteBackups() {
166+
return (
167+
<>
168+
{backupSubscriptionStatus.status === 'off' ? (
169+
<SettingsRow className="Preferences--BackupsRow">
170+
<Control
171+
icon="Preferences__BackupsIcon"
172+
left={
173+
<label>
174+
{i18n('icu:Preferences--signal-backups')}{' '}
175+
<div className="Preferences--backup-details__value">
176+
<I18n
177+
id="icu:Preferences--signal-backups-off-description"
178+
i18n={i18n}
179+
components={{
180+
learnMoreLink,
181+
}}
182+
/>
183+
</div>
184+
</label>
185+
}
186+
right={null}
187+
/>
188+
</SettingsRow>
189+
) : (
190+
<SettingsRow className="Preferences--BackupsRow">
191+
<FlowingControl>
192+
<div className="Preferences__two-thirds-flow">
193+
<LightIconLabel icon="Preferences__BackupsIcon">
194+
<label>
195+
{i18n('icu:Preferences--signal-backups')}{' '}
196+
<div className="Preferences__description">
197+
{renderBackupsSubscriptionSummary({
198+
subscriptionStatus: backupSubscriptionStatus,
199+
i18n,
200+
locale,
201+
})}
202+
</div>
203+
</label>
204+
</LightIconLabel>
205+
</div>
206+
<div
207+
className={classNames(
208+
'Preferences__flow-button',
209+
'Preferences__one-third-flow',
210+
'Preferences__one-third-flow--align-right'
211+
)}
212+
>
213+
<Button
214+
onClick={() => setPage(SettingsPage.BackupsDetails)}
215+
variant={ButtonVariant.Secondary}
216+
>
217+
{i18n('icu:Preferences__button--manage')}
218+
</Button>
219+
</div>
220+
</FlowingControl>
221+
</SettingsRow>
222+
)}
223+
</>
224+
);
225+
}
149226

150-
{backupSubscriptionStatus.status === 'off' ? (
151-
<SettingsRow className="Preferences--BackupsRow">
152-
<Control
153-
icon="Preferences__BackupsIcon"
154-
left={
155-
<label>
156-
{i18n('icu:Preferences--signal-backups')}{' '}
157-
<div className="Preferences--backup-details__value">
158-
<I18n
159-
id="icu:Preferences--signal-backups-off-description"
160-
i18n={i18n}
161-
components={{
162-
learnMoreLink,
163-
}}
164-
/>
165-
</div>
166-
</label>
167-
}
168-
right={null}
169-
/>
170-
</SettingsRow>
171-
) : (
172-
<SettingsRow className="Preferences--BackupsRow">
227+
function renderLocalBackups() {
228+
return (
229+
<>
230+
<SettingsRow
231+
className="Preferences--BackupsRow"
232+
title={i18n('icu:Preferences__backup-other-ways')}
233+
>
173234
<FlowingControl>
174235
<div className="Preferences__two-thirds-flow">
175-
<LightIconLabel icon="Preferences__BackupsIcon">
236+
<LightIconLabel icon="Preferences__LocalBackupsIcon">
176237
<label>
177-
{i18n('icu:Preferences--signal-backups')}{' '}
238+
{i18n('icu:Preferences__local-backups')}{' '}
178239
<div className="Preferences__description">
179-
{renderBackupsSubscriptionSummary({
180-
subscriptionStatus: backupSubscriptionStatus,
181-
i18n,
182-
locale,
183-
})}
240+
{isLocalBackupsSetup
241+
? null
242+
: i18n('icu:Preferences--local-backups-off-description')}
184243
</div>
185244
</label>
186245
</LightIconLabel>
@@ -193,82 +252,61 @@ export function PreferencesBackups({
193252
)}
194253
>
195254
<Button
196-
onClick={() => setPage(SettingsPage.BackupsDetails)}
255+
className="Preferences--BackupsAuthButton"
256+
disabled={isAuthPending}
257+
onClick={async () => {
258+
setAuthError(undefined);
259+
260+
if (!isLocalBackupsSetup) {
261+
try {
262+
setIsAuthPending(true);
263+
const result = await promptOSAuth('enable-backups');
264+
if (result !== 'success' && result !== 'unsupported') {
265+
setAuthError(result);
266+
return;
267+
}
268+
} finally {
269+
setIsAuthPending(false);
270+
}
271+
}
272+
273+
setPage(SettingsPage.LocalBackups);
274+
}}
197275
variant={ButtonVariant.Secondary}
198276
>
199-
{i18n('icu:Preferences__button--manage')}
277+
{isLocalBackupsSetup
278+
? i18n('icu:Preferences__button--manage')
279+
: i18n('icu:Preferences__button--set-up')}
200280
</Button>
201281
</div>
202282
</FlowingControl>
203283
</SettingsRow>
204-
)}
205-
206-
<SettingsRow
207-
className="Preferences--BackupsRow"
208-
title={i18n('icu:Preferences__backup-other-ways')}
209-
>
210-
<FlowingControl>
211-
<div className="Preferences__two-thirds-flow">
212-
<LightIconLabel icon="Preferences__LocalBackupsIcon">
213-
<label>
214-
{i18n('icu:Preferences__local-backups')}{' '}
215-
<div className="Preferences__description">
216-
{isLocalBackupsSetup
217-
? null
218-
: i18n('icu:Preferences--local-backups-off-description')}
219-
</div>
220-
</label>
221-
</LightIconLabel>
222-
</div>
223-
<div
224-
className={classNames(
225-
'Preferences__flow-button',
226-
'Preferences__one-third-flow',
227-
'Preferences__one-third-flow--align-right'
228-
)}
284+
285+
{authError && (
286+
<ConfirmationDialog
287+
i18n={i18n}
288+
dialogName="PreferencesLocalBackups--ErrorDialog"
289+
onClose={() => setAuthError(undefined)}
290+
cancelButtonVariant={ButtonVariant.Secondary}
291+
cancelText={i18n('icu:ok')}
229292
>
230-
<Button
231-
className="Preferences--BackupsAuthButton"
232-
disabled={isAuthPending}
233-
onClick={async () => {
234-
setAuthError(undefined);
235-
236-
if (!isLocalBackupsSetup) {
237-
try {
238-
setIsAuthPending(true);
239-
const result = await promptOSAuth('enable-backups');
240-
if (result !== 'success' && result !== 'unsupported') {
241-
setAuthError(result);
242-
return;
243-
}
244-
} finally {
245-
setIsAuthPending(false);
246-
}
247-
}
293+
{getOSAuthErrorString(authError) ?? i18n('icu:error')}
294+
</ConfirmationDialog>
295+
)}
296+
</>
297+
);
298+
}
248299

249-
setPage(SettingsPage.LocalBackups);
250-
}}
251-
variant={ButtonVariant.Secondary}
252-
>
253-
{isLocalBackupsSetup
254-
? i18n('icu:Preferences__button--manage')
255-
: i18n('icu:Preferences__button--set-up')}
256-
</Button>
257-
</div>
258-
</FlowingControl>
259-
</SettingsRow>
260-
261-
{authError && (
262-
<ConfirmationDialog
263-
i18n={i18n}
264-
dialogName="PreferencesLocalBackups--ErrorDialog"
265-
onClose={() => setAuthError(undefined)}
266-
cancelButtonVariant={ButtonVariant.Secondary}
267-
cancelText={i18n('icu:ok')}
268-
>
269-
{getOSAuthErrorString(authError) ?? i18n('icu:error')}
270-
</ConfirmationDialog>
271-
)}
300+
return (
301+
<>
302+
<div className="Preferences__padding">
303+
<div className="Preferences__description Preferences__description--medium">
304+
{i18n('icu:Preferences--backup-section-description')}
305+
</div>
306+
</div>
307+
308+
{isRemoteBackupsEnabled ? renderRemoteBackups() : null}
309+
{isLocalBackupsEnabled ? renderLocalBackups() : null}
272310
</>
273311
);
274312
}

0 commit comments

Comments
 (0)