Files
Mangarr/assets/react/app/domain/manga.js
2025-02-12 16:12:01 +01:00

75 lines
1.6 KiB
JavaScript

import { Chapter } from './chapter.js';
export class Manga {
constructor(
id,
title,
slug,
imageUrl,
author,
publicationYear,
genres,
status,
rating,
description = ''
) {
this.id = id;
this.title = title;
this.slug = slug;
this.imageUrl = imageUrl;
this.author = author;
this.publicationYear = publicationYear;
this.genres = genres;
this.status = status;
this.rating = rating;
this.description = description;
}
}
export class MangaCollection {
constructor(items, total, page, limit, hasNextPage, hasPreviousPage) {
this.items = items;
this.total = total;
this.page = page;
this.limit = limit;
this.hasNextPage = hasNextPage;
this.hasPreviousPage = hasPreviousPage;
}
}
export class MangaDetail extends Manga {
constructor(manga, chapters = []) {
super(
manga.id,
manga.title,
manga.slug,
manga.imageUrl,
manga.author,
manga.publicationYear,
manga.genres,
manga.status,
manga.rating,
manga.description
);
this.chapters = this.organizeChaptersByVolume(chapters);
}
organizeChaptersByVolume(chapters) {
const volumeMap = new Map();
chapters.forEach(chapter => {
const volume = chapter.volume || 0;
if (!volumeMap.has(volume)) {
volumeMap.set(volume, []);
}
volumeMap.get(volume).push(chapter);
});
// Sort chapters within each volume
volumeMap.forEach(chapters => {
chapters.sort((a, b) => b.number - a.number);
});
return new Map([...volumeMap.entries()].sort((a, b) => b[0] - a[0]));
}
}