Repository navigation
[codex] Add library browse filters and sort - #34
Conversation
- Share startup prefetch paths for recommendations, libraries, and library sections - Reuse cached library sections and first browse pages across iOS and tvOS
- Build catalog filter queries from shared state with focused tests - Add facet-driven filter UI, sort controls, and per-library persistence - Key browse and facet caches by full filter state
The old sheet eagerly laid out a FlowLayout chip cloud for every facet at once. With a long vocabulary (TV genres) the layout reported its single-row intrinsic width as its size, which a vertical ScrollView adopted and centered — pushing the sheet and its footer past both screen edges. It was also slow to present and visually heavy. Replace it with a compact, instantly-rendered list: - Quick one-tap rows at top (watch status, HDR/Dolby Vision) with trailing checkmarks. - Drill-in category rows (Genre, Decade, Content Rating, languages, …) that push a lazy value picker; long lists get an inline search field. Values are only laid out when a category is opened. - Match all/any and Preserve sort & filters fold in as plain list sections. Drop the "Show N results" apply button (wasted space) — the draft commits on dismiss, so results just update when the sheet closes. Also harden FlowLayout (still used by PersonDetailView) to clamp its reported width to the proposed width so it can never inflate its container again. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (13)
📝 WalkthroughWalkthroughThis PR adds shared catalog filter state, query building, facet loading, and persistence, then rewires iOS browse and tvOS browse screens to use the shared model instead of genre/sort-only filtering. ChangesShared catalog filtering system
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
…-filters-sort # Conflicts: # iosApp/iosApp/Screens/Browse/BrowseViewModel.swift # iosApp/iosApp/Startup/StartupContentPrefetcher.swift
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e68dd57551
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 10
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
iosApp/iosApp/Screens/Browse/BrowseViewModel.swift (1)
42-68: 🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick winLet resets invalidate active loads and mark every fetch in-flight.
Line 43 returns before Line 45 bumps
generation, so a filter/sort reset during an active load can let the stale response pass Line 90 and write old results under the newcurrentCacheKey. Line 66 also leaves pagination requests unguarded whenitemsis non-empty, allowing duplicate load-more calls for the same page.Suggested direction
func loadItems(reset: Bool = false) async { - guard !isLoading else { return } + if !reset, isLoading { return } if reset { generation += 1 // Surface the cached page-1 snapshot instantly so the grid @@ let myGeneration = generation - if items.isEmpty { - isLoading = true - } + isLoading = true error = nil @@ - isLoading = false - isRefreshing = false + if myGeneration == generation { + isLoading = false + isRefreshing = false + } }Also applies to: 107-108
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@iosApp/iosApp/Screens/Browse/BrowseViewModel.swift` around lines 42 - 68, In BrowseViewModel.loadItems(reset:), make resets invalidate any in-flight request by bumping generation before the early isLoading return path can short-circuit, so stale responses cannot pass the myGeneration check and overwrite the new currentCacheKey state. Also ensure every fetch path is marked in-flight, not just the first page, by guarding pagination requests with isLoading or a dedicated in-flight flag so duplicate load-more calls for the same page cannot run concurrently. Apply the same fix to the later fetch/append logic referenced by the “Also applies to” note.
🧹 Nitpick comments (1)
iosApp/Tests/CatalogQueryBuilderTests.swift (1)
78-84: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd the dual-dynamic-range wire-format case.
This suite only covers
hdr=true. Since the state model supports selecting bothhdranddolbyVision, add a case that asserts they lower into onematch=anygroup so this regression stays covered.Proposed test
func testHDRBooleanRule() { var s = CatalogFilterState(); s.hdr = true let q = build(s) XCTAssertEqual(q["groups[0][rules][0][field]"], "hdr") XCTAssertEqual(q["groups[0][rules][0][op]"], "is") XCTAssertEqual(q["groups[0][rules][0][value]"], "true") } + + func testDynamicRangeValuesShareOneAnyGroup() { + var s = CatalogFilterState() + s.hdr = true + s.dolbyVision = true + + let q = build(s) + XCTAssertEqual(q["groups[0][match]"], "any") + XCTAssertEqual(q["groups[0][rules][0][field]"], "hdr") + XCTAssertEqual(q["groups[0][rules][1][field]"], "dolby_vision") + XCTAssertNil(q["groups[1][match]"]) + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@iosApp/Tests/CatalogQueryBuilderTests.swift` around lines 78 - 84, The CatalogQueryBuilderTests coverage only verifies the hdr boolean path, so add a new test in CatalogQueryBuilderTests alongside testHDRBooleanRule that sets both CatalogFilterState.hdr and CatalogFilterState.dolbyVision to true and asserts the query builder produces a single match=any group. Verify the generated query from build(_:) includes both rules under the same group and that each rule uses the expected field/op/value wire format.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@iosApp/iosApp/Navigation/Route.swift`:
- Around line 65-71: The toFilterState() conversion currently only maps yearMin
to a single decade and ignores yearMax, so year ranges are collapsed incorrectly
and max-only inputs are lost. Update CatalogFilterState building in
Route.toFilterState() to derive the decade filter from both yearMin and yearMax,
preserving the intended range when either bound is present. Make sure the logic
in toFilterState() handles min-only, max-only, and bounded ranges consistently
before setting state.decades.
In `@iosApp/iosApp/Networking/ContinuumAPI.swift`:
- Around line 505-509: The legacy dispatcher for catalog filters is ignoring the
include_technical query value, so the typed
`catalogFilters(libraryId:includeTechnical:)` path loses that option. Update the
`get("/api/v1/catalog/filters", query:)` handling in `ContinuumAPI` to forward
the `include_technical` parameter from the query dictionary instead of always
relying on the default, and make sure the legacy route preserves the value
produced by `catalogFilters(...)`.
In `@iosApp/iosApp/Screens/Browse/BrowseViewModel.swift`:
- Around line 28-37: The cached-item hydration path in BrowseViewModel is
leaving mediaType stuck at its default, so cached/offline libraries can expose
the wrong sort/filter vocabulary. Update hydratePage1FromCache() to derive and
assign mediaType from the cached response as soon as the page-1 snapshot is
loaded, and make sure configure(libraryId:) still hydrates from cache using that
refined value before the UI reads filter/sort state.
In `@iosApp/iosApp/Screens/Browse/Filtering/CatalogFacets.swift`:
- Around line 88-109: The facet cache key in CatalogFacets is missing the
includeTechnical dimension, so facets, cachedFacets, and prefetch can reuse the
wrong CatalogFilters shape across requests. Update the key generation used by
facets(libraryId:includeTechnical:), cachedFacets(libraryId:), and
prefetch(libraryId:) to include includeTechnical, and adjust
CacheKey.catalogFilters so cached entries are separated for technical and
non-technical responses.
In `@iosApp/iosApp/Screens/Browse/Filtering/CatalogFilterState.swift`:
- Around line 151-160: The active facet count logic in
CatalogFilterState.activeFacetCount is counting hdr and dolbyVision separately
even though they represent one dynamic range facet. Update the count calculation
so the dynamicRange state is treated as a single facet dimension, and adjust the
existing hdr/dolbyVision checks in activeFacetCount to use the dynamicRange
property or equivalent combined logic instead of incrementing twice.
- Around line 298-322: The cacheKeyFragment serialization in CatalogFilterState
is ambiguous because raw filter values are joined with "," and sections with
"|", which can make distinct selections produce the same key. Update
cacheKeyFragment to encode or escape each value before joining so delimiters
inside values cannot collide, while keeping the existing structure in
CatalogFilterState and its join helper. Ensure every appended segment (genres,
studios, languages, etc.) uses the escaped form consistently so cache keys
remain injective.
In `@iosApp/iosApp/Screens/Browse/Filtering/CatalogQueryBuilder.swift`:
- Around line 55-58: The filter assembly in CatalogQueryBuilder’s query-building
flow is emitting hdr and dolby_vision as separate top-level groups, which turns
the low-dynamic-range facet into an AND instead of the intended OR. Update the
logic around the existing groups.addBool calls so the HDR-related selections are
combined into a single OR group when building the catalog query, using the same
grouping mechanism already used for other multi-value facets in
CatalogQueryBuilder.
In `@iosApp/iosApp/Screens/Browse/FilterView.swift`:
- Around line 37-42: The Reset action in FilterView’s toolbar is clearing the
entire CatalogFilterState through draft.resetFilters(), which also wipes sort
and order even though this sheet only edits filters. Update the Button("Reset")
handler to preserve the current sort/order values, or route it through a
filter-only reset helper on CatalogFilterState so only filter fields are reset
while sort state remains unchanged.
In `@iosApp/iosApp/tvOS/Screens/Libraries/TVBrowseFilterUI.swift`:
- Around line 271-279: The preview scheduling in schedulePreview() only cancels
the previous task when a new preview starts, so closing the panel can leave a
delayed onPreview(draft) call running and later update liveCount with stale
data. Add explicit cancellation when the filter panel closes or disappears by
cancelling previewTask from the relevant lifecycle/close handler in
TVBrowseFilterUI, and keep the existing Task.isCancelled checks so the pending
resultCount update is skipped after close.
In `@iosApp/iosApp/tvOS/Screens/Libraries/TVLibraryGridViewModel.swift`:
- Around line 194-202: The reset refresh path is using TVLibraryGridViewModel’s
current nextOffset instead of restarting at 0, so after hydratePage1FromCache()
it skips page 1 and corrupts pagination. Update the reset fetch logic around
CatalogQueryBuilder.build to force offset 0 on refresh/reset, and adjust the
success cursor handling in the same view model so nextOffset is advanced only
from the freshly fetched data rather than the cached page count.
---
Outside diff comments:
In `@iosApp/iosApp/Screens/Browse/BrowseViewModel.swift`:
- Around line 42-68: In BrowseViewModel.loadItems(reset:), make resets
invalidate any in-flight request by bumping generation before the early
isLoading return path can short-circuit, so stale responses cannot pass the
myGeneration check and overwrite the new currentCacheKey state. Also ensure
every fetch path is marked in-flight, not just the first page, by guarding
pagination requests with isLoading or a dedicated in-flight flag so duplicate
load-more calls for the same page cannot run concurrently. Apply the same fix to
the later fetch/append logic referenced by the “Also applies to” note.
---
Nitpick comments:
In `@iosApp/Tests/CatalogQueryBuilderTests.swift`:
- Around line 78-84: The CatalogQueryBuilderTests coverage only verifies the hdr
boolean path, so add a new test in CatalogQueryBuilderTests alongside
testHDRBooleanRule that sets both CatalogFilterState.hdr and
CatalogFilterState.dolbyVision to true and asserts the query builder produces a
single match=any group. Verify the generated query from build(_:) includes both
rules under the same group and that each rule uses the expected field/op/value
wire format.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 545c0959-afc6-48cc-9cdb-c2b875e37657
📒 Files selected for processing (18)
iosApp/Tests/CatalogQueryBuilderTests.swiftiosApp/iosApp/Navigation/Route.swiftiosApp/iosApp/Networking/ContinuumAPI.swiftiosApp/iosApp/Networking/Models.swiftiosApp/iosApp/Networking/ResponseCache.swiftiosApp/iosApp/Screens/Browse/BrowseView.swiftiosApp/iosApp/Screens/Browse/BrowseViewModel.swiftiosApp/iosApp/Screens/Browse/FilterView.swiftiosApp/iosApp/Screens/Browse/Filtering/BrowsePrefsStore.swiftiosApp/iosApp/Screens/Browse/Filtering/CatalogFacets.swiftiosApp/iosApp/Screens/Browse/Filtering/CatalogFilterState.swiftiosApp/iosApp/Screens/Browse/Filtering/CatalogQueryBuilder.swiftiosApp/iosApp/Screens/Browse/Filtering/CatalogSortKey.swiftiosApp/iosApp/Startup/StartupContentPrefetcher.swiftiosApp/iosApp/tvOS/Navigation/TVMainTabView.swiftiosApp/iosApp/tvOS/Screens/Libraries/TVBrowseFilterUI.swiftiosApp/iosApp/tvOS/Screens/Libraries/TVLibraryGridView.swiftiosApp/iosApp/tvOS/Screens/Libraries/TVLibraryGridViewModel.swift
- Make TVCascadeSelector one focusable panel with internal highlighted-row state driven by onMoveCommand, replacing per-row Button/@focusstate - Align flyout first section with anchored library row via measured row centers - Add focusRequest-driven focus claiming to TVCatalogGrid and TVBrowseControlRow - Give TVBrowseSortPanel/FilterPanel explicit focus scopes; redesign filter panel as list→values drill-in - Guard iOS-only List modifiers behind tvOS-safe helpers in FilterView - Disable top menu bar while cascade panel holds focus
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@iosApp/iosApp/tvOS/Navigation/TVCascadeSelector.swift`:
- Around line 505-517: The library focus change path in TVCascadeSelector should
also drive the capped ScrollView so newly selected libraries stay visible.
Update the moveLibrary(from:by:) / moveToLibrary(_:) flow to explicitly scroll
to the target `.library(id)` when focus moves, rather than only changing
internal state. Use the existing libraryRows and focus-handling logic in
TVCascadeSelector to trigger scrolling whenever the focused library changes.
In `@iosApp/iosApp/tvOS/Screens/Libraries/TVBrowseFilterUI.swift`:
- Around line 376-379: The reset action in resetRow is clearing more than just
filters because draft.resetFilters() is resetting the full CatalogFilterState
and can wipe the sort/order selected elsewhere. Update the reset flow so “Reset
filters” only clears filter-related fields while preserving the current
sort/order, either by changing CatalogFilterState.resetFilters() or introducing
a filter-only reset used by resetRow before claimFocus(.done).
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f8af5294-072b-42c6-b63a-75fd56e9a534
📒 Files selected for processing (8)
iosApp/iosApp/Screens/Browse/FilterView.swiftiosApp/iosApp/tvOS/Navigation/TVCascadeSelector.swiftiosApp/iosApp/tvOS/Navigation/TVTopMenuBar.swiftiosApp/iosApp/tvOS/Screens/Components/TVCatalogGrid.swiftiosApp/iosApp/tvOS/Screens/Libraries/TVBrowseFilterUI.swiftiosApp/iosApp/tvOS/Screens/Libraries/TVLibraryGridView.swiftiosApp/iosApp/tvOS/Screens/Libraries/TVLibraryGridViewModel.swiftiosApp/iosApp/tvOS/Screens/Libraries/TVLibraryTypeTabView.swift
💤 Files with no reviewable changes (1)
- iosApp/iosApp/tvOS/Screens/Libraries/TVLibraryGridViewModel.swift
🚧 Files skipped from review as they are similar to previous changes (1)
- iosApp/iosApp/tvOS/Screens/Libraries/TVLibraryGridView.swift
Summary
Validation
git diff --check origin/main...HEADxcodebuild test -project Silo.xcodeproj -scheme Silo -destination 'platform=iOS Simulator,id=EE2F7F14-2BCC-4836-AAB7-7E3D01847420' CODE_SIGNING_ALLOWED=NO -only-testing:SiloTests/CatalogQueryBuilderTestsNote: an initial simulator-name test run was retried with an explicit simulator UUID because two
iPhone 17 Prosimulators are present locally.Summary by CodeRabbit
includeTechnicaloption.