feat(book-uploader): Improved UX of drag&drop when adding books. (#2410)
The current experience was not great when you have several libraries, instead of swallowing the drop it was disabling the drag/drop zone leading to the browser taking over and opening the file. This changes keeps the drag & drop enabled but just swallows the files and displays an error if no library is selected. It also improves the UI by making it more clear when a drag event is happening.
This commit is contained in:
@@ -90,8 +90,7 @@
|
|||||||
[multiple]="true"
|
[multiple]="true"
|
||||||
accept=".pdf,.epub,.cbz,.cbr,.cb7,.fb2,.mobi,.azw,.azw3"
|
accept=".pdf,.epub,.cbz,.cbr,.cb7,.fb2,.mobi,.azw,.azw3"
|
||||||
(onSelect)="onFilesSelect($event)"
|
(onSelect)="onFilesSelect($event)"
|
||||||
(uploadHandler)="uploadFiles($event)"
|
(uploadHandler)="uploadFiles($event)">
|
||||||
[disabled]="value === 'library' ? (!selectedLibrary || !selectedPath) : false">
|
|
||||||
<ng-template #header let-files let-chooseCallback="chooseCallback" let-clearCallback="clearCallback" let-uploadCallback="uploadCallback">
|
<ng-template #header let-files let-chooseCallback="chooseCallback" let-clearCallback="clearCallback" let-uploadCallback="uploadCallback">
|
||||||
<div class="upload-actions">
|
<div class="upload-actions">
|
||||||
<div class="action-buttons">
|
<div class="action-buttons">
|
||||||
|
|||||||
@@ -98,9 +98,10 @@
|
|||||||
|
|
||||||
.file-upload-section {
|
.file-upload-section {
|
||||||
::ng-deep .p-fileupload {
|
::ng-deep .p-fileupload {
|
||||||
border: 1px solid var(--border-color);
|
border: 2px dashed var(--border-color);
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
background: var(--ground-background);
|
background: var(--ground-background);
|
||||||
|
transition: border-color 0.3s ease, background-color 0.3s ease;
|
||||||
|
|
||||||
.p-fileupload-buttonbar {
|
.p-fileupload-buttonbar {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -115,6 +116,25 @@
|
|||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
border: none;
|
border: none;
|
||||||
|
transition: background-color 0.3s ease;
|
||||||
|
|
||||||
|
&.p-fileupload-highlight {
|
||||||
|
background: color-mix(in srgb, var(--primary-color) 5%, transparent);
|
||||||
|
|
||||||
|
.empty-icon-wrapper {
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
|
||||||
|
.empty-icon {
|
||||||
|
color: var(--primary-color);
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(1.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&:has(.p-fileupload-highlight) {
|
||||||
|
border-color: var(--primary-color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,12 +319,13 @@
|
|||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
border: 3px dashed var(--border-color);
|
border: 3px dashed var(--border-color);
|
||||||
|
transition: border-color 0.3s ease;
|
||||||
|
|
||||||
.empty-icon {
|
.empty-icon {
|
||||||
font-size: 2.5rem;
|
font-size: 2.5rem;
|
||||||
color: var(--text-secondary-color);
|
color: var(--text-secondary-color);
|
||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
transition: color 0.3s ease;
|
transition: color 0.3s ease, opacity 0.3s ease, transform 0.3s ease;
|
||||||
|
|
||||||
&.active {
|
&.active {
|
||||||
color: #22c55e;
|
color: #22c55e;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {Component, inject, OnInit} from '@angular/core';
|
import {Component, inject, OnInit, ViewChild} from '@angular/core';
|
||||||
import {FileSelectEvent, FileUpload, FileUploadHandlerEvent} from 'primeng/fileupload';
|
import {FileSelectEvent, FileUpload, FileUploadHandlerEvent} from 'primeng/fileupload';
|
||||||
import {Button} from 'primeng/button';
|
import {Button} from 'primeng/button';
|
||||||
import {AsyncPipe} from '@angular/common';
|
import {AsyncPipe} from '@angular/common';
|
||||||
@@ -43,6 +43,8 @@ interface UploadingFile {
|
|||||||
styleUrl: './book-uploader.component.scss'
|
styleUrl: './book-uploader.component.scss'
|
||||||
})
|
})
|
||||||
export class BookUploaderComponent implements OnInit {
|
export class BookUploaderComponent implements OnInit {
|
||||||
|
@ViewChild(FileUpload) fileUpload!: FileUpload;
|
||||||
|
|
||||||
files: UploadingFile[] = [];
|
files: UploadingFile[] = [];
|
||||||
isUploading: boolean = false;
|
isUploading: boolean = false;
|
||||||
uploadCompleted: boolean = false;
|
uploadCompleted: boolean = false;
|
||||||
@@ -116,6 +118,18 @@ export class BookUploaderComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onFilesSelect(event: FileSelectEvent): void {
|
onFilesSelect(event: FileSelectEvent): void {
|
||||||
|
if (this.value === 'library' && (!this.selectedLibrary || !this.selectedPath)) {
|
||||||
|
this.messageService.add({
|
||||||
|
severity: 'error',
|
||||||
|
summary: 'No Destination Selected',
|
||||||
|
detail: 'Please select a library and subpath before adding files.',
|
||||||
|
life: 5000
|
||||||
|
});
|
||||||
|
// We need to clear the files input explicitely, otherwise the files remain selected in the file upload component
|
||||||
|
this.fileUpload.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const newFiles = event.currentFiles;
|
const newFiles = event.currentFiles;
|
||||||
for (const file of newFiles) {
|
for (const file of newFiles) {
|
||||||
const exists = this.files.some(f => f.file.name === file.name && f.file.size === file.size);
|
const exists = this.files.some(f => f.file.name === file.name && f.file.size === file.size);
|
||||||
|
|||||||
Reference in New Issue
Block a user