Skip to content

Commit 50f8c83

Browse files
committed
[BOOK-244] fix: 도서 상태 변경 로직 수정
1 parent 2cd288f commit 50f8c83

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

feature/detail/src/main/kotlin/com/ninecraft/booket/feature/detail/book/BookDetailPresenter.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class BookDetailPresenter @AssistedInject constructor(
7171
var currentStartIndex by rememberRetained { mutableIntStateOf(START_INDEX) }
7272
var isLastPage by rememberRetained { mutableStateOf(false) }
7373
var currentBookStatus by rememberRetained { mutableStateOf(BookStatus.READING) }
74+
var selectedBookStatus by rememberRetained { mutableStateOf(BookStatus.READING) }
7475
var currentRecordSort by rememberRetained { mutableStateOf(RecordSort.PAGE_NUMBER_ASC) }
7576
var isBookUpdateBottomSheetVisible by rememberRetained { mutableStateOf(false) }
7677
var isRecordSortBottomSheetVisible by rememberRetained { mutableStateOf(false) }
@@ -97,6 +98,8 @@ class BookDetailPresenter @AssistedInject constructor(
9798
val records = readingRecordsDef.await()
9899

99100
bookDetail = detail
101+
currentBookStatus = BookStatus.fromValue(detail.userBookStatus) ?: BookStatus.BEFORE_READING
102+
selectedBookStatus = currentBookStatus
100103
seedsStates = seeds.categories.toImmutableList()
101104
readingRecords = records.content.toPersistentList()
102105
readingRecordsPageInfo = records.page
@@ -214,11 +217,11 @@ class BookDetailPresenter @AssistedInject constructor(
214217
}
215218

216219
is BookDetailUiEvent.OnBookStatusItemSelected -> {
217-
currentBookStatus = event.bookStatus
220+
selectedBookStatus = event.bookStatus
218221
}
219222

220223
is BookDetailUiEvent.OnBookStatusUpdateButtonClick -> {
221-
upsertBook(screen.isbn13, currentBookStatus.value)
224+
upsertBook(screen.isbn13, selectedBookStatus.value)
222225
}
223226

224227
is BookDetailUiEvent.OnRecordSortBottomSheetDismiss -> {
@@ -259,6 +262,7 @@ class BookDetailPresenter @AssistedInject constructor(
259262
isBookUpdateBottomSheetVisible = isBookUpdateBottomSheetVisible,
260263
isRecordSortBottomSheetVisible = isRecordSortBottomSheetVisible,
261264
currentBookStatus = currentBookStatus,
265+
selectedBookStatus = selectedBookStatus,
262266
currentRecordSort = currentRecordSort,
263267
sideEffect = sideEffect,
264268
eventSink = ::handleEvent,

feature/detail/src/main/kotlin/com/ninecraft/booket/feature/detail/book/BookDetailUi.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ internal fun BookDetailUi(
9595
},
9696
bookStatuses = BookStatus.entries.toTypedArray().toImmutableList(),
9797
currentBookStatus = state.currentBookStatus,
98+
selectedBookStatus = state.selectedBookStatus,
9899
onItemSelected = {
99100
state.eventSink(BookDetailUiEvent.OnBookStatusItemSelected(it))
100101
},

feature/detail/src/main/kotlin/com/ninecraft/booket/feature/detail/book/BookDetailUiState.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ data class BookDetailUiState(
3232
val currentStartIndex: Int = 1,
3333
val isLastPage: Boolean = false,
3434
val currentBookStatus: BookStatus = BookStatus.BEFORE_READING,
35+
val selectedBookStatus: BookStatus = BookStatus.BEFORE_READING,
3536
val currentRecordSort: RecordSort = RecordSort.PAGE_NUMBER_ASC,
3637
val isBookUpdateBottomSheetVisible: Boolean = false,
3738
val isRecordSortBottomSheetVisible: Boolean = false,

feature/detail/src/main/kotlin/com/ninecraft/booket/feature/detail/book/component/BookUpdateBottomSheet.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ internal fun BookUpdateBottomSheet(
4848
onCloseButtonClick: () -> Unit,
4949
bookStatuses: ImmutableList<BookStatus>,
5050
currentBookStatus: BookStatus?,
51+
selectedBookStatus: BookStatus,
5152
onItemSelected: (BookStatus) -> Unit,
5253
onBookUpdateButtonClick: () -> Unit,
5354
modifier: Modifier = Modifier,
@@ -94,9 +95,9 @@ internal fun BookUpdateBottomSheet(
9495
bookStatuses.forEach { item ->
9596
BookStatusItem(
9697
item = item,
97-
selected = item == currentBookStatus,
98+
selected = item == selectedBookStatus,
9899
onClick = {
99-
if (item != currentBookStatus) {
100+
if (item != selectedBookStatus) {
100101
onItemSelected(item)
101102
}
102103
},
@@ -112,7 +113,7 @@ internal fun BookUpdateBottomSheet(
112113
sizeStyle = largeButtonStyle,
113114
colorStyle = ReedButtonColorStyle.PRIMARY,
114115
modifier = Modifier.fillMaxWidth(),
115-
enabled = currentBookStatus != null,
116+
enabled = currentBookStatus != selectedBookStatus,
116117
text = stringResource(R.string.book_update_ok),
117118
)
118119
Spacer(modifier = Modifier.height(ReedTheme.spacing.spacing4))
@@ -167,6 +168,7 @@ private fun BookUpdateBottomSheetPreview() {
167168
onCloseButtonClick = {},
168169
bookStatuses = BookStatus.entries.toImmutableList(),
169170
currentBookStatus = null,
171+
selectedBookStatus = BookStatus.BEFORE_READING,
170172
onItemSelected = {},
171173
onBookUpdateButtonClick = {},
172174
)

0 commit comments

Comments
 (0)