Skip to content

feat(home): implement sorting functionality for coin list#51

Open
00fanxi wants to merge 2 commits intomainfrom
Feat-sort-coin-list
Open

feat(home): implement sorting functionality for coin list#51
00fanxi wants to merge 2 commits intomainfrom
Feat-sort-coin-list

Conversation

@00fanxi
Copy link
Copy Markdown
Collaborator

@00fanxi 00fanxi commented Jan 27, 2026

관련 이슈

  • Closes #

사전 점검

  • ./gradlew spotlessApply 실행을 완료하였습니다.

작업 개요

  1. SortHeaderItem.kt에서 SortHeaderItem의 텍스트 사이즈를 14 -> 12로 변경하였습니다.
  2. HomeContract.kt에서 enum class SortField를 추가하였습니다.
  3. HomeContract.kt에서 data class HomeUiState에 sortField와 sortDirection을 추가하였습니다.
  4. HomeContract.kt에서 sealed interface HomeEvent에 OnSortClicked를 추가하였습니다.
  5. HomeViewModel.kt에서 observeCoins 함수에서 먼저 sortCoins를 진행하도록 하였습니다.
  6. HomeViewModel.kt에서 updateSort와 sortCoins 함수를 추가하였습니다.
  7. HomeViewModel.kt에서 toggleDirection과 defaultSortDirection 함수를 추가하였습니다.
  8. HomeViewModel.kt에서 handleEvent에 HomeEvent.OnSortClicked 발생시 updateSort를 진행하도록 하였습니다.
  9. HomeScreen.kt에서 SortHeader의 onSymbolClick, onPriceClick, onChangeClick에 이벤트를 연결하고, 각 Sort Ui를 업데이트도 업데이트 하도록 만들었습니다.

상세 내용

1️⃣ UI/UX 변경

Before After
image

2️⃣ 로직 및 아키텍처

  • 기존 방식:
  • 변경 방식:
구분 AS-IS (기존) TO-BE (변경)
정렬 기능 추가

3️⃣ 리팩토링

리뷰어 집중 포인트(참고 사항)

후속 작업

  • [ ]

@00fanxi 00fanxi linked an issue Jan 27, 2026 that may be closed by this pull request
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements interactive sorting for the home coin list and aligns the sort header UI with the new behavior.

Changes:

  • Home state/contract: adds sortField, sortDirection, and OnSortClicked to HomeUiState/HomeEvent so sorting can be driven from the ViewModel.
  • ViewModel logic: wires OnSortClicked into HomeViewModel, introduces sortCoins, and ensures incoming coin data is always sorted according to the current sort field/direction.
  • UI wiring: connects SortHeader in HomeScreen to the new sort state and events, and adjusts SortHeaderItem text size for the sort header labels.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
home/presentation/src/main/java/io/soma/cryptobook/home/presentation/component/sortheader/SortHeaderItem.kt Adjusts sort header label text size (14sp → 12sp) to match updated design.
home/presentation/src/main/java/io/soma/cryptobook/home/presentation/HomeViewModel.kt Adds sort handling (OnSortClicked, updateSort, sortCoins, default/toggle direction) and applies sorting to observed coin lists.
home/presentation/src/main/java/io/soma/cryptobook/home/presentation/HomeScreen.kt Binds sort state from HomeUiState into SortHeader and dispatches OnSortClicked events on header clicks.
home/presentation/src/main/java/io/soma/cryptobook/home/presentation/HomeContract.kt Extends HomeUiState with sort-related fields, introduces SortField enum, and adds OnSortClicked event.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +97 to +100
return if (sortDirection == SortDirection.Desc) {
coins.sortedWith(comparator).asReversed()
}else{
coins.sortedWith(comparator)
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if/else branch uses a }else{ style that differs from the rest of the Kotlin codebase, which consistently uses spaces (} else {, e.g. core/network/src/main/java/io/soma/cryptobook/core/network/base/BaseDataSource.kt:38). For consistency with established formatting conventions (and to keep tools like Spotless/ktlint happy), please add spaces around else here.

Copilot uses AI. Check for mistakes.
Comment on lines 10 to +15
val coins: List<CoinItem> = emptyList(),
val isLoading: Boolean = false,
val errorMsg: String? = null,
val sortField: SortField = SortField.Price,
val sortDirection: SortDirection = SortDirection.Desc,
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HomeUiState now exposes sortDirection using SortDirection from the component.sortheader package, which couples the screen contract to a specific UI component implementation. In other screens (e.g. coin-detail/presentation/src/main/java/io/soma/cryptobook/coindetail/presentation/CoinDetailContract.kt), UI state types stay independent of leaf UI components, so it would be more consistent and maintainable to define SortDirection alongside HomeUiState (or in a shared presentation package) and let SortHeader/SortHeaderItem depend on that instead.

Copilot uses AI. Check for mistakes.
fontFamily = fontFamily,
fontWeight = FontWeight.Bold,
fontSize = 14.sp,
fontSize = 12.sp,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lineHeight = 20.sp 이기 때문에 fontSize를 바꾸는 것은 의미가 없습니다. 바꾼 이유가 있을까요?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

24h change % 부분이 가로로 길이가 초과되서요

@00fanxi 00fanxi self-assigned this Feb 4, 2026
@00fanxi 00fanxi requested a review from acious February 4, 2026 18:08
Comment on lines +79 to +81
onSymbolClick = { onEvent(HomeEvent.OnSortClicked(SortField.Symbol)) },
onPriceClick = { onEvent(HomeEvent.OnSortClicked(SortField.Price)) },
onChangeClick = { onEvent(HomeEvent.OnSortClicked(SortField.Change)) },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

명시적으로 넣는거보다 state.sortField를 인자로 넣어도 되겠네요

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

코인 리스트 정렬

4 participants