-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmangadex-shell.component.ts
More file actions
57 lines (49 loc) · 2.29 KB
/
Copy pathmangadex-shell.component.ts
File metadata and controls
57 lines (49 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Component, signal } from '@angular/core';
import { forkJoin, map, of, switchMap } from 'rxjs';
import { MangadexService } from './mangadex.service';
import { Base64 } from '../../shared/utils';
import { CommonReadModule, ReadBaseComponent } from '../@common-read';
import { MANGADEX_PATH } from '../../app-routing.module';
@Component({
imports: [CommonReadModule],
selector: 'app-mangadex-shell',
template: `<app-common-read [episode$]="episode$" [error$]="error$" [loading$]="loading$" (refreshData)="refreshData()" [playlist]="playlistService.playlist()" [playlistLink]="playlistLink()" [currentPlaylistItem]="currentPlItem()" >
<source-copyright [sourceName]="sourceName()" [sourceUrl]="sourceUrl()" />
<source-copyright-logo ngProjectAs="source-logo" [sourceName]="sourceName()" [sourceUrl]="sourceUrl()" [sourceImageSrc]="sourceImageSrc()" />
</app-common-read>`
})
export default class MangadexShellComponent extends ReadBaseComponent {
protected readonly sourceName = signal('MangaDex');
protected readonly sourceUrl = signal('https://mangadex.org');
protected readonly sourceImageSrc = signal('/assets/logos/mangadex-logo.svg');
override episode$ = this.combineParamMapAndRefresh()
.pipe(this.tapStartLoading(),
switchMap(([params]) => {
const idParam = params?.get('id');
if (!idParam) return of(null);
const id = (Base64.isBase64(idParam)) ? Base64.fromBase64(idParam) : idParam;
const id64 = Base64.toBase64(id);
const ch$ = this.mangadex.getChapter(id);
return ch$.pipe(
switchMap(ch => {
const imgs$ = this.mangadex.getChapterImages(id);
const manga$ = (ch.mangaId) ? this.mangadex.getManga(ch.mangaId) : of(null);
return forkJoin([imgs$, manga$]).pipe(
map(([imgs, manga]) => {
ch.images = imgs;
ch.nsfw = manga?.nsfw ?? undefined;
return ch;
}),
this.catchError()
);
}),
this.catchError(),
this.tapSetMetaTags(MANGADEX_PATH),
this.tapSaveToHistory(MANGADEX_PATH, id64),
this.tapSaveToCurrentPlaylistItem(MANGADEX_PATH, id),
this.finalizeLoading()
);
})
);
constructor(public mangadex: MangadexService) { super() }
}