Skip to content

Commit

Permalink
[FEATURE]#74 : 차단 시 프로그래스 바 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjaino committed Aug 5, 2024
1 parent 233afe5 commit ef495a0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.bff.wespot.entire.screen.screen

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
Expand All @@ -14,6 +17,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -99,6 +103,12 @@ fun BlockListScreen(
}
}

if (state.isLoading) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
CircularProgressIndicator()
}
}

LaunchedEffect(Unit) {
action(EntireAction.OnBlockListScreenEntered)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ data class EntireUiState(
val blockedMessageList: List<BlockedMessage> = listOf(),
val unBlockList: List<Int> = listOf(),
val unBlockMessageId: Int = -1,
val isLoading: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,22 @@ class EntireViewModel @Inject constructor(
}

private fun unblockMessage() = intent {
val messageId = state.unBlockMessageId
if (state.unBlockList.contains(messageId).not()) {
val updatedList = state.unBlockList.toMutableList().apply { add(messageId) }
reduce { state.copy(unBlockList = updatedList) }
}
reduce { state.copy(isLoading = true) }

viewModelScope.launch {
messageStorageRepository.blockMessage(messageId)
.onFailure {
Timber.e(it)
// 차단 해제 실패 시, 차단 해제된 목록에서 삭제
if (state.unBlockList.contains(messageId)) {
messageStorageRepository.blockMessage(state.unBlockMessageId)
.onSuccess {
if (state.unBlockList.contains(state.unBlockMessageId).not()) {
val updatedList = state.unBlockList.toMutableList().apply {
remove(messageId)
add(state.unBlockMessageId)
}
reduce { state.copy(unBlockList = updatedList) }
reduce { state.copy(unBlockList = updatedList, isLoading = false) }
}
}
.onFailure {
reduce { state.copy(isLoading = false) }
Timber.e(it)
}
}
}

Expand Down

0 comments on commit ef495a0

Please sign in to comment.