Related titles: switch to Map to avoid duplicated entries

This commit is contained in:
Cuong M. Tran 2024-05-03 10:21:22 +07:00
parent efac4c12fc
commit 5942daa4e1
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
2 changed files with 11 additions and 8 deletions

View file

@ -579,7 +579,7 @@ private fun MangaScreenSmallImpl(
onClick = { /* Should show a page with grid/list of all the related manga */ },
) {
RelatedMangas(
mangas = state.relatedMangas,
mangas = state.relatedMangas.map { it.value },
getMangaState = { getMangaState(it) },
onClickManga = onRelatedMangaClick,
onLongClickManga = onRelatedMangaLongClick,
@ -941,7 +941,7 @@ fun MangaScreenLargeImpl(
onClick = { /* Should show a page with grid/list of all the related manga */ },
) {
RelatedMangas(
mangas = state.relatedMangas,
mangas = state.relatedMangas.map { it.value },
getMangaState = { getMangaState(it) },
onClickManga = onRelatedMangaClick,
onLongClickManga = onRelatedMangaLongClick,

View file

@ -1105,12 +1105,15 @@ class MangaScreenModel(
withIOContext {
if (state.source !is MergedSource) {
val relatedMangas = if (Injekt.get<SourcePreferences>().relatedMangas().get()) {
withIOContext {
state.source.getRelatedMangaList(state.manga.toSManga())
.map {
networkToLocalManga.await(it.toDomainManga(state.source.id))
}
val map = mutableMapOf<Long, Manga>()
val list = state.source.getRelatedMangaList(state.manga.toSManga())
.map {
networkToLocalManga.await(it.toDomainManga(state.source.id))
}
list.forEach {
map[it.id] = it
}
map
} else {
null
}
@ -1711,7 +1714,7 @@ class MangaScreenModel(
val previewsRowCount: Int,
// SY <--
// KMK -->
val relatedMangas: List<Manga>? = null,
val relatedMangas: MutableMap<Long, Manga>? = null,
// KMK <--
) : State {
val processedChapters by lazy {