Skip to content

Commit bf290fa

Browse files
committed
[refactor] #55: ViewModel이 onCleared 시점에 좋아요 상태를 업데이트하도록 변경
ViewModel이 `onCleared` 될 때, 사진의 현재 좋아요 상태(`isFavorite`)와 초기 좋아요 상태(`committedFavorite`)를 비교합니다. 두 상태가 다를 경우, `photoRepository.updateFavorite`를 호출하여 변경된 좋아요 상태를 서버에 반영합니다. 이를 통해 사용자가 화면을 벗어났을 때 좋아요 상태가 최종적으로 업데이트되도록 보장합니다.
1 parent ec0ea59 commit bf290fa

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

feature/archive/impl/src/main/kotlin/com/neki/android/feature/archive/impl/photo_detail/PhotoDetailViewModel.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,17 @@ class PhotoDetailViewModel @AssistedInject constructor(
120120
}
121121
}
122122
}
123+
124+
override fun onCleared() {
125+
super.onCleared()
126+
127+
val currentFavorite = store.uiState.value.photo.isFavorite
128+
val committedFavorite = store.uiState.value.committedFavorite
129+
130+
if (currentFavorite != committedFavorite) {
131+
applicationScope.launch {
132+
photoRepository.updateFavorite(photo.id, currentFavorite)
133+
}
134+
}
135+
}
123136
}

0 commit comments

Comments
 (0)