Skip to content

create first issue#288

Merged
rainxchzed merged 6 commits intoOpenHub-Store:mainfrom
bilalahmadsheikh:copilot/create-first-issue
Mar 7, 2026
Merged

create first issue#288
rainxchzed merged 6 commits intoOpenHub-Store:mainfrom
bilalahmadsheikh:copilot/create-first-issue

Conversation

@bilalahmadsheikh
Copy link
Contributor

@bilalahmadsheikh bilalahmadsheikh commented Mar 3, 2026

fixed import format and added sort order direction

Summary by CodeRabbit

  • New Features
    • Added sort order selection enabling users to choose ascending or descending direction for search result sorting.
    • Enhanced sort preferences dialog now provides comprehensive sorting control by integrating sort criteria (most stars, most forks, best match) with new sort-order options in a dedicated interface.

Copilot AI and others added 3 commits March 3, 2026 04:54
… sort UI

- Create SortOrder enum in domain layer with toGithubParam() method
- Update SortBy.toGithubParams() to toGithubSortParam() returning only field name
- Update SearchRepository interface and implementation to accept SortOrder
- Add SortOrder to SearchState and SearchAction
- Handle new sort actions in SearchViewModel
- Update SortByBottomSheet with sort order toggle chips
- Wire sort button and dialog into SearchRoot
- Add string resources for sort order labels

Co-authored-by: bilalahmadsheikh <169471620+bilalahmadsheikh@users.noreply.github.com>
Co-authored-by: bilalahmadsheikh <169471620+bilalahmadsheikh@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 3, 2026 05:13
Copy link

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

This PR extends the search feature’s sorting capabilities by introducing an explicit sort-order (ascending/descending) alongside existing sort-by options, and wires it through the UI → ViewModel → repository → GitHub request layer.

Changes:

  • Add SortOrder domain model and presentation label mapping for localization.
  • Update search state/actions/viewmodel and repository interface/impl to accept and apply sortOrder.
  • Add UI controls for selecting sort order and localize existing “Close” / “Sort by” strings.

Reviewed changes

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

Show a summary per file
File Description
feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/utils/SortOrderMapper.kt Adds localized labels for SortOrder.
feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/components/SortByBottomSheet.kt Adds sort-order selection UI alongside sort-by options.
feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/SearchViewModel.kt Passes sortOrder into searches and reacts to OnSortOrderSelected.
feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/SearchState.kt Stores selected sort order and sort dialog visibility.
feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/SearchRoot.kt Wires sort dialog visibility and adds a “Sort” chip entry point.
feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/SearchAction.kt Introduces actions for sort order selection and dialog toggling.
feature/search/domain/src/commonMain/kotlin/zed/rainxch/domain/repository/SearchRepository.kt Extends repository API to include sortOrder.
feature/search/domain/src/commonMain/kotlin/zed/rainxch/domain/model/SortOrder.kt Adds SortOrder enum and GitHub query param mapping.
feature/search/domain/src/commonMain/kotlin/zed/rainxch/domain/model/SortBy.kt Refactors GitHub sort param mapping to return sort-only.
feature/search/data/src/commonMain/kotlin/zed/rainxch/search/data/repository/SearchRepositoryImpl.kt Applies sort/order params and adds sortOrder to caching key.
core/presentation/src/commonMain/composeResources/values/strings.xml Adds localized strings for sort order and “Sort” label.
Comments suppressed due to low confidence (1)

feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/components/SortByBottomSheet.kt:38

  • SortByBottomSheet uses AlertDialog rather than a ModalBottomSheet, so the name is misleading (and inconsistent with LanguageFilterBottomSheet). Consider renaming this composable to SortByDialog (or switching implementation to a bottom sheet) to avoid confusing callers and future maintenance issues.
