Skip to content

Commit

Permalink
Password Persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
SAUL committed Oct 23, 2024
1 parent 65a1004 commit a5c2986
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/main/kotlin/ui/screens/SecVaultScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class SecVaultScreen : Screen {
val secVaultState by screenModel.secVaultState.collectAsState()
val toaster = rememberToasterState()

LaunchedEffect(Unit) {
screenModel.init()
}

Toaster(
state = toaster,
alignment = Alignment.TopEnd,
Expand Down
28 changes: 14 additions & 14 deletions src/main/kotlin/viewmodel/SecVaultScreenModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import repository.password.projection.PasswordSummary

class SecVaultScreenModel(
private val passwordRepository: PasswordRepository,
dispatcher: CoroutineDispatcher = Dispatchers.IO
private val dispatcher: CoroutineDispatcher = Dispatchers.IO
) : ScreenModel {

private val _secVaultState = MutableStateFlow<UiState<Any>>(UiState.Idle)
Expand All @@ -39,7 +39,19 @@ class SecVaultScreenModel(
private val _passwordItems = MutableStateFlow<List<PasswordSummary>>(emptyList())
val passwordItems: StateFlow<List<PasswordSummary>> = _passwordItems.asStateFlow()

init {
fun selectMenuItem(item: DefaultMenuItem) {
_selectedMenuItem.value = item
}

fun selectSortItem(item: PasswordSort) {
_selectedSortItem.value = item
}

fun clearError() {
_secVaultState.value = UiState.Idle
}

fun init() {
screenModelScope.launch(dispatcher) {
_secVaultState.value = UiState.Loading
loadPasswords(PasswordSort.NAME)
Expand All @@ -59,18 +71,6 @@ class SecVaultScreenModel(
}
}

fun selectMenuItem(item: DefaultMenuItem) {
_selectedMenuItem.value = item
}

fun selectSortItem(item: PasswordSort) {
_selectedSortItem.value = item
}

fun clearError() {
_secVaultState.value = UiState.Idle
}

private suspend fun loadPasswords(sort: PasswordSort) {
_passwordItems.value = when (val passwords = passwordRepository.findSummaries(sort)) {
is Result.Success -> {
Expand Down

0 comments on commit a5c2986

Please sign in to comment.