Simplify dropzone transitions to make more reliable

This commit is contained in:
shamoon 2023-09-26 02:18:14 -07:00
parent e002149ee4
commit 1110cca384
4 changed files with 18 additions and 43 deletions

View File

@ -3,10 +3,10 @@
<ngx-file-drop dropZoneClassName="main-dropzone" contentClassName="main-content" [disabled]="!dragDropEnabled" <ngx-file-drop dropZoneClassName="main-dropzone" contentClassName="main-content" [disabled]="!dragDropEnabled"
(onFileDrop)="dropped($event)" (onFileOver)="fileOver()" (onFileLeave)="fileLeave()"> (onFileDrop)="dropped($event)" (onFileOver)="fileOver()" (onFileLeave)="fileLeave()">
<ng-template ngx-file-drop-content-tmp> <ng-template ngx-file-drop-content-tmp>
<div class="global-dropzone-overlay fade" [class.show]="fileIsOver" [class.hide]="hidden"> <div class="global-dropzone-overlay">
<h2 i18n>Drop files to begin upload</h2> <h2 i18n>Drop files to begin upload</h2>
</div> </div>
<div [class.inert]="fileIsOver"> <div class="main-wrapper">
<router-outlet></router-outlet> <router-outlet></router-outlet>
</div> </div>
</ng-template> </ng-template>

View File

@ -149,19 +149,17 @@ describe('AppComponent', () => {
}) })
it('should support drag drop', fakeAsync(() => { it('should support drag drop', fakeAsync(() => {
expect(component.fileIsOver).toBeFalsy() expect(settingsService.globalDropzoneActive).toBeFalsy()
component.fileOver() component.fileOver()
tick(1) tick(1)
fixture.detectChanges() fixture.detectChanges()
expect(component.fileIsOver).toBeTruthy() expect(settingsService.globalDropzoneActive).toBeTruthy()
const dropzone = fixture.debugElement.query( const dropzone = fixture.debugElement.query(
By.css('.global-dropzone-overlay') By.css('.global-dropzone-overlay')
) )
expect(dropzone).not.toBeNull() expect(dropzone).not.toBeNull()
component.fileLeave()
tick(700) tick(700)
fixture.detectChanges() fixture.detectChanges()
expect(dropzone.classes['hide']).toBeTruthy()
// drop // drop
const toastSpy = jest.spyOn(toastService, 'show') const toastSpy = jest.spyOn(toastService, 'show')
const uploadSpy = jest.spyOn(uploadDocumentsService, 'onNgxFileDrop') const uploadSpy = jest.spyOn(uploadDocumentsService, 'onNgxFileDrop')
@ -173,6 +171,7 @@ describe('AppComponent', () => {
}, },
} as unknown as NgxFileDropEntry, } as unknown as NgxFileDropEntry,
]) ])
expect(settingsService.globalDropzoneActive).toBeFalsy()
tick(3000) tick(3000)
expect(toastSpy).toHaveBeenCalled() expect(toastSpy).toHaveBeenCalled()
expect(uploadSpy).toHaveBeenCalled() expect(uploadSpy).toHaveBeenCalled()

View File

@ -25,10 +25,6 @@ export class AppComponent implements OnInit, OnDestroy {
successSubscription: Subscription successSubscription: Subscription
failedSubscription: Subscription failedSubscription: Subscription
private fileLeaveTimeoutID: any
fileIsOver: boolean = false
hidden: boolean = true
constructor( constructor(
private settings: SettingsService, private settings: SettingsService,
private consumerStatusService: ConsumerStatusService, private consumerStatusService: ConsumerStatusService,
@ -263,31 +259,14 @@ export class AppComponent implements OnInit, OnDestroy {
public fileOver() { public fileOver() {
this.settings.globalDropzoneActive = true this.settings.globalDropzoneActive = true
// allows transition
setTimeout(() => {
this.fileIsOver = true
}, 1)
this.hidden = false
// stop fileLeave timeout
clearTimeout(this.fileLeaveTimeoutID)
} }
public fileLeave(immediate: boolean = false) { public fileLeave() {
this.settings.globalDropzoneActive = false this.settings.globalDropzoneActive = false
const ms = immediate ? 0 : 500
this.fileLeaveTimeoutID = setTimeout(() => {
this.fileIsOver = false
// await transition completed
setTimeout(() => {
this.hidden = true
}, 150)
}, ms)
} }
public dropped(files: NgxFileDropEntry[]) { public dropped(files: NgxFileDropEntry[]) {
this.settings.globalDropzoneActive = false this.fileLeave()
this.fileLeave(true)
this.uploadDocumentsService.onNgxFileDrop(files) this.uploadDocumentsService.onNgxFileDrop(files)
if (files.length > 0) if (files.length > 0)
this.toastService.showInfo($localize`Initiating upload...`, 3000) this.toastService.showInfo($localize`Initiating upload...`, 3000)

View File

@ -505,28 +505,25 @@ table.table {
user-select: none !important; user-select: none !important;
text-align: center; text-align: center;
padding-top: 25%; padding-top: 25%;
opacity: 0;
transition: opacity 0.05s linear;
h2 { h2 {
color: var(--pngx-primary-text-contrast) color: var(--pngx-primary-text-contrast)
} }
&.show {
opacity: 1 !important;
} }
&.hide { .ngx-file-drop__drop-zone--over {
display: none; .global-dropzone-overlay {
} opacity: 1;
pointer-events: all !important;
} }
.ngx-file-drop__drop-zone--over .global-dropzone-overlay { .main-wrapper {
opacity: 0;
}
.inert {
pointer-events: none !important; pointer-events: none !important;
user-select: none !important; user-select: none !important;
} }
}
.alert-primary { .alert-primary {
--bs-alert-color: var(--bs-primary); --bs-alert-color: var(--bs-primary);