fun SortByBottomSheet(
    sortByOptions: List<SortBy>,
    selectedSortBy: SortBy,
    selectedSortOrder: SortOrder,
    onSortBySelected: (SortBy) -> Unit,
    onSortOrderSelected: (SortOrder) -> Unit,
    onDismissRequest: () -> Unit,
    modifier: Modifier = Modifier
) {
    AlertDialog(
        onDismissRequest = onDismissRequest,

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

): String {
val queryHash = query.trim().lowercase().hashCode().toUInt().toString(16)
return "search:$queryHash:${platform.name}:${language.name}:${sortBy.name}:page$page"
return "search:$queryHash:${platform.name}:${language.name}:${sortBy.name}:${sortOrder.name}:page$page"
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

searchCacheKey(...) includes sortOrder unconditionally, but the request only applies sortOrder when sortBy.toGithubSortParam() is non-null. For SortBy.BestMatch, this will create distinct cache keys (and cache entries / misses) for ascending vs descending even though the upstream request is identical. Consider omitting/normalizing sortOrder in the cache key when sortBy doesn’t produce a sort param.

Suggested change
return "search:$queryHash:${platform.name}:${language.name}:${sortBy.name}:${sortOrder.name}:page$page"
val effectiveSortOrder = if (sortBy.toGithubSortParam() == null) {
"NONE"
} else {
sortOrder.name
}
return "search:$queryHash:${platform.name}:${language.name}:${sortBy.name}:$effectiveSortOrder:page$page"

Copilot uses AI. Check for mistakes.
Comment on lines +74 to +91
Spacer(Modifier.height(4.dp))

Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically
) {
SortOrder.entries.forEach { order ->
FilterChip(
selected = order == selectedSortOrder,
onClick = { onSortOrderSelected(order) },
label = {
Text(
text = stringResource(order.label()),
style = MaterialTheme.typography.bodyMedium
)
}
)
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

Sort order selection is offered even when selectedSortBy is BestMatch, but the data layer only sends the order param when sort is non-null. That means changing sort order while on BestMatch has no effect (but still triggers a search), which is confusing UX. Consider hiding/disable the sort-order chips when selectedSortBy == SortBy.BestMatch (or otherwise indicate it has no effect).

Suggested change
Spacer(Modifier.height(4.dp))
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically
) {
SortOrder.entries.forEach { order ->
FilterChip(
selected = order == selectedSortOrder,
onClick = { onSortOrderSelected(order) },
label = {
Text(
text = stringResource(order.label()),
style = MaterialTheme.typography.bodyMedium
)
}
)
if (selectedSortBy != SortBy.BestMatch) {
Spacer(Modifier.height(4.dp))
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically
) {
SortOrder.entries.forEach { order ->
FilterChip(
selected = order == selectedSortOrder,
onClick = { onSortOrderSelected(order) },
label = {
Text(
text = stringResource(order.label()),
style = MaterialTheme.typography.bodyMedium
)
}
)
}

Copilot uses AI. Check for mistakes.
@rainxchzed
Copy link
Member

rainxchzed commented Mar 4, 2026

Hey @bilalahmadsheikh Thank you for your contribution, all the changes look quite good to me but i would like that you would also add localized strings for other languages to so all the users will have sort labels in their local language 👍

@rainxchzed
Copy link
Member

@bilalahmadsheikh When you finish with this please ping me here so i could review and merge 👍

@bilalahmadsheikh
Copy link
Contributor Author

@rainxchzed I have completed.

@rainxchzed
Copy link
Member

Cool! Let it get merged then, thanks a lot for your contribution!

@rainxchzed rainxchzed merged commit 658b3c4 into OpenHub-Store:main Mar 7, 2026
1 check was pending
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 7, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a94f8186-695e-48ef-84ec-101c16b345ca

📥 Commits

Reviewing files that changed from the base of the PR and between 8a9b476 and ffbbd3b.

📒 Files selected for processing (11)
  • core/presentation/src/commonMain/composeResources/values/strings.xml
  • feature/search/data/src/commonMain/kotlin/zed/rainxch/search/data/repository/SearchRepositoryImpl.kt
  • feature/search/domain/src/commonMain/kotlin/zed/rainxch/domain/model/SortBy.kt
  • feature/search/domain/src/commonMain/kotlin/zed/rainxch/domain/model/SortOrder.kt
  • feature/search/domain/src/commonMain/kotlin/zed/rainxch/domain/repository/SearchRepository.kt
  • feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/SearchAction.kt
  • feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/SearchRoot.kt
  • feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/SearchState.kt
  • feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/SearchViewModel.kt
  • feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/components/SortByBottomSheet.kt
  • feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/utils/SortOrderMapper.kt

Walkthrough

A new sort order feature is implemented by introducing a SortOrder enum with Ascending/Descending options, refactoring SortBy to separate sort direction concerns, and extending the presentation layer with UI controls, state management, and repository parameter passing to support sort order selection.

Changes

Cohort / File(s) Summary
String Resources
core/presentation/src/commonMain/composeResources/values/strings.xml
Added three new string resources for sort functionality: sort_order_descending, sort_order_ascending, and sort_label.
Domain Model - Sort Refactoring
feature/search/domain/src/commonMain/kotlin/zed/rainxch/domain/model/SortBy.kt, feature/search/domain/src/commonMain/kotlin/zed/rainxch/domain/model/SortOrder.kt
Introduced new SortOrder enum with Descending and Ascending constants and toGithubParam() method. Refactored SortBy.toGithubParams() to toGithubSortParam() returning only the sort parameter ("stars", "forks", or null) without direction.
Domain Repository Interface
feature/search/domain/src/commonMain/kotlin/zed/rainxch/domain/repository/SearchRepository.kt
Updated searchRepositories() method signature to include sortOrder: SortOrder parameter.
Data Layer Implementation
feature/search/data/src/commonMain/kotlin/zed/rainxch/search/data/repository/SearchRepositoryImpl.kt
Added sortOrder parameter to searchRepositories() and searchCacheKey() methods. Updated cache key generation and search query construction to use sortOrder.toGithubParam() for the order parameter.
Presentation Actions & State
feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/SearchAction.kt, feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/SearchState.kt
Added new actions OnSortOrderSelected and OnToggleSortByDialogVisibility. Extended SearchState with selectedSortOrder (default Descending), isSortByDialogVisible (default false), and autoDetectClipboardEnabled (default true) properties.
Presentation View Model
feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/SearchViewModel.kt
Added handlers for new sort order actions that update state, reset pagination, trigger search flow, and toggle dialog visibility. Updated repository search call to pass sortOrder parameter.
Presentation UI & Components
feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/SearchRoot.kt, feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/components/SortByBottomSheet.kt
Updated SearchRoot to display sort option row with toggle and SortByBottomSheet when visible. Enhanced SortByBottomSheet with selectedSortOrder and onSortOrderSelected callback, added FilterChip-based sort order selection UI with HorizontalDivider separation, and replaced hardcoded strings with localized resources.
Presentation Utils
feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/utils/SortOrderMapper.kt
Created extension function SortOrder.label() mapping Descending to sort_order_descending and Ascending to sort_order_ascending string resources.

Sequence Diagram

sequenceDiagram
    participant User as User
    participant UI as SearchUI
    participant VM as SearchViewModel
    participant Repo as SearchRepository
    participant Data as SearchRepositoryImpl
    
    User->>UI: Click sort order button
    UI->>VM: dispatch OnToggleSortByDialogVisibility
    VM->>VM: toggle isSortByDialogVisible
    UI->>UI: display SortByBottomSheet
    
    User->>UI: select sort order (Ascending/Descending)
    UI->>VM: dispatch OnSortOrderSelected(sortOrder)
    VM->>VM: update selectedSortOrder
    VM->>VM: reset to page 1
    VM->>VM: cancel debounce timer
    
    VM->>Repo: searchRepositories(..., sortOrder)
    Repo->>Data: searchRepositories(..., sortOrder)
    Data->>Data: generate cache key with sortOrder
    Data->>Data: construct query with sortOrder.toGithubParam()
    Data-->>Repo: return search results
    Repo-->>VM: emit PaginatedDiscoveryRepositories
    VM->>VM: update search results state
    VM-->>UI: emit new state
    UI-->>User: display filtered results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related issues

  • Good First Issue #289 — This PR implements the exact same code-level additions (SortOrder enum, toGithubSortParam refactor, repository signature updates, presentation actions/state/UI, and resource strings) addressing the same sort order selection feature.

Possibly related PRs

Poem

🐰 A sort order hops along the flow,
From UI tap to search below,
Ascending, descending, we choose with care,
Split from SortBy, now a pair! 🔄✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

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