mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-06 16:14:15 +00:00
feat: Add amazing backups card description (#595)
- Resolves: #587 Reviewed-on: https://git.selfprivacy.org/SelfPrivacy/selfprivacy.org.app/pulls/595 Reviewed-by: Inex Code <inex.code@selfprivacy.org> Co-authored-by: NaiJi <naijiworld@protonmail.com> Co-committed-by: NaiJi <naijiworld@protonmail.com>
This commit is contained in:
parent
35cbcebacb
commit
b925f7c8d4
|
@ -221,7 +221,13 @@
|
||||||
},
|
},
|
||||||
"backup": {
|
"backup": {
|
||||||
"card_title": "Backup",
|
"card_title": "Backup",
|
||||||
"card_subtitle": "Manage your backups",
|
"card_subtitle": "Last backup was {numericValue}{measurement} ago",
|
||||||
|
"measurement": {
|
||||||
|
"seconds": "sec",
|
||||||
|
"minutes": "min",
|
||||||
|
"hours": "h",
|
||||||
|
"days": "d"
|
||||||
|
},
|
||||||
"description": "Will save your day in case of incident: hackers attack, server deletion, etc.",
|
"description": "Will save your day in case of incident: hackers attack, server deletion, etc.",
|
||||||
"reupload_key": "Force reupload key",
|
"reupload_key": "Force reupload key",
|
||||||
"reuploaded_key": "Key reuploaded",
|
"reuploaded_key": "Key reuploaded",
|
||||||
|
|
|
@ -20,6 +20,8 @@ sealed class BackupsState extends Equatable {
|
||||||
|
|
||||||
List<Backup> serviceBackups(final String serviceId) => [];
|
List<Backup> serviceBackups(final String serviceId) => [];
|
||||||
|
|
||||||
|
Duration? timeSinceLastBackup() => null;
|
||||||
|
|
||||||
Duration? get autobackupPeriod => null;
|
Duration? get autobackupPeriod => null;
|
||||||
|
|
||||||
AutobackupQuotas? get autobackupQuotas => null;
|
AutobackupQuotas? get autobackupQuotas => null;
|
||||||
|
@ -125,6 +127,17 @@ class BackupsInitialized extends BackupsState {
|
||||||
? null
|
? null
|
||||||
: _backupConfig?.autobackupPeriod;
|
: _backupConfig?.autobackupPeriod;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Duration? timeSinceLastBackup() {
|
||||||
|
if (backups.isEmpty) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final timeNow = DateTime.now();
|
||||||
|
final timeLastBackup = backups.first.time;
|
||||||
|
final delta = timeNow.difference(timeLastBackup);
|
||||||
|
return Duration(seconds: delta.inSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@Deprecated('Infer the initializations status from state')
|
@Deprecated('Infer the initializations status from state')
|
||||||
bool get isInitialized => true;
|
bool get isInitialized => true;
|
||||||
|
|
|
@ -15,6 +15,7 @@ import 'package:selfprivacy/ui/molecules/cards/server_outdated_card.dart';
|
||||||
import 'package:selfprivacy/ui/organisms/headers/brand_header.dart';
|
import 'package:selfprivacy/ui/organisms/headers/brand_header.dart';
|
||||||
import 'package:selfprivacy/ui/router/router.dart';
|
import 'package:selfprivacy/ui/router/router.dart';
|
||||||
import 'package:selfprivacy/utils/breakpoints.dart';
|
import 'package:selfprivacy/utils/breakpoints.dart';
|
||||||
|
import 'package:selfprivacy/utils/extensions/duration.dart';
|
||||||
import 'package:skeletonizer/skeletonizer.dart';
|
import 'package:skeletonizer/skeletonizer.dart';
|
||||||
|
|
||||||
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||||
|
@ -33,6 +34,7 @@ class _ProvidersPageState extends State<ProvidersPage> {
|
||||||
final bool isReady = context.watch<ServerInstallationCubit>().state
|
final bool isReady = context.watch<ServerInstallationCubit>().state
|
||||||
is ServerInstallationFinished;
|
is ServerInstallationFinished;
|
||||||
final BackupsState backupsState = context.watch<BackupsBloc>().state;
|
final BackupsState backupsState = context.watch<BackupsBloc>().state;
|
||||||
|
|
||||||
final DnsRecordsStatus dnsStatus =
|
final DnsRecordsStatus dnsStatus =
|
||||||
context.watch<DnsRecordsCubit>().state.dnsState;
|
context.watch<DnsRecordsCubit>().state.dnsState;
|
||||||
|
|
||||||
|
@ -127,12 +129,7 @@ class _ProvidersPageState extends State<ProvidersPage> {
|
||||||
: StateType.uninitialized,
|
: StateType.uninitialized,
|
||||||
icon: BrandIcons.save,
|
icon: BrandIcons.save,
|
||||||
title: 'backup.card_title'.tr(),
|
title: 'backup.card_title'.tr(),
|
||||||
subtitle: backupsState is BackupsInitialized
|
subtitle: _backupsCardSubtitle(backupsState),
|
||||||
? 'backup.card_subtitle'.tr()
|
|
||||||
: backupsState is BackupsLoading ||
|
|
||||||
backupsState is BackupsInitial
|
|
||||||
? 'basis.loading'.tr()
|
|
||||||
: '',
|
|
||||||
onTap: isClickable()
|
onTap: isClickable()
|
||||||
? () => context.pushRoute(const BackupDetailsRoute())
|
? () => context.pushRoute(const BackupDetailsRoute())
|
||||||
: null,
|
: null,
|
||||||
|
@ -142,4 +139,40 @@ class _ProvidersPageState extends State<ProvidersPage> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String _backupsCardSubtitle(final BackupsState backupsState) {
|
||||||
|
if (backupsState is BackupsInitialized) {
|
||||||
|
final timeSince = backupsState.timeSinceLastBackup();
|
||||||
|
if (timeSince == null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
int numericValue = 0;
|
||||||
|
String measurement = 'backup.measurement.seconds'.tr();
|
||||||
|
if (timeSince.inMinutes < 1) {
|
||||||
|
numericValue = timeSince.inSeconds;
|
||||||
|
} else if (timeSince.inHours < 1) {
|
||||||
|
numericValue = timeSince.inMinutes;
|
||||||
|
measurement = 'backup.measurement.minutes'.tr();
|
||||||
|
} else if (timeSince.inDays < 1) {
|
||||||
|
numericValue = timeSince.inHours;
|
||||||
|
measurement = 'backup.measurement.hours'.tr();
|
||||||
|
} else {
|
||||||
|
numericValue = timeSince.inDays;
|
||||||
|
measurement = 'backup.measurement.days'.tr();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'backup.card_subtitle'.tr(
|
||||||
|
namedArgs: {
|
||||||
|
'numericValue': numericValue.toString(),
|
||||||
|
'measurement': measurement,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else if (backupsState is BackupsLoading ||
|
||||||
|
backupsState is BackupsInitial) {
|
||||||
|
return 'basis.loading'.tr();
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue