Downloading Enhancements (#2599)

This commit is contained in:
Joe Milazzo 2024-01-11 14:08:57 -06:00 committed by GitHub
parent e6f6090fcf
commit 70cb687ef6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 139 additions and 45 deletions

View file

@ -40,7 +40,7 @@ export class NavService {
this.renderer = rendererFactory.createRenderer(null, null);
// To avoid flashing, let's check if we are authenticated before we show
this.accountService.currentUser$.subscribe(u => {
this.accountService.currentUser$.pipe(take(1)).subscribe(u => {
if (u) {
this.showNavBar();
}

View file

@ -19,7 +19,7 @@ export class ReviewSeriesModalComponent implements OnInit {
protected readonly modal = inject(NgbActiveModal);
private readonly seriesService = inject(SeriesService);
private readonly cdRef = inject(ChangeDetectorRef);
protected readonly minLength = 20;
protected readonly minLength = 5;
@Input({required: true}) review!: UserReview;
reviewGroup!: FormGroup;

View file

@ -277,11 +277,23 @@ export class CardItemComponent implements OnInit {
});
this.download$ = this.downloadService.activeDownloads$.pipe(takeUntilDestroyed(this.destroyRef), map((events) => {
if(this.utilityService.isSeries(this.entity)) return events.find(e => e.entityType === 'series' && e.subTitle === this.downloadService.downloadSubtitle('series', (this.entity as Series))) || null;
if(this.utilityService.isVolume(this.entity)) return events.find(e => e.entityType === 'volume' && e.subTitle === this.downloadService.downloadSubtitle('volume', (this.entity as Volume))) || null;
if(this.utilityService.isChapter(this.entity)) return events.find(e => e.entityType === 'chapter' && e.subTitle === this.downloadService.downloadSubtitle('chapter', (this.entity as Chapter))) || null;
if(this.utilityService.isSeries(this.entity)) {
return events.find(e => e.entityType === 'series' && e.id == this.entity.id
&& e.subTitle === this.downloadService.downloadSubtitle('series', (this.entity as Series))) || null;
}
if(this.utilityService.isVolume(this.entity)) {
return events.find(e => e.entityType === 'volume' && e.id == this.entity.id
&& e.subTitle === this.downloadService.downloadSubtitle('volume', (this.entity as Volume))) || null;
}
if(this.utilityService.isChapter(this.entity)) {
return events.find(e => e.entityType === 'chapter' && e.id == this.entity.id
&& e.subTitle === this.downloadService.downloadSubtitle('chapter', (this.entity as Chapter))) || null;
}
// Is PageBookmark[]
if(this.entity.hasOwnProperty('length')) return events.find(e => e.entityType === 'bookmark' && e.subTitle === this.downloadService.downloadSubtitle('bookmark', [(this.entity as PageBookmark)])) || null;
if(this.entity.hasOwnProperty('length')) {
return events.find(e => e.entityType === 'bookmark'
&& e.subTitle === this.downloadService.downloadSubtitle('bookmark', [(this.entity as PageBookmark)])) || null;
}
return null;
}));

View file

@ -20,6 +20,4 @@ export class DownloadIndicatorComponent {
* Observable that represents when the download completes
*/
@Input({required: true}) download$!: Observable<Download | DownloadEvent | null> | null;
constructor() { }
}

View file

@ -48,7 +48,7 @@
<div class="btn-group me-3">
<button type="button" class="btn btn-primary" (click)="continue()">
<span>
<i class="fa fa-book-open" aria-hidden="true"></i>
<i class="fa fa-book-open me-1" aria-hidden="true"></i>
<span class="read-btn--text">{{t('continue')}}</span>
</span>
</button>
@ -63,7 +63,7 @@
</button>
<button ngbDropdownItem (click)="continue(true)">
<span>
<i class="fa fa-book-open" aria-hidden="true"></i>
<i class="fa fa-book-open me-1" aria-hidden="true"></i>
<span class="read-btn--text">{{t('continue')}}</span>
(<i class="fa fa-glasses ms-1" aria-hidden="true"></i>)
<span class="visually-hidden">{{t('incognito-alt')}}</span>
@ -71,7 +71,7 @@
</button>
<button ngbDropdownItem (click)="read(true)">
<span>
<i class="fa fa-book" aria-hidden="true"></i>
<i class="fa fa-book me-1" aria-hidden="true"></i>
<span class="read-btn--text">&nbsp;{{t('read')}}</span>
(<i class="fa fa-glasses ms-1" aria-hidden="true"></i>)
<span class="visually-hidden">{{t('incognito-alt')}}</span>

View file

@ -40,6 +40,10 @@ export interface DownloadEvent {
* Progress of the download itself
*/
progress: number;
/**
* Entity id. For entities without id like logs or bookmarks, uses 0 instead
*/
id: number;
}
/**
@ -178,7 +182,7 @@ export class DownloadService {
download((blob, filename) => {
this.save(blob, decodeURIComponent(filename));
}),
tap((d) => this.updateDownloadState(d, downloadType, subtitle)),
tap((d) => this.updateDownloadState(d, downloadType, subtitle, 0)),
finalize(() => this.finalizeDownloadState(downloadType, subtitle))
);
}
@ -193,7 +197,7 @@ export class DownloadService {
download((blob, filename) => {
this.save(blob, decodeURIComponent(filename));
}),
tap((d) => this.updateDownloadState(d, downloadType, subtitle)),
tap((d) => this.updateDownloadState(d, downloadType, subtitle, series.id)),
finalize(() => this.finalizeDownloadState(downloadType, subtitle))
);
}
@ -204,12 +208,12 @@ export class DownloadService {
this.downloadsSource.next(values);
}
private updateDownloadState(d: Download, entityType: DownloadEntityType, entitySubtitle: string) {
private updateDownloadState(d: Download, entityType: DownloadEntityType, entitySubtitle: string, id: number) {
let values = this.downloadsSource.getValue();
if (d.state === 'PENDING') {
const index = values.findIndex(v => v.entityType === entityType && v.subTitle === entitySubtitle);
if (index >= 0) return; // Don't let us duplicate add
values.push({entityType: entityType, subTitle: entitySubtitle, progress: 0});
values.push({entityType: entityType, subTitle: entitySubtitle, progress: 0, id});
} else if (d.state === 'IN_PROGRESS') {
const index = values.findIndex(v => v.entityType === entityType && v.subTitle === entitySubtitle);
if (index >= 0) {
@ -232,7 +236,7 @@ export class DownloadService {
download((blob, filename) => {
this.save(blob, decodeURIComponent(filename));
}),
tap((d) => this.updateDownloadState(d, downloadType, subtitle)),
tap((d) => this.updateDownloadState(d, downloadType, subtitle, chapter.id)),
finalize(() => this.finalizeDownloadState(downloadType, subtitle))
);
}
@ -247,14 +251,14 @@ export class DownloadService {
download((blob, filename) => {
this.save(blob, decodeURIComponent(filename));
}),
tap((d) => this.updateDownloadState(d, downloadType, subtitle)),
tap((d) => this.updateDownloadState(d, downloadType, subtitle, volume.id)),
finalize(() => this.finalizeDownloadState(downloadType, subtitle))
);
}
private async confirmSize(size: number, entityType: DownloadEntityType) {
return (size < this.SIZE_WARNING ||
await this.confirmService.confirm(translate('toasts.confirm-download-size', {entityType: 'entity-type.' + entityType, size: bytesPipe.transform(size)})));
await this.confirmService.confirm(translate('toasts.confirm-download-size', {entityType: translate('entity-type.' + entityType), size: bytesPipe.transform(size)})));
}
private downloadBookmarks(bookmarks: PageBookmark[]) {
@ -268,7 +272,7 @@ export class DownloadService {
download((blob, filename) => {
this.save(blob, decodeURIComponent(filename));
}),
tap((d) => this.updateDownloadState(d, downloadType, subtitle)),
tap((d) => this.updateDownloadState(d, downloadType, subtitle, 0)),
finalize(() => this.finalizeDownloadState(downloadType, subtitle))
);
}

View file

@ -3,7 +3,6 @@
}
.stat-container {
max-width: 700px;
height: auto;
box-sizing:border-box;
}

View file

@ -32,7 +32,6 @@ export class ReadingActivityComponent implements OnInit {
@Input() individualUserMode: boolean = false;
private readonly destroyRef = inject(DestroyRef);
//private readonly translocoService = inject(TranslocoService);
private readonly statService = inject(StatisticsService);
private readonly memberService = inject(MemberService);
@ -44,7 +43,6 @@ export class ReadingActivityComponent implements OnInit {
users$: Observable<Member[]> | undefined;
data$: Observable<Array<PieDataItem>>;
timePeriods = TimePeriods;
//mangaFormatPipe = new MangaFormatPipe(this.translocoService);
constructor() {
this.data$ = this.formGroup.valueChanges.pipe(