mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-03-31 18:56:21 +00:00
fix: Only display time since last backup on provider card
This commit is contained in:
parent
8cbe69fa90
commit
9dfe7a3431
3 changed files with 43 additions and 16 deletions
|
@ -221,8 +221,13 @@
|
|||
},
|
||||
"backup": {
|
||||
"card_title": "Backup",
|
||||
"card_subtitle": "{backupsPeriod} · Last backup: {lastBackups}",
|
||||
"card_subtitle_never": "Never",
|
||||
"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.",
|
||||
"reupload_key": "Force reupload key",
|
||||
"reuploaded_key": "Key reuploaded",
|
||||
|
|
|
@ -20,6 +20,8 @@ sealed class BackupsState extends Equatable {
|
|||
|
||||
List<Backup> serviceBackups(final String serviceId) => [];
|
||||
|
||||
Duration? timeSinceLastBackup() => null;
|
||||
|
||||
Duration? get autobackupPeriod => null;
|
||||
|
||||
AutobackupQuotas? get autobackupQuotas => null;
|
||||
|
@ -125,6 +127,17 @@ class BackupsInitialized extends BackupsState {
|
|||
? null
|
||||
: _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
|
||||
@Deprecated('Infer the initializations status from state')
|
||||
bool get isInitialized => true;
|
||||
|
|
|
@ -33,8 +33,7 @@ class _ProvidersPageState extends State<ProvidersPage> {
|
|||
Widget build(final BuildContext context) {
|
||||
final bool isReady = context.watch<ServerInstallationCubit>().state
|
||||
is ServerInstallationFinished;
|
||||
final backupsState = context.watch<BackupsBloc>().state;
|
||||
_backupsCardSubtitle(backupsState);
|
||||
final BackupsState backupsState = context.watch<BackupsBloc>().state;
|
||||
|
||||
final DnsRecordsStatus dnsStatus =
|
||||
context.watch<DnsRecordsCubit>().state.dnsState;
|
||||
|
@ -143,20 +142,30 @@ class _ProvidersPageState extends State<ProvidersPage> {
|
|||
|
||||
String _backupsCardSubtitle(final BackupsState backupsState) {
|
||||
if (backupsState is BackupsInitialized) {
|
||||
final period = backupsState.autobackupPeriod;
|
||||
final backups = backupsState.backups;
|
||||
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: {
|
||||
'backupsPeriod': (period != null)
|
||||
? 'backup.autobackup_period_every'.tr(
|
||||
namedArgs: {
|
||||
'period': period.toPrettyString(context.locale),
|
||||
},
|
||||
)
|
||||
: 'backup.autobackup_period_never'.tr(),
|
||||
'lastBackups': backups.isNotEmpty
|
||||
? DateFormat('yyyy-MM-dd H:m').format(backups.first.time)
|
||||
: 'backup.card_subtitle_never'.tr(),
|
||||
'numericValue': numericValue.toString(),
|
||||
'measurement': measurement,
|
||||
},
|
||||
);
|
||||
} else if (backupsState is BackupsLoading ||
|
||||
|
|
Loading…
Add table
Reference in a new issue