-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(chat): use new popup model for chat info (#454)
- Loading branch information
Showing
16 changed files
with
241 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 0 additions & 67 deletions
67
...in/kotlin/fr/outadoc/justchatting/feature/chat/presentation/StreamAndUserInfoViewModel.kt
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
.../commonMain/kotlin/fr/outadoc/justchatting/feature/chat/presentation/UserInfoViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package fr.outadoc.justchatting.feature.chat.presentation | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import fr.outadoc.justchatting.feature.shared.domain.TwitchRepository | ||
import fr.outadoc.justchatting.feature.shared.domain.model.User | ||
import fr.outadoc.justchatting.utils.logging.logError | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.onStart | ||
import kotlinx.coroutines.launch | ||
|
||
internal class UserInfoViewModel( | ||
private val twitchRepository: TwitchRepository, | ||
) : ViewModel() { | ||
|
||
sealed class State { | ||
data object Loading : State() | ||
data class Error(val throwable: Throwable) : State() | ||
data class Loaded(val user: User) : State() | ||
} | ||
|
||
private val _state = MutableStateFlow<State>(State.Loading) | ||
val state = _state.asStateFlow() | ||
|
||
fun load(userId: String) { | ||
viewModelScope.launch { | ||
twitchRepository | ||
.getUserById(userId) | ||
.map { userResult -> | ||
userResult.fold( | ||
onSuccess = { user -> | ||
State.Loaded(user) | ||
}, | ||
onFailure = { exception -> | ||
logError<UserInfoViewModel>(exception) { | ||
"Error while loading user $userId: $exception" | ||
} | ||
State.Error(exception) | ||
}, | ||
) | ||
} | ||
.onStart { emit(State.Loading) } | ||
.collect(_state) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.