Skip to content

Commit 54f0dcb

Browse files
committed
Updated to new S3 backed contributors list
1 parent e64b4e1 commit 54f0dcb

File tree

3 files changed

+15
-44
lines changed

3 files changed

+15
-44
lines changed

app/src/commonMain/kotlin/service/DefaultWebClient.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const val FIND_URL = "https://oni-data.stefanoltmann.de"
6262

6363
const val SEARCH_INDEX_URL = "https://oni-search.stefanoltmann.de"
6464
const val COUNT_URL = "$SEARCH_INDEX_URL/count"
65+
const val CONTRIBUTORS_URL = "$SEARCH_INDEX_URL/contributors"
6566

6667
const val INGEST_SERVER_URL = "https://ingest.mapsnotincluded.org"
6768
const val REQUEST_URL = "$INGEST_SERVER_URL/request-coordinate"
@@ -472,9 +473,9 @@ object DefaultWebClient : WebClient {
472473
return success
473474
}
474475

475-
override suspend fun findContributors(): List<Contributor> {
476+
override suspend fun findContributors(): Map<String, Long> {
476477

477-
val response = httpClient.get("$INGEST_SERVER_URL/contributors") {
478+
val response = httpClient.get(CONTRIBUTORS_URL) {
478479
accept(ContentType.Application.Json)
479480
}
480481

@@ -483,7 +484,7 @@ object DefaultWebClient : WebClient {
483484

484485
try {
485486

486-
val contributors: List<Contributor> = response.body()
487+
val contributors: Map<String, Long> = response.body()
487488

488489
println("[WEBCLIENT] Found ${contributors.size} contributors.")
489490

app/src/commonMain/kotlin/service/WebClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ interface WebClient {
5555

5656
suspend fun setUsername(username: String): Boolean
5757

58-
suspend fun findContributors(): List<Contributor>
58+
suspend fun findContributors(): Map<String, Long>
5959

6060
suspend fun getLastModifiedMillis(url: String): Long?
6161

app/src/commonMain/kotlin/ui/LeaderboardViewList.kt

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ import androidx.compose.material3.MaterialTheme
3838
import androidx.compose.material3.Text
3939
import androidx.compose.runtime.Composable
4040
import androidx.compose.runtime.MutableState
41-
import androidx.compose.runtime.mutableStateOf
4241
import androidx.compose.runtime.produceState
43-
import androidx.compose.runtime.remember
4442
import androidx.compose.ui.Alignment
4543
import androidx.compose.ui.Modifier
4644
import androidx.compose.ui.graphics.Color
@@ -54,11 +52,8 @@ import io.github.stefanoltmann.app.generated.resources.uiLeaderBoardExplainer
5452
import io.github.stefanoltmann.app.generated.resources.uiLeaderBoardRank
5553
import io.github.stefanoltmann.app.generated.resources.uiLeaderBoardUsername
5654
import io.github.stefanoltmann.app.generated.resources.uiLoading
57-
import kotlin.time.Clock
5855
import kotlin.time.ExperimentalTime
5956
import kotlinx.coroutines.CancellationException
60-
import kotlinx.coroutines.delay
61-
import kotlinx.coroutines.isActive
6257
import org.jetbrains.compose.resources.stringResource
6358
import service.DefaultWebClient
6459
import ui.theme.DefaultSpacer
@@ -68,9 +63,6 @@ import ui.theme.defaultPadding
6863
import ui.theme.defaultRoundedCornerShape
6964
import ui.theme.doubleSpacing
7065
import ui.theme.lightGray
71-
import util.formatDate
72-
73-
const val CONTRIBUTOR_LIST_UPDATE_INTERVAL_MS: Long = 60000
7466

7567
private val contributorListFontSize = 20.sp
7668

@@ -81,24 +73,15 @@ fun LeaderboardViewList(
8173
errorMessage: MutableState<String?>
8274
) {
8375

84-
val lastRefreshTime = remember { mutableStateOf(0L) }
85-
8676
val contributorsState = produceState(emptyList()) {
8777

8878
try {
8979

90-
while (isActive) {
91-
92-
lastRefreshTime.value = Clock.System.now().toEpochMilliseconds()
93-
94-
value = DefaultWebClient.findContributors().map {
95-
it.copy(
96-
username = steamIdToUsernameMap[it.steamIdHash]
97-
)
80+
value = DefaultWebClient.findContributors()
81+
.map {
82+
it.key to it.value
9883
}
99-
100-
delay(CONTRIBUTOR_LIST_UPDATE_INTERVAL_MS)
101-
}
84+
.sortedByDescending { it.second }
10285

10386
} catch (_: CancellationException) {
10487

@@ -144,21 +127,6 @@ fun LeaderboardViewList(
144127

145128
DefaultSpacer()
146129

147-
Text(
148-
text = formatDate(lastRefreshTime.value),
149-
style = MaterialTheme.typography.bodyMedium,
150-
color = lightGray,
151-
textAlign = TextAlign.Center,
152-
modifier = Modifier
153-
.background(
154-
Color.Black,
155-
defaultRoundedCornerShape
156-
)
157-
.defaultPadding()
158-
)
159-
160-
DefaultSpacer()
161-
162130
Row {
163131

164132
FillSpacer()
@@ -215,7 +183,7 @@ fun LeaderboardViewList(
215183
modifier = Modifier.padding(doubleSpacing)
216184
) {
217185

218-
itemsIndexed(contributors) { index, contributor ->
186+
itemsIndexed(contributors) { index, entry ->
219187

220188
val rank = index + 1
221189

@@ -239,11 +207,13 @@ fun LeaderboardViewList(
239207

240208
DoubleSpacer()
241209

210+
val name = steamIdToUsernameMap[entry.first] ?: "Anonymous"
211+
242212
Text(
243-
text = contributor.username ?: "Anonymous",
213+
text = name,
244214
style = MaterialTheme.typography.bodyLarge,
245215
fontSize = contributorListFontSize,
246-
color = if (contributor.username == null)
216+
color = if (name == "Anonymous")
247217
lightGray.copy(0.3F)
248218
else
249219
lightGray,
@@ -255,7 +225,7 @@ fun LeaderboardViewList(
255225
DoubleSpacer()
256226

257227
Text(
258-
text = contributor.mapCount.toString(),
228+
text = entry.second.toString(),
259229
style = MaterialTheme.typography.bodyLarge,
260230
fontSize = contributorListFontSize,
261231
color = lightGray,

0 commit comments

Comments
 (0)