From 0784baa58b9ed0257b6e8570dc8088868a8a3d40 Mon Sep 17 00:00:00 2001 From: algosketch Date: Tue, 30 Jul 2024 17:54:25 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EC=84=A0=EB=AC=BC=20=EC=B7=A8?= =?UTF-8?q?=EC=86=8C=20=ED=9B=84=20=EB=92=A4=EB=A1=9C=EA=B0=80=EA=B8=B0=20?= =?UTF-8?q?=EC=8B=9C=20=EB=B3=80=EA=B2=BD=EB=90=9C=20=EC=83=81=ED=83=9C=20?= =?UTF-8?q?=EC=A6=89=EC=8B=9C=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/screen/reservations/ReservationsScreen.kt | 5 +++++ .../screen/reservations/ReservationsViewModel.kt | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/presentation/src/main/java/com/nexters/boolti/presentation/screen/reservations/ReservationsScreen.kt b/presentation/src/main/java/com/nexters/boolti/presentation/screen/reservations/ReservationsScreen.kt index 2fcce9fa..6e376cdb 100644 --- a/presentation/src/main/java/com/nexters/boolti/presentation/screen/reservations/ReservationsScreen.kt +++ b/presentation/src/main/java/com/nexters/boolti/presentation/screen/reservations/ReservationsScreen.kt @@ -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 @@ -57,6 +58,10 @@ fun ReservationsScreen( ) { val uiState by viewModel.uiState.collectAsStateWithLifecycle() + LaunchedEffect(Unit) { + viewModel.fetchReservations() + } + Scaffold( topBar = { BtBackAppBar( diff --git a/presentation/src/main/java/com/nexters/boolti/presentation/screen/reservations/ReservationsViewModel.kt b/presentation/src/main/java/com/nexters/boolti/presentation/screen/reservations/ReservationsViewModel.kt index 3e3cf723..ecd1f668 100644 --- a/presentation/src/main/java/com/nexters/boolti/presentation/screen/reservations/ReservationsViewModel.kt +++ b/presentation/src/main/java/com/nexters/boolti/presentation/screen/reservations/ReservationsViewModel.kt @@ -23,16 +23,14 @@ class ReservationsViewModel @Inject constructor( MutableStateFlow(ReservationsUiState.Loading) val uiState: StateFlow = _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 {