7
7
Output ,
8
8
ViewChild ,
9
9
} from '@angular/core' ;
10
+ import { CameraSource } from '@capacitor/camera' ;
10
11
import { Directory , FilesystemPlugin } from '@capacitor/filesystem' ;
11
12
import { AlertController , Platform } from '@ionic/angular' ;
12
13
import { TranslocoService } from '@ngneat/transloco' ;
@@ -58,6 +59,12 @@ export class PrePublishModeComponent {
58
59
59
60
private toggleBlackAndWhiteFilter = true ;
60
61
62
+ readonly curCaptureCameraSource$ = new ReplaySubject < CameraSource > ( 1 ) ;
63
+
64
+ readonly isFromGallery$ = this . curCaptureCameraSource$ . pipe (
65
+ map ( cameraSource => cameraSource === CameraSource . Photos )
66
+ ) ;
67
+
61
68
readonly curCaptureFileSize$ = new ReplaySubject < number > ( 1 ) ;
62
69
63
70
readonly curCaptureFilePath$ = new ReplaySubject < string > ( 1 ) ;
@@ -98,7 +105,12 @@ export class PrePublishModeComponent {
98
105
readonly isFileSizeExceeded$ = combineLatest ( [
99
106
this . curCaptureFileSize$ ,
100
107
this . maxAllowedFileSize$ ,
101
- ] ) . pipe ( map ( ( [ curSize , maxSize ] ) => curSize < maxSize ) ) ;
108
+ ] ) . pipe ( map ( ( [ curSize , maxSize ] ) => curSize > maxSize ) ) ;
109
+
110
+ @Input ( )
111
+ set curCaptureCameraSource ( value : CameraSource | undefined ) {
112
+ if ( value ) this . curCaptureCameraSource$ . next ( value ) ;
113
+ }
102
114
103
115
@Input ( )
104
116
set curCaptureFileSize ( value : number | undefined ) {
@@ -223,21 +235,25 @@ export class PrePublishModeComponent {
223
235
tap ( isImage => ( isImage ? this . confirmImage ( ) : this . confirmVideo ( ) ) )
224
236
) ;
225
237
226
- const showIsFileSizeExceededAction $ = defer ( ( ) =>
227
- this . showIsFileSizeExceededModal ( )
238
+ const showFileSizeExceededAction $ = defer ( ( ) =>
239
+ this . showFileSizeExceededModal ( )
228
240
) ;
229
241
230
- this . isFileSizeExceeded$
242
+ const shouldShowFileSizeExeededDialog$ = combineLatest ( [
243
+ this . isFromGallery$ ,
244
+ this . isFileSizeExceeded$ ,
245
+ ] ) . pipe ( map ( ( [ c1 , c2 ] ) => c1 === true && c2 === true ) ) ;
246
+
247
+ shouldShowFileSizeExeededDialog$
231
248
. pipe (
232
249
first ( ) ,
233
- switchMap ( hasEnoughMemory =>
250
+ switchMap ( shouldShowFileSizeExeededDialog =>
234
251
iif (
235
- ( ) => hasEnoughMemory ,
236
- runConfirmAction $,
237
- showIsFileSizeExceededAction $
252
+ ( ) => shouldShowFileSizeExeededDialog ,
253
+ showFileSizeExceededAction $,
254
+ runConfirmAction $
238
255
)
239
- ) ,
240
- catchError ( ( error : unknown ) => this . errorService . toastError$ ( error ) )
256
+ )
241
257
)
242
258
. subscribe ( ) ;
243
259
}
@@ -259,7 +275,7 @@ export class PrePublishModeComponent {
259
275
this . confirm . emit ( true ) ;
260
276
}
261
277
262
- private showIsFileSizeExceededModal ( ) {
278
+ private showFileSizeExceededModal ( ) {
263
279
const translations$ = this . translocoService . selectTranslateObject ( {
264
280
'customCamera.error.fileSizeExeedsLimit' : null ,
265
281
ok : null ,
0 commit comments