feat: Show torrent count for each filter state in drawer (#109)#196
feat: Show torrent count for each filter state in drawer (#109)#196ananyaaa66 wants to merge 1 commit intoCCExtractor:mainfrom
Conversation
…#109) - Add getFilterCount() to TorrentService reusing existing _filterList logic - Expose filter count in DrawerViewModel - Add trailing count badge to FilterTile widget with themed styling - Count updates reactively as torrents change state Closes CCExtractor#109
📝 WalkthroughWalkthroughThis change adds filter count display functionality to the app's drawer. A new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
lib/ui/widgets/dumb_widgets/filter_tile_list_widgets.dart (1)
40-47: Consider a minimum width for visual consistency (optional).The badge width varies with digit count. For consistent alignment across filter tiles, you could add a minimum width constraint:
💡 Optional: Add minimum width
trailing: Container( padding: EdgeInsets.symmetric(horizontal: 8, vertical: 2), + constraints: BoxConstraints(minWidth: 28), decoration: BoxDecoration( color: isSelected ? Colors.white.withOpacity(0.3) : Theme.of(context).colorScheme.secondary.withOpacity(0.15), borderRadius: BorderRadius.circular(12), ),🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/ui/widgets/dumb_widgets/filter_tile_list_widgets.dart` around lines 40 - 47, The badge Container in the trailing of the filter tile (the Container with padding, decoration and color used when isSelected) should get a minimum width to keep badges visually consistent across digit counts; update that Container (in filter_tile_list_widgets) to include constraints: BoxConstraints(minWidth: <value>) and keep its existing padding, and ensure child alignment (e.g., Center or alignment: Alignment.center) so single-digit badges remain centered — adjust the minWidth value to match your design (e.g., ~28–36) for consistent alignment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/ui/widgets/smart_widgets/drawer/drawer_viewmodel.dart`:
- Around line 50-53: DrawerViewModel currently reads counts synchronously via
getFilterCount and never subscribes to TorrentService, so counts won’t update
while the drawer is open; fix by subscribing to TorrentService changes in
DrawerViewModel.init() (e.g., listen to TorrentService.torrentsList or its
change stream) and call notifyListeners() when the list or filter counts change,
and remove the listener in dispose(), or alternatively change the UI side by
wrapping FilterTile’s count display in a ValueListenableBuilder (or
StreamBuilder) bound to TorrentService.torrentsList so the count updates
reactively; reference methods/classes: DrawerViewModel.init(), getFilterCount(),
notifyListeners(), TorrentService.torrentsList, and FilterTile.
---
Nitpick comments:
In `@lib/ui/widgets/dumb_widgets/filter_tile_list_widgets.dart`:
- Around line 40-47: The badge Container in the trailing of the filter tile (the
Container with padding, decoration and color used when isSelected) should get a
minimum width to keep badges visually consistent across digit counts; update
that Container (in filter_tile_list_widgets) to include constraints:
BoxConstraints(minWidth: <value>) and keep its existing padding, and ensure
child alignment (e.g., Center or alignment: Alignment.center) so single-digit
badges remain centered — adjust the minWidth value to match your design (e.g.,
~28–36) for consistent alignment.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9ade8dfa-ccdf-41ff-b702-f746fbb35f10
📒 Files selected for processing (3)
lib/services/state_services/torrent_service.dartlib/ui/widgets/dumb_widgets/filter_tile_list_widgets.dartlib/ui/widgets/smart_widgets/drawer/drawer_viewmodel.dart
| /// Returns the count of torrents matching a given [Filter] | ||
| int getFilterCount(Filter filter) { | ||
| return _torrentService?.getFilterCount(filter) ?? 0; | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check if DrawerViewModel subscribes to TorrentService changes anywhere
rg -n "addListener|listen" lib/ui/widgets/smart_widgets/drawer/
# Check how drawer is used and if it rebuilds on torrent changes
rg -n -A 5 "DrawerViewModel" lib/ui/widgets/smart_widgets/drawer/Repository: CCExtractor/rutorrent-flutter
Length of output: 1795
🏁 Script executed:
# Check DrawerViewModel.init() and full implementation
head -80 lib/ui/widgets/smart_widgets/drawer/drawer_viewmodel.dartRepository: CCExtractor/rutorrent-flutter
Length of output: 3231
🏁 Script executed:
# Check FilterTile implementation and how it uses getFilterCount
fd -t f "filter_tile" lib/ --exec cat -n {} \;Repository: CCExtractor/rutorrent-flutter
Length of output: 3785
🏁 Script executed:
# Check if BaseViewModel or TorrentService have built-in change propagation
rg -n "class BaseViewModel|class TorrentService" lib/Repository: CCExtractor/rutorrent-flutter
Length of output: 170
Counts will not update live while the drawer is open, contradicting the PR's claimed reactive behavior.
The getFilterCount method reads synchronously without subscribing to TorrentService changes. DrawerViewModel doesn't listen to TorrentService (neither in init() nor elsewhere), so it won't call notifyListeners() when torrents change. FilterTile is a StatelessWidget that reads the count once at build time without any reactive wrapper, so the displayed count will only refresh when the drawer is reopened, not while it remains open and torrent states change.
To match the PR's description of reactive updates, DrawerViewModel should:
- Listen to
TorrentServicechanges ininit()and callnotifyListeners()when the torrent list or filter counts change, or - Wrap the count display in
FilterTilewithValueListenableBuilderonTorrentService.torrentsList
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@lib/ui/widgets/smart_widgets/drawer/drawer_viewmodel.dart` around lines 50 -
53, DrawerViewModel currently reads counts synchronously via getFilterCount and
never subscribes to TorrentService, so counts won’t update while the drawer is
open; fix by subscribing to TorrentService changes in DrawerViewModel.init()
(e.g., listen to TorrentService.torrentsList or its change stream) and call
notifyListeners() when the list or filter counts change, and remove the listener
in dispose(), or alternatively change the UI side by wrapping FilterTile’s count
display in a ValueListenableBuilder (or StreamBuilder) bound to
TorrentService.torrentsList so the count updates reactively; reference
methods/classes: DrawerViewModel.init(), getFilterCount(), notifyListeners(),
TorrentService.torrentsList, and FilterTile.
Closes #109
Summary
Shows the count of torrents for each filter state (All, Downloading, Completed, Active, Inactive, Error) as a badge next to each filter tile in the drawer, matching the ruTorrent web interface behavior.
Changes
torrent_service.dart: AddedgetFilterCount(Filter)method that reuses the existing_filterList()logic to return the countdrawer_viewmodel.dart: ExposedgetFilterCount()via the DrawerViewModelfilter_tile_list_widgets.dart: Added a trailing count badge with themed styling to each FilterTileThe count updates reactively as torrents change state (download, complete, error, etc.).
Summary by CodeRabbit