feat: Add StarredScreen to display starred repositories#13
Conversation
- Created `StarredScreen` and `StarredViewModel` to display user's starred repos. - Updated `ProfileScreen` to wire the navigation to the new Starred route. - Updated `App.kt` to define the new `Route.Starred`. - Added string resource `starred_title`.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Code Review
This pull request introduces a new 'Starred' screen to the application, enabling users to view their starred repositories. The changes include new UI components, a dedicated ViewModel, and updated navigation logic. Key feedback points include addressing a potential resource leak caused by direct ViewModel instantiation in the navigation graph, sharing the GitHubApiClient instance across the app for efficiency, adding unique keys to the LazyColumn for better performance, and moving hardcoded error messages to string resources.
| } | ||
| composable<Route.Starred> { | ||
| StarredScreen( | ||
| viewModel = StarredViewModel(), |
There was a problem hiding this comment.
Instantiating the ViewModel directly inside the composable block causes a new instance to be created on every recomposition. Furthermore, since it's not obtained through a ViewModelStoreOwner (e.g., using viewModel()), its onCleared() method will never be called, leading to a resource leak of the HttpClient inside GitHubApiClient. Consider using a proper ViewModel provider that respects the navigation backstack lifecycle.
| import kotlinx.coroutines.launch | ||
|
|
||
| class StarredViewModel : ViewModel() { | ||
| private val apiClient = GitHubApiClient(createTokenStorage()) |
| contentPadding = PaddingValues(vertical = Dimens.SpacingMedium), | ||
| verticalArrangement = Arrangement.spacedBy(Dimens.SpacingMedium) | ||
| ) { | ||
| items(state.starredRepos) { repo -> |
There was a problem hiding this comment.
It is recommended to provide a unique key for items in a LazyColumn. This helps Compose maintain the state of items correctly during recompositions and list updates, improving performance.
| items(state.starredRepos) { repo -> | |
| items(items = state.starredRepos, key = { it.id }) { repo -> |
| } | ||
| ) | ||
| } | ||
| .onFailure { _uiState.value = StarredUiState.Error(it.message ?: "Unknown error") } |
Added the Starred screen which uses
GitHubApiClient.getStarredReposto show the list of the user's starred repositories. It is now accessible via the Profile screen using the "Starred" navigation row.PR created automatically by Jules for task 3691899229925730222 started by @TheRealAshik