Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(custom-camera.page): remove capture after discard/approve #1814

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/app/features/home/custom-camera/custom-camera.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand All @@ -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;
Expand Down
13 changes: 11 additions & 2 deletions src/app/features/home/custom-camera/custom-camera.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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(
Expand Down Expand Up @@ -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);
Expand Down