-
Notifications
You must be signed in to change notification settings - Fork 108
[HackDay][Horizon] Refactor refresh logic #3324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This commit refactors the centralized HorizonEventHandler into individual feature-specific event handlers to improve code organization and reduce coupling between features. Changes: - Created DashboardEventHandler for dashboard-specific events - Created InboxEventHandler for inbox-specific events - Created LearnEventHandler for learn-specific events - Removed global HorizonEventHandler dependency from ViewModels - Updated ViewModels to use feature-specific event handlers - Updated Screens to pass feature-specific event handlers to ViewModels - Fixed test files to include required event handler parameters Benefits: - Better separation of concerns - Reduced coupling between unrelated features - More maintainable and testable code - Each feature manages its own refresh/event logic All unit tests pass successfully. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
📊 Code Coverage Report✅ Student
✅ Teacher
✅ Pandautils
📈 Overall Average
|
andrasmaczak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks better, but I think it could be improved to only refresh the widgets that needs to be refreshed. For example if the user selects an announcement, we only need to refresh that widget, don't need to refresh every other widget.
Code Review: Refactor Refresh LogicSummaryThis PR refactors the refresh logic in the Horizon module by introducing event-based communication using event handlers instead of relying on Navigation's Positive Aspects ✅Architecture Improvements
Code Quality
Areas for Improvement 🔍1. Race Condition Risk in DashboardViewModel:46-62dashboardEventHandler.events.collect { event ->
when (event) {
is DashboardEvent.DashboardRefresh -> {
_uiState.update { it.copy(externalShouldRefresh = true) }
refresh()
delay(50) // Give some time for the refresh to start
_uiState.update { it.copy(externalShouldRefresh = false) }
}Issue: The hardcoded Recommendation: Consider using a state machine or callback-based approach: is DashboardEvent.DashboardRefresh -> {
_uiState.update { it.copy(externalShouldRefresh = true) }
viewModelScope.launch {
refresh()
// Reset after refresh completes, not after arbitrary delay
_uiState.update { it.copy(externalShouldRefresh = false) }
}
}2. Error Handling in Event CollectorsMultiple ViewModels collect events but don't handle potential exceptions:
Recommendation: Wrap event collectors in try-catch or use 3. Event Handler Testing GapWhile ViewModels are tested with event handlers, the event handlers themselves lack unit tests. Consider adding tests for:
4. Missing newline at end of file
5. Potential Memory Leak in DashboardScreen:112-122LaunchedEffect(uiState.snackbarMessage) {
if (uiState.snackbarMessage != null) {
snackbarHostState.showSnackbar(
message = uiState.snackbarMessage,
)
uiState.onSnackbarDismiss()
}
}Issue: If Recommendation: Consider using a consumable event pattern or checking if the snackbar is already dismissed before calling 6. Inconsistent Event Naming
Recommendation: Consider consistent naming like: sealed interface DashboardEvent {
data object Refresh : DashboardEvent
data object RefreshProgress : DashboardEvent
data class ShowSnackbar(val message: String) : DashboardEvent
}Security Considerations 🔒No security concerns identified. The event handlers don't handle sensitive data or expose security vulnerabilities. Performance Considerations ⚡
Test Coverage 📊Strengths:
Gaps:
Minor Issues
Recommendations Summary
Overall AssessmentThis is a well-executed refactoring that significantly improves the architecture. The event-driven approach is cleaner and more maintainable than the previous SavedStateHandle pattern. With the minor improvements suggested above, this will be production-ready code. Recommendation: Approve with minor changes requested, particularly addressing the Review generated by Claude Code - Hackday PR Review |
Pull Request Review: [HackDay][Horizon] Refactor refresh logicSummaryThis PR successfully refactors the refresh logic from a SavedStateHandle-based approach to an event-driven architecture using dedicated EventHandler classes. This is a solid architectural improvement that eliminates tight coupling between screens and improves code maintainability. ✅ StrengthsArchitecture & Design
Code Quality
Test Coverage
|
No description provided.