Skip to content

Commit ed596c4

Browse files
committed
Update timestamp every 10 seconds
1 parent c12e478 commit ed596c4

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

shared/src/commonMain/kotlin/site/remlit/snowdrop/App.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ fun App() = safe {
273273
}
274274
}
275275

276+
// app really starts here
276277
AppTheme {
277278
Provided {
278279

shared/src/commonMain/kotlin/site/remlit/snowdrop/component/Status.kt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ import androidx.compose.material3.TooltipBox
3333
import androidx.compose.material3.TooltipDefaults
3434
import androidx.compose.material3.rememberTooltipState
3535
import androidx.compose.runtime.Composable
36+
import androidx.compose.runtime.LaunchedEffect
3637
import androidx.compose.runtime.getValue
38+
import androidx.compose.runtime.key
3739
import androidx.compose.runtime.mutableStateOf
3840
import androidx.compose.runtime.remember
3941
import androidx.compose.runtime.rememberCoroutineScope
@@ -57,6 +59,7 @@ import androidx.navigation.toRoute
5759
import com.russhwolf.settings.ExperimentalSettingsApi
5860
import io.kamel.image.KamelImage
5961
import io.kamel.image.asyncPainterResource
62+
import kotlinx.coroutines.delay
6063
import kotlinx.coroutines.launch
6164
import org.jetbrains.compose.resources.painterResource
6265
import org.jetbrains.compose.resources.stringResource
@@ -133,6 +136,7 @@ import snowdrop.shared.generated.resources.show_likes
133136
import snowdrop.shared.generated.resources.show_reactions
134137
import snowdrop.shared.generated.resources.unbookmark
135138
import kotlin.math.ceil
139+
import kotlin.time.Duration.Companion.seconds
136140

137141
@Composable
138142
@OptIn(ExperimentalSettingsApi::class, ExperimentalGridApi::class)
@@ -182,6 +186,14 @@ fun Status(status: Status) {
182186
threadViewMainStatus = inThreadView && navHandler.currentBackStackEntry
183187
?.toRoute<ThreadRoute>()?.id == realStatus.id
184188

189+
var timestampKey by remember { mutableStateOf(0) }
190+
LaunchedEffect(Unit) {
191+
while (true) {
192+
delay(10.seconds)
193+
timestampKey++
194+
}
195+
}
196+
185197

186198
@Composable
187199
fun FooterButton(
@@ -303,10 +315,13 @@ fun Status(status: Status) {
303315
horizontalAlignment = Alignment.CenterHorizontally
304316
) {
305317
Visibility(status.visibility!!)
306-
Text(
307-
"${realStatus.getCreatedAtTimestamp()?.toRelativeString()}",
308-
fontSize = 13.sp
309-
)
318+
319+
key(timestampKey) {
320+
Text(
321+
"${realStatus.getCreatedAtTimestamp()?.toRelativeString()}",
322+
fontSize = 13.sp
323+
)
324+
}
310325
}
311326
}
312327
}

0 commit comments

Comments
 (0)