Skip to content

Commit

Permalink
feat(capture-tab): show confirm dialog before refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
sultanmyrza committed Dec 14, 2023
1 parent 6fb9378 commit a09e1e8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
41 changes: 28 additions & 13 deletions src/app/features/home/capture-tab/capture-tab.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { formatDate, KeyValue } from '@angular/common';
import { HttpErrorResponse } from '@angular/common/http';
import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { Router } from '@angular/router';
import {
ActionSheetButton,
Expand All @@ -15,7 +16,6 @@ import {
catchError,
concatMap,
concatMapTo,
finalize,
map,
pluck,
shareReplay,
Expand Down Expand Up @@ -45,6 +45,7 @@ import { getOldProof } from '../../../shared/repositories/proof/old-proof-adapte
import { Proof } from '../../../shared/repositories/proof/proof';
import { ProofRepository } from '../../../shared/repositories/proof/proof-repository.service';
import { reloadApp } from '../../../utils/miscellaneous';
import { PrefetchingDialogComponent } from '../onboarding/prefetching-dialog/prefetching-dialog.component';

@UntilDestroy({ checkProperties: true })
@Component({
Expand Down Expand Up @@ -158,6 +159,8 @@ export class CaptureTabComponent implements OnInit {
private readonly mediaStore: MediaStore,
private readonly database: Database,
private readonly confirmAlert: ConfirmAlert,
private readonly dialog: MatDialog,

private readonly preferenceManager: PreferenceManager,
private readonly changeDetectorRef: ChangeDetectorRef,
private readonly proofRepository: ProofRepository,
Expand Down Expand Up @@ -334,17 +337,29 @@ export class CaptureTabComponent implements OnInit {
return item.id;
}

refreshCaptures(event: Event) {
this.diaBackendAssetRefreshingService
.refresh()
.pipe(
finalize(() => {
this.capturedTabPageIndex$.next(0);
this.collectedTabPageIndex$.next(0);
this.draftTabPageIndex$.next(0);
return (<CustomEvent>event).detail.complete();
})
)
.subscribe();
async refreshCaptures(event: Event) {
(<CustomEvent>event).detail.complete();

const confirmRefresh = await this.showRefreshAlert();
if (confirmRefresh) {
this.capturedTabPageIndex$.next(0);
this.collectedTabPageIndex$.next(0);
this.draftTabPageIndex$.next(0);

return this.dialog.open(PrefetchingDialogComponent, {
disableClose: true,
});
}
}

private async showRefreshAlert() {
return this.confirmAlert.present({
header: this.translocoService.translate('syncAndRestore'),
message: this.translocoService.translate('message.confirmSyncAndRestore'),
confirmButtonText: this.translocoService.translate(
'confirmSyncAndRestore'
),
cancelButtonText: this.translocoService.translate('cancelSyncAndRestore'),
});
}
}
4 changes: 4 additions & 0 deletions src/assets/i18n/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
"restorePhotos": "Restore Captures",
"restore": "Restore",
"skip": "Skip",
"syncAndRestore": "Sync and restore all assets?",
"confirmSyncAndRestore": "Confirm",
"cancelSyncAndRestore": "Do it later",
"contactUs": "Contact us",
"editUsername": "Edit Username",
"forgotPassword": "Forgot Password",
Expand Down Expand Up @@ -169,6 +172,7 @@
"networkNotConnected": "No internet connections.",
"allPhotosRegistered": "All Captures registered on blockchain successfully",
"confirmPrefetch": "Do you want to restore the registered Captures? It may take minutes to complete.",
"confirmSyncAndRestore": "This will download all assets again and making sure your local data is up to date",
"loadingPreviousData": "Restoring Captures...",
"doNotTurnOffApp": "Please keep the screen on and DO NOT leave the app.",
"upgrading": "Upgrading...",
Expand Down
4 changes: 4 additions & 0 deletions src/assets/i18n/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
"restorePhotos": "恢復已註冊的瞬時影像",
"restore": "恢復",
"skip": "跳過",
"syncAndRestore": "同步並還原所有資產?",
"confirmSyncAndRestore": "確認",
"cancelSyncAndRestore": "稍後再說",
"contactUs": "聯絡我們",
"editUsername": "修改使用者名稱",
"forgotPassword": "忘記密碼",
Expand Down Expand Up @@ -169,6 +172,7 @@
"networkNotConnected": "沒有網路連線",
"allPhotosRegistered": "所有瞬時影像都已成功註冊",
"confirmPrefetch": "是否要恢復已註冊的瞬時影像?這個流程需要數分鐘的時間。",
"confirmSyncAndRestore": "這將重新下載所有資產,並確保您的本地數據是最新的。",
"loadingPreviousData": "正在恢復已註冊的瞬時影像...",
"doNotTurnOffApp": "載入中,期間請勿關閉螢幕與離開 APP。",
"upgrading": "升級中...",
Expand Down

0 comments on commit a09e1e8

Please sign in to comment.