Refactored the setContinuePoint code from the UI to the backend. Now, through an API, we can get the chapter to restart from. (#973)

This commit is contained in:
Joseph Milazzo 2022-01-20 15:49:26 -08:00 committed by GitHub
parent 3eb494dff4
commit 218f642870
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 281 additions and 59 deletions

View file

@ -103,33 +103,8 @@ export class ReaderService {
return this.httpClient.get<number>(this.baseUrl + 'reader/prev-chapter?seriesId=' + seriesId + '&volumeId=' + volumeId + '&currentChapterId=' + currentChapterId);
}
getCurrentChapter(volumes: Array<Volume>): Chapter {
let currentlyReadingChapter: Chapter | undefined = undefined;
const chapters = volumes.filter(v => v.number !== 0).map(v => v.chapters || []).flat().sort(this.utilityService.sortChapters);
for (const c of chapters) {
if (c.pagesRead < c.pages) {
currentlyReadingChapter = c;
break;
}
}
if (currentlyReadingChapter === undefined) {
// Check if there are specials we can load:
const specials = volumes.filter(v => v.number === 0).map(v => v.chapters || []).flat().sort(this.utilityService.sortChapters);
for (const c of specials) {
if (c.pagesRead < c.pages) {
currentlyReadingChapter = c;
break;
}
}
if (currentlyReadingChapter === undefined) {
// Default to first chapter
currentlyReadingChapter = chapters[0];
}
}
return currentlyReadingChapter;
getCurrentChapter(seriesId: number) {
return this.httpClient.get<Chapter>(this.baseUrl + 'reader/continue-point?seriesId=' + seriesId);
}
/**

View file

@ -135,9 +135,9 @@ export class SeriesService {
}));
}
getContinueReading(libraryId: number = 0) {
return this.httpClient.get<InProgressChapter[]>(this.baseUrl + 'series/continue-reading?libraryId=' + libraryId);
}
// getContinueReading(libraryId: number = 0) {
// return this.httpClient.get<InProgressChapter[]>(this.baseUrl + 'series/continue-reading?libraryId=' + libraryId);
// }
refreshMetadata(series: Series) {
return this.httpClient.post(this.baseUrl + 'series/refresh-metadata', {libraryId: series.libraryId, seriesId: series.id});

View file

@ -354,14 +354,14 @@ export class SeriesDetailComponent implements OnInit, OnDestroy {
.filter(action => this.actionFactoryService.filterBookmarksForFormat(action, this.series));
this.volumeActions = this.actionFactoryService.getVolumeActions(this.handleVolumeActionCallback.bind(this));
this.chapterActions = this.actionFactoryService.getChapterActions(this.handleChapterActionCallback.bind(this));
this.seriesService.getVolumes(this.series.id).subscribe(volumes => {
this.chapters = volumes.filter(v => v.number === 0).map(v => v.chapters || []).flat().sort(this.utilityService.sortChapters);
this.volumes = volumes.sort(this.utilityService.sortVolumes);
this.setContinuePoint();
const vol0 = this.volumes.filter(v => v.number === 0);
this.hasSpecials = vol0.map(v => v.chapters || []).flat().sort(this.utilityService.sortChapters).filter(c => c.isSpecial || isNaN(parseInt(c.range, 10))).length > 0 ;
if (this.hasSpecials) {
@ -398,7 +398,7 @@ export class SeriesDetailComponent implements OnInit, OnDestroy {
setContinuePoint() {
this.hasReadingProgress = this.volumes.filter(v => v.pagesRead > 0).length > 0 || this.chapters.filter(c => c.pagesRead > 0).length > 0;
this.currentlyReadingChapter = this.readerService.getCurrentChapter(this.volumes);
this.readerService.getCurrentChapter(this.series.id).subscribe(chapter => this.currentlyReadingChapter = chapter);
}
markAsRead(vol: Volume) {
@ -488,7 +488,7 @@ export class SeriesDetailComponent implements OnInit, OnDestroy {
// If user has progress on the volume, load them where they left off
if (volume.pagesRead < volume.pages && volume.pagesRead > 0) {
// Find the continue point chapter and load it
this.openChapter(this.readerService.getCurrentChapter([volume]));
this.readerService.getCurrentChapter(this.series.id).subscribe(chapter => this.openChapter(chapter));
return;
}