Skip to content

Commit

Permalink
feat : 선물 취소 후 뒤로가기 시 변경된 상태 즉시 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
HamBP committed Jul 30, 2024
1 parent 26cc452 commit 0784baa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -57,6 +58,10 @@ fun ReservationsScreen(
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()

LaunchedEffect(Unit) {
viewModel.fetchReservations()
}

Scaffold(
topBar = {
BtBackAppBar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ class ReservationsViewModel @Inject constructor(
MutableStateFlow(ReservationsUiState.Loading)
val uiState: StateFlow<ReservationsUiState> = _uiState.asStateFlow()

init {
fetchReservations()
}

fun fetchReservations() {
reservationRepository.getReservations()
.onStart {
_uiState.update { ReservationsUiState.Loading }
}
.onEach { reservations ->
if (uiState.value == reservations) return@onEach

_uiState.update { ReservationsUiState.Success(reservations) }
}
.catch {
Expand Down

0 comments on commit 0784baa

Please sign in to comment.