From 2f74ca102d14557ec570b22a8437ffc6befa698e Mon Sep 17 00:00:00 2001 From: sultanmyrza Date: Wed, 13 Jul 2022 18:11:04 +0600 Subject: [PATCH] fix(custom-camera.page): remove capture after discard/approve --- .../home/custom-camera/custom-camera.page.ts | 6 +++--- .../home/custom-camera/custom-camera.service.ts | 13 +++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/app/features/home/custom-camera/custom-camera.page.ts b/src/app/features/home/custom-camera/custom-camera.page.ts index 79c7e75bd..ad655c7d1 100644 --- a/src/app/features/home/custom-camera/custom-camera.page.ts +++ b/src/app/features/home/custom-camera/custom-camera.page.ts @@ -156,9 +156,9 @@ export class CustomCameraPage implements OnInit, OnDestroy { this.removeCurrentCapture(); } - confirmCurrentCapture() { + async confirmCurrentCapture() { if (this.curCaptureFilePath && this.curCaptureType) { - this.customCameraService.uploadToCapture( + await this.customCameraService.uploadToCapture( this.curCaptureFilePath, this.curCaptureType ); @@ -179,7 +179,7 @@ export class CustomCameraPage implements OnInit, OnDestroy { } private removeCurrentCapture() { - // TODO: remove file this.curCaptureFilePath to free space + this.customCameraService.removeFile(this.curCaptureFilePath); this.curCaptureFilePath = undefined; this.curCaptureMimeType = undefined; this.curCaptureSrc = undefined; diff --git a/src/app/features/home/custom-camera/custom-camera.service.ts b/src/app/features/home/custom-camera/custom-camera.service.ts index 30febf614..2bce4eebe 100644 --- a/src/app/features/home/custom-camera/custom-camera.service.ts +++ b/src/app/features/home/custom-camera/custom-camera.service.ts @@ -1,10 +1,12 @@ import { HttpClient } from '@angular/common/http'; -import { Injectable } from '@angular/core'; +import { Inject, Injectable } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; import { Capacitor } from '@capacitor/core'; +import { FilesystemPlugin } from '@capacitor/filesystem'; import { TranslocoService } from '@ngneat/transloco'; import { PreviewCamera } from '@numbersprotocol/preview-camera'; import { BehaviorSubject } from 'rxjs'; +import { FILESYSTEM_PLUGIN } from '../../../shared/capacitor-plugins/capacitor-plugins.module'; import { CaptureService } from '../../../shared/capture/capture.service'; import { ErrorService } from '../../../shared/error/error.service'; import { blobToBase64 } from '../../../utils/encoding/encoding'; @@ -27,7 +29,9 @@ export class CustomCameraService { private readonly httpClient: HttpClient, private readonly captureService: CaptureService, private readonly errorService: ErrorService, - private readonly translocoService: TranslocoService + private readonly translocoService: TranslocoService, + @Inject(FILESYSTEM_PLUGIN) + private readonly filesystemPlugin: FilesystemPlugin ) {} private mediaItemFromFilePath( @@ -89,6 +93,11 @@ export class CustomCameraService { return PreviewCamera.stopRecord().catch(() => ({})); } + async removeFile(filePath: string | undefined) { + if (!filePath) return; + await this.filesystemPlugin.deleteFile({ path: filePath }); + } + private changeGlobalCSSBackgroundToTransparent() { document.querySelector('body')?.classList.add(this.globalCSSClass); document.querySelector('ion-app')?.classList.add(this.globalCSSClass);