Files
Mangarr/assets/vue/app/domain/reader/domain/entities/Chapter.js

35 lines
900 B
JavaScript

export class Chapter {
constructor({ id, mangaId, number, title, pages = [], read = false, lastReadPage = 0, navigation = {} }) {
this.id = id;
this.mangaId = mangaId;
this.number = number;
this.title = title;
this.pages = pages;
this.read = read;
this.lastReadPage = lastReadPage;
this.navigation = {
previousChapter: navigation.previousChapter || null,
nextChapter: navigation.nextChapter || null
};
}
static create(data) {
return new Chapter(data);
}
markAsRead() {
this.read = true;
this.lastReadPage = this.pages.length;
}
markAsUnread() {
this.read = false;
this.lastReadPage = 0;
}
updateLastReadPage(pageNumber) {
this.lastReadPage = pageNumber;
this.read = pageNumber === this.pages.length;
}
}