Skip to content

Commit

Permalink
Fix Tracker Status and Scores (#843)
Browse files Browse the repository at this point in the history
  • Loading branch information
Syer10 authored Jan 23, 2024
1 parent 4bec027 commit 9121a63
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.graphql.types.TrackRecordNodeList
import suwayomi.tachidesk.graphql.types.TrackRecordNodeList.Companion.toNodeList
import suwayomi.tachidesk.graphql.types.TrackRecordType
import suwayomi.tachidesk.graphql.types.TrackStatusType
import suwayomi.tachidesk.graphql.types.TrackerType
import suwayomi.tachidesk.manga.impl.track.tracker.TrackerManager
import suwayomi.tachidesk.manga.impl.track.tracker.model.toTrack
Expand All @@ -36,6 +37,36 @@ class TrackerDataLoader : KotlinDataLoader<Int, TrackerType> {
}
}

class TrackerStatusesDataLoader : KotlinDataLoader<Int, List<TrackStatusType>> {
override val dataLoaderName = "TrackerStatusesDataLoader"

override fun getDataLoader(): DataLoader<Int, List<TrackStatusType>> =
DataLoaderFactory.newDataLoader { ids ->
future {
ids.map { id ->
TrackerManager.getTracker(id)?.let { tracker ->
tracker.getStatusList().map {
TrackStatusType(it, tracker.getStatus(it)!!)
}
}
}
}
}
}

class TrackerScoresDataLoader : KotlinDataLoader<Int, List<String>> {
override val dataLoaderName = "TrackerStatusesDataLoader"

override fun getDataLoader(): DataLoader<Int, List<String>> =
DataLoaderFactory.newDataLoader { ids ->
future {
ids.map { id ->
TrackerManager.getTracker(id)?.getScoreList()
}
}
}
}

class TrackRecordsForMangaIdDataLoader : KotlinDataLoader<Int, TrackRecordNodeList> {
override val dataLoaderName = "TrackRecordsForMangaIdDataLoader"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import suwayomi.tachidesk.graphql.dataLoaders.TrackRecordDataLoader
import suwayomi.tachidesk.graphql.dataLoaders.TrackRecordsForMangaIdDataLoader
import suwayomi.tachidesk.graphql.dataLoaders.TrackRecordsForTrackerIdDataLoader
import suwayomi.tachidesk.graphql.dataLoaders.TrackerDataLoader
import suwayomi.tachidesk.graphql.dataLoaders.TrackerScoresDataLoader
import suwayomi.tachidesk.graphql.dataLoaders.TrackerStatusesDataLoader
import suwayomi.tachidesk.graphql.dataLoaders.UnreadChapterCountForMangaDataLoader

class TachideskDataLoaderRegistryFactory {
Expand Down Expand Up @@ -65,6 +67,8 @@ class TachideskDataLoaderRegistryFactory {
ExtensionDataLoader(),
ExtensionForSourceDataLoader(),
TrackerDataLoader(),
TrackerStatusesDataLoader(),
TrackerScoresDataLoader(),
TrackRecordsForMangaIdDataLoader(),
DisplayScoreForTrackRecordDataLoader(),
TrackRecordsForTrackerIdDataLoader(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,24 @@ class TrackerType(
},
)

fun statuses(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<List<TrackStatusType>> {
return dataFetchingEnvironment.getValueFromDataLoader<Int, List<TrackStatusType>>("TrackerStatusesDataLoader", id)
}

fun scores(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<List<String>> {
return dataFetchingEnvironment.getValueFromDataLoader<Int, List<String>>("TrackerScoresDataLoader", id)
}

fun trackRecords(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<TrackRecordNodeList> {
return dataFetchingEnvironment.getValueFromDataLoader<Int, TrackRecordNodeList>("TrackRecordsForTrackerIdDataLoader", id)
}
}

class TrackStatusType(
val value: Int,
val name: String,
)

class TrackRecordType(
val id: Int,
val mangaId: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ object Track {
name = it.name,
icon = proxyThumbnailUrl(it.id),
statusList = it.getStatusList(),
statusTextMap = it.getStatusList().associateWith { k -> it.getStatus(k) ?: "" },
statusTextMap = it.getStatusList().associateWith { k -> it.getStatus(k).orEmpty() },
scoreList = it.getScoreList(),
record = record,
)
Expand Down Expand Up @@ -223,7 +223,8 @@ object Track {
}
if (input.scoreString != null) {
val score = tracker.indexToScore(tracker.getScoreList().indexOf(input.scoreString))
recordDb[TrackRecordTable.score] = score.toDouble()
// conversion issues between Float <-> Double so convert to string before double
recordDb[TrackRecordTable.score] = score.toString().toDouble()
}
if (input.startDate != null) {
recordDb[TrackRecordTable.startDate] = input.startDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class Anilist(id: Int) : Tracker(id, "AniList"), DeletableTrackService {
@StringRes
override fun getStatus(status: Int): String? =
when (status) {
READING -> "reading"
PLAN_TO_READ -> "plan_to_read"
COMPLETED -> "completed"
ON_HOLD -> "on_hold"
DROPPED -> "dropped"
REREADING -> "repeating"
READING -> "Reading"
PLAN_TO_READ -> "Plan to read"
COMPLETED -> "Completed"
ON_HOLD -> "On hold"
DROPPED -> "Dropped"
REREADING -> "Rereading"
else -> null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ class MyAnimeList(id: Int) : Tracker(id, "MyAnimeList"), DeletableTrackService {
@StringRes
override fun getStatus(status: Int): String? =
when (status) {
READING -> "reading"
PLAN_TO_READ -> "plan_to_read"
COMPLETED -> "completed"
ON_HOLD -> "on_hold"
DROPPED -> "dropped"
REREADING -> "repeating"
READING -> "Reading"
PLAN_TO_READ -> "Plan to read"
COMPLETED -> "Completed"
ON_HOLD -> "On hold"
DROPPED -> "Dropped"
REREADING -> "Rereading"
else -> null
}

Expand Down

0 comments on commit 9121a63

Please sign in to comment.