Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.plcoding.run.presentation.run_overview

sealed interface RunOverviewEvent {
data object OnLogout : RunOverviewEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.plcoding.core.presentation.designsystem.components.RuniqueFloatingAct
import com.plcoding.core.presentation.designsystem.components.RuniqueScaffold
import com.plcoding.core.presentation.designsystem.components.RuniqueToolbar
import com.plcoding.core.presentation.designsystem.components.util.DropDownItem
import com.plcoding.core.presentation.ui.ObserveAsEvents
import com.plcoding.run.presentation.R
import com.plcoding.run.presentation.run_overview.components.RunListItem
import org.koin.androidx.compose.koinViewModel
Expand All @@ -40,13 +41,18 @@ fun RunOverviewScreenRoot(
onAnalyticsClick: () -> Unit,
viewModel: RunOverviewViewModel = koinViewModel(),
) {
ObserveAsEvents(flow = viewModel.events) { event ->
when (event) {
RunOverviewEvent.OnLogout -> onLogoutClick()
}
}

RunOverviewScreen(
state = viewModel.state,
onAction = { action ->
when(action) {
RunOverviewAction.OnAnalyticsClick -> onAnalyticsClick()
RunOverviewAction.OnStartClick -> onStartRunClick()
RunOverviewAction.OnLogoutClick -> onLogoutClick()
else -> Unit
}
viewModel.onAction(action)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import com.plcoding.core.domain.run.RunRepository
import com.plcoding.core.domain.run.SyncRunScheduler
import com.plcoding.run.presentation.run_overview.mapper.toRunUi
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch
import kotlin.time.Duration.Companion.minutes

Expand All @@ -25,6 +27,9 @@ class RunOverviewViewModel(
var state by mutableStateOf(RunOverviewState())
private set

private val eventChannel = Channel<RunOverviewEvent>()
val events = eventChannel.receiveAsFlow()

init {
viewModelScope.launch {
syncRunScheduler.scheduleSync(
Expand Down Expand Up @@ -62,6 +67,7 @@ class RunOverviewViewModel(
runRepository.deleteAllRuns()
runRepository.logout()
sessionStorage.set(null)
eventChannel.send(RunOverviewEvent.OnLogout)
}
}
}