style(gtk): clean up search code slightly

This commit is contained in:
Johannes Frohnmeyer 2024-06-29 17:47:12 +02:00
parent c1e729a0fa
commit 9b55a3f08d
Signed by: Johannes
GPG Key ID: E76429612C2929F4

View File

@ -127,19 +127,18 @@ class ModsTab(window: InstanceSettingsWindow) : SettingsTab<Leaflet, InstanceSet
VoidFuture(ForkJoinPool.commonPool().submit {
val sources: List<ModSource> = when (page) {
Page.CURSEFORGE -> {
val cf = CurseforgeApi.search(instance.gameVersion, currentSearchString, 0, "Popularity") //TODO allow user to choose sort mode
cf.mapNotNull {
//TODO allow user to choose sort mode
CurseforgeApi.search(instance.gameVersion, currentSearchString, 0, "Popularity").mapNotNull { cf ->
if (isCancelled) return@submit
val file = it.latestFilesIndexes.firstOrNull { it.gameVersion == instance.gameVersion } //TODO support compatible minor versions
val file = cf.latestFilesIndexes.firstOrNull { it.gameVersion == instance.gameVersion } //TODO support compatible minor versions
if (file == null) null
else CurseforgeModSource(it.id, file.fileId)
else CurseforgeModSource(cf.id, file.fileId)
}
}
Page.MODRINTH -> {
val mr = ModrinthApi.search(currentSearchString, 0, instance.gameVersion, ModrinthProjectType.mod).hits
mr.mapNotNull {
ModrinthApi.search(currentSearchString, 0, instance.gameVersion, ModrinthProjectType.mod).hits.mapNotNull { mr ->
if (isCancelled) return@submit
val file = ModrinthApi.getLatestVersions(it.project_id, instance.gameVersion).best
val file = ModrinthApi.getLatestVersions(mr.project_id, instance.gameVersion).best
if (file == null) null
else ModrinthModSource(file.id)
}