Skip to content

feat: Added Date-based filtering and sorting feature for the gallery#249

Open
Prriiiyankaaa wants to merge 13 commits into
Abhash-Chakraborty:mainfrom
Prriiiyankaaa:main
Open

feat: Added Date-based filtering and sorting feature for the gallery#249
Prriiiyankaaa wants to merge 13 commits into
Abhash-Chakraborty:mainfrom
Prriiiyankaaa:main

Conversation

@Prriiiyankaaa
Copy link
Copy Markdown

@Prriiiyankaaa Prriiiyankaaa commented May 26, 2026

Summary

Closes #215

Adds upload-date sorting and date-range filtering to the gallery so larger local libraries are easier to browse when users remember roughly when an image was uploaded.

What changed

  • Added sort_order support to /api/gallery with newest and oldest options.
  • Added date filtering for last_30_days, last_60_days, last_90_days, and custom date_start / date_end ranges.
  • Added validation for invalid custom date values instead of silently ignoring bad input.
  • Added a gallery date/sort filter UI that persists state in the URL.
  • Preserved existing status filters, liked-only filtering, pagination, and preview modal URL behavior.
  • Added backend and frontend coverage for the new filtering behavior.

Testing

  • uv run ruff check .
  • uv run ruff format --check .
  • uv run pytest tests/test_gallery.py -q
  • pnpm exec vitest run src/__tests__/gallery-url-state.test.tsx

Notes

The PR is scoped to gallery upload-date filtering and sorting. Unrelated backend formatting changes were removed.

Note

Add date-based filtering and sort order controls to the gallery

  • Adds sort_order (newest/oldest) and date_range (last_30_days, last_60_days, last_90_days, custom) query parameters to the /gallery backend endpoint, filtering on Media.created_at.
  • Adds a parse_date_range utility in gallery.py that handles preset and custom date ranges, normalizing bounds and returning UTC-aware datetimes; invalid custom dates return HTTP 422.
  • Adds a GalleryDateFilter UI component with sort and date range dropdowns, including custom start/end date inputs.
  • Integrates sort and date filter state into the gallery page URL, React Query key, and getGallery API calls in page.tsx and api.ts.
  • Behavioral Change: date_start/date_end URL params are only set when date_range=custom and are cleared otherwise; sort_order defaults to newest and is omitted from the URL when at its default value.

Macroscope summarized b802d57.

Summary by CodeRabbit

Release Notes

  • New Features
    • Added gallery sorting options to display images by newest or oldest first
    • Added date range filtering with preset options (last 30/60/90 days) and custom date picker
    • Gallery filters now persist in the URL for shareable and bookmarkable views

Review Change Stack

Copilot AI review requested due to automatic review settings May 26, 2026 10:54
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 19483330-c6c9-4f37-af4d-7ab2c64e68d4

📥 Commits

Reviewing files that changed from the base of the PR and between 5525fb9 and 2f98b8e.

📒 Files selected for processing (4)
  • backend/src/find_api/routers/gallery.py
  • backend/tests/test_gallery.py
  • frontend/src/app/gallery/page.tsx
  • frontend/src/store/galleryStore.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • backend/tests/test_gallery.py
  • backend/src/find_api/routers/gallery.py
  • frontend/src/app/gallery/page.tsx

📝 Walkthrough

Walkthrough

PR adds gallery sort order (newest/oldest) and date-range filtering (presets: last 30/60/90 days; custom start/end) across backend and frontend. Backend parses dates to UTC bounds, filters Media.created_at, and orders query; frontend renders sort/date picker, syncs selection to URL, and resets pagination on filter change.

Changes

Gallery sorting and date-range filtering

Layer / File(s) Summary
Type contracts and API client
frontend/src/lib/api.ts
Backend and frontend share SortOrder and DateRangePreset types; getGallery params extend to accept sortOrder, dateRange, dateStart, dateEnd and forward them as query parameters.
Backend date parsing and endpoint wiring
backend/src/find_api/routers/gallery.py
parse_date_range(...) converts preset/custom date strings into UTC start/end bounds, validating custom ISO dates and normalizing end-of-day; /gallery endpoint applies created_at range filters, orders by newest/oldest, then paginates.
Backend date filtering tests
backend/tests/test_gallery.py
TestGalleryDateFiltering verifies newest/oldest sort, preset date ranges (30/60/90 days), custom ranges (with start/end/both), composition with status/liked filters, invalid date validation, and default all-items behavior.
Gallery state store
frontend/src/store/galleryStore.ts
New Zustand store manages GalleryFilterState (filter mode, liked-only, sort order, date range/start/end) with setFilters and resetFilters actions.
Frontend GalleryDateFilter component
frontend/src/components/gallery-date-filter.tsx
Client-side component: sort-order dropdown, date-range presets, custom date-picker with Apply/Clear/Cancel, local UI state, outside-click handling, and change callbacks.
Gallery page URL sync and query wiring
frontend/src/app/gallery/page.tsx, frontend/src/store/galleryStore.ts
Parses sort_order/date_range from URL into typed values; syncs into store; includes sort/date in useInfiniteQuery key for pagination reset on filter change; extends buildGalleryHref/updateGalleryParams to persist/clear sort/date URL params; adds GalleryDateFilter to header panel.
Frontend URL restoration tests
frontend/src/__tests__/gallery-url-state.test.tsx
Mocks GalleryDateFilter; tests default sort, URL restoration of sort_order/date_range presets and custom ranges, composition with status/liked, and ?media= deep-linking with all filter params.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Abhash-Chakraborty/Find#147: Extends frontend/src/__tests__/gallery-url-state.test.tsx to validate sort/date query-parameter restoration and deep-link behavior in the same test file.

  • Abhash-Chakraborty/Find#224: Modifies frontend/src/app/gallery/page.tsx around useInfiniteQuery integration; this PR adds sort_order/date_range to the query key and params, overlapping in the same data-fetching code paths.

  • Abhash-Chakraborty/Find#110: Persists status/liked filters to URL in frontend/src/app/gallery/page.tsx; this PR extends the same URL-state plumbing (buildGalleryHref/updateGalleryParams) to handle sort/date parameters.

Suggested labels

frontend, ui/ux, testing

Suggested reviewers

  • Abhash-Chakraborty

Poem

🐰 A gallery now sorts by time,
newest-first or oldest—sublime!
Custom ranges let users glance,
past thirty, sixty, ninety days' dance,
All URL-persisted, tests pass with a shine! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 76.19% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main feature added: date-based filtering and sorting for the gallery. It is clear, concise, and directly reflects the primary change in the changeset.
Description check ✅ Passed The PR description covers the template requirements including summary, type of change (feature), what changed, testing steps, and includes a linked issue reference. However, some checklist items and specific documentation are incomplete.
Linked Issues check ✅ Passed The PR implements all acceptance criteria from issue #215: sort by upload date (newest/oldest) [#215], filter by date ranges (last 30/60/90 days, custom) [#215], works with existing status filters [#215], URL state persistence [#215], validated parameters with safe defaults [#215], preserves existing flows [#215], and includes test coverage [#215].
Out of Scope Changes check ✅ Passed All changes are within the scope of gallery upload-date filtering and sorting. No gallery redesign, calendar-heavy UI, search ranking changes, or out-of-scope modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

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

@Prriiiyankaaa
Copy link
Copy Markdown
Author

Hi @Abhash-Chakraborty , I have made the required changes, kindly have a look and let me know if any changes required.

Copy link
Copy Markdown
Contributor

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

Note

Copilot was unable to run its full agentic suite in this review.

Adds date-based filtering and upload-date sorting to the gallery across the frontend (URL/state + UI + API params) and backend (query parsing + SQL filtering), with accompanying tests.

Changes:

  • Extend gallery API parameters to include sort_order and date range filtering (date_range, date_start, date_end)
  • Add a new GalleryDateFilter UI component and integrate it into the gallery page with URL-state support
  • Add frontend and backend tests for the new sort/date filtering behavior

Reviewed changes

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

Show a summary per file
File Description
frontend/src/lib/api.ts Adds sort/date query params and exports shared types for gallery filtering
frontend/src/components/gallery-date-filter.tsx New client component for sort order + date range selection (including custom dates)
frontend/src/app/gallery/page.tsx Wires URL params → typed state → getGallery params; integrates the new filter UI
frontend/src/tests/gallery-url-state.test.tsx Adds URL-state restoration tests for sort/date filtering
backend/src/find_api/routers/gallery.py Implements sort_order and date filtering in /api/gallery
backend/tests/test_gallery.py Adds backend tests covering sorting and date-range filter combinations

Comment thread frontend/src/app/gallery/page.tsx Outdated
Comment on lines +204 to +209
const getDateRangeParam = (dateRange: DateRangePreset | null): string | null => {
return dateRange || null;
};

return "all";
};
Comment thread frontend/src/app/gallery/page.tsx Outdated
Comment on lines +370 to +375
const nextFilter = nextState.filter ?? filter;
const nextLikedOnly = nextState.likedOnly ?? likedOnly;
const nextSortOrder = nextState.sortOrder ?? sortOrder;
const nextDateRange = nextState.dateRange ?? dateRange;
const nextDateStart = nextState.dateStart ?? dateStart;
const nextDateEnd = nextState.dateEnd ?? dateEnd;
Comment thread frontend/src/lib/api.ts Outdated
Comment on lines +240 to +246
limit?: number;
status?: MediaStatus;
liked?: boolean;
sortOrder?: SortOrder;
dateRange?: DateRangePreset;
dateStart?: string;
dateEnd?: string;
Comment on lines +28 to +29
const [customStart, setCustomStart] = useState(dateStart || "");
const [customEnd, setCustomEnd] = useState(dateEnd || "");
Comment on lines +30 to +31
const sortMenuRef = useRef<HTMLDivElement>(null);
const datePickerRef = useRef<HTMLDivElement>(null);
Comment on lines +399 to +417
// Handle date range
const dateRangeParam = getDateRangeParam(nextDateRange);
if (dateRangeParam) {
nextParams.set("date_range", dateRangeParam);
} else {
nextParams.delete("date_range");
}

if (nextDateStart) {
nextParams.set("date_start", nextDateStart);
} else {
nextParams.delete("date_start");
}

if (nextDateEnd) {
nextParams.set("date_end", nextDateEnd);
} else {
nextParams.delete("date_end");
}
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 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 `@frontend/src/app/gallery/page.tsx`:
- Around line 208-210: Remove the stray `return "all";` and the extra `};` that
follow the end of `getDateRangeParam` so the file parses correctly; edit the
block after `getDateRangeParam` to delete that standalone return and the stray
closing brace, leaving a single properly-terminated function and allowing
`getStatusParamFromFilter` to start immediately afterward with correct braces.

In `@frontend/src/components/gallery-date-filter.tsx`:
- Around line 28-29: The local state variables customStart/customEnd are only
set once from props (dateStart/dateEnd) and can go stale when URL params change;
add a useEffect in the gallery-date-filter component that watches [dateStart,
dateEnd] and calls setCustomStart(dateStart || "") and setCustomEnd(dateEnd ||
"") to mirror prop updates into local state so the inputs and labels reflect
navigation/deep-link changes.
- Around line 145-151: The component currently calls both onDateRangeChange(...)
and onCustomDateChange(...) for a single user action (e.g., when option.value is
truthy or falsy), causing duplicate router.push calls and race conditions; fix
by emitting a single callback per interaction—either stop calling
onCustomDateChange from the option branch and only call onDateRangeChange with a
unified payload (e.g., include range, start, end) or consolidate into one
exported handler (e.g., a unified setDateFilter(range, start, end)) and update
callers to use that instead; update all places referencing onDateRangeChange and
onCustomDateChange (including the branch around option.value and the similar
47–54 block) so only the single chosen callback updates URL state.
🪄 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

Run ID: 826b71cd-dbe1-444f-a769-893772a48f4a

📥 Commits

Reviewing files that changed from the base of the PR and between f8d65e0 and 3f94dbd.

📒 Files selected for processing (6)
  • backend/src/find_api/routers/gallery.py
  • backend/tests/test_gallery.py
  • frontend/src/__tests__/gallery-url-state.test.tsx
  • frontend/src/app/gallery/page.tsx
  • frontend/src/components/gallery-date-filter.tsx
  • frontend/src/lib/api.ts

Comment thread frontend/src/app/gallery/page.tsx Outdated
Comment thread frontend/src/components/gallery-date-filter.tsx
Comment thread frontend/src/components/gallery-date-filter.tsx Outdated
@github-actions github-actions Bot added the needs linked issue Pull request needs to link a valid issue before review. label May 26, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 26, 2026

PR Context Summary

Suggested issue links

  • No strong issue match found yet.

Use Fixes #123 or Closes #123 in the PR body when one of the suggestions is the intended issue.
Manual rerun: Actions > PR Context Triage > Run workflow > set pr_number and force_review=true.

@Abhash-Chakraborty
Copy link
Copy Markdown
Owner

@Prriiiyankaaa please fix the CI

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
frontend/src/app/gallery/page.tsx (1)

33-44: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Run Biome on this file before merge.

frontend-check is still failing on the @/lib/api import ordering and formatter output in this hunk, so this file will keep CI red until the Biome fixes are applied. As per coding guidelines, frontend/src/**/*.{ts,tsx}: Frontend code uses TypeScript strict mode, 2-space indentation, double quotes, and Biome formatting.

Also applies to: 175-185, 204-206, 253-253, 370-372, 426-426

🤖 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 `@frontend/src/app/gallery/page.tsx` around lines 33 - 44, Run Biome on
frontend/src/app/gallery/page.tsx and fix formatting and import ordering for the
import block that currently lists api, deleteImage, deleteImagesBulk,
DateRangePreset, GalleryResponse, SortOrder, getGallery, getImageDetail,
reprocessImage, and toggleLike from "`@/lib/api`"; ensure Biome's rules are
applied (TypeScript strict settings, 2-space indentation, double quotes) and
reorder/format the import to satisfy the linter/formatter so frontend-check
passes for the reported hunks (including the other affected ranges 175-185,
204-206, 253, 370-372, 426).
frontend/src/components/gallery-date-filter.tsx (1)

194-211: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Associate the custom date controls with accessible labels.

The standalone label at Line 194 is not bound to either date input, so CI fails and screen readers won't get a proper name for these fields. Use a fieldset/legend for the group, or add separate label + id pairs for each input.

🤖 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 `@frontend/src/components/gallery-date-filter.tsx` around lines 194 - 211, The
"Custom date range" label is not associated with the two date inputs
(customStart/customEnd), causing accessibility CI failure; update the JSX in
gallery-date-filter.tsx to either wrap the inputs in a fieldset with a legend or
add individual <label for="..."> paired with unique ids on the date inputs
(e.g., id="custom-start" and id="custom-end") and keep the existing onChange
handlers (setCustomStart/setCustomEnd) intact so screen readers can correctly
announce each control.
🤖 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 `@frontend/src/components/gallery-date-filter.tsx`:
- Around line 3-5: This file's imports and formatting violate the project's
Biome rules (import ordering, 2-space indentation, double quotes); run Biome to
auto-fix formatting and import order for
frontend/src/components/gallery-date-filter.tsx (affecting the import statements
for ChevronDown, Calendar, useEffect, useRef, useState and the type imports
DateRangePreset, SortOrder) and reformat the other affected hunks so the file
conforms to the frontend TypeScript style (TypeScript strict mode, 2-space
indent, double quotes) before merging.

---

Outside diff comments:
In `@frontend/src/app/gallery/page.tsx`:
- Around line 33-44: Run Biome on frontend/src/app/gallery/page.tsx and fix
formatting and import ordering for the import block that currently lists api,
deleteImage, deleteImagesBulk, DateRangePreset, GalleryResponse, SortOrder,
getGallery, getImageDetail, reprocessImage, and toggleLike from "`@/lib/api`";
ensure Biome's rules are applied (TypeScript strict settings, 2-space
indentation, double quotes) and reorder/format the import to satisfy the
linter/formatter so frontend-check passes for the reported hunks (including the
other affected ranges 175-185, 204-206, 253, 370-372, 426).

In `@frontend/src/components/gallery-date-filter.tsx`:
- Around line 194-211: The "Custom date range" label is not associated with the
two date inputs (customStart/customEnd), causing accessibility CI failure;
update the JSX in gallery-date-filter.tsx to either wrap the inputs in a
fieldset with a legend or add individual <label for="..."> paired with unique
ids on the date inputs (e.g., id="custom-start" and id="custom-end") and keep
the existing onChange handlers (setCustomStart/setCustomEnd) intact so screen
readers can correctly announce each control.
🪄 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

Run ID: 00bfc8f7-9036-4eb5-a194-f9442398ca92

📥 Commits

Reviewing files that changed from the base of the PR and between 3f94dbd and 96dc739.

📒 Files selected for processing (2)
  • frontend/src/app/gallery/page.tsx
  • frontend/src/components/gallery-date-filter.tsx

Comment thread frontend/src/components/gallery-date-filter.tsx Outdated
Priyanka added 2 commits May 26, 2026 21:41
Prevent race condition where onDateRangeChange and onCustomDateChange
were called sequentially, causing two router.push calls. Now uses single
onDateFilterChange callback to update all date params atomically.
Comment thread frontend/src/app/gallery/page.tsx
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented May 26, 2026

Approvability

Verdict: Needs human review

1 blocking correctness issue found. This PR introduces a new date filtering and sorting feature with significant new frontend components, state management, and backend logic. Multiple open review comments identify potential bugs including a race condition on initial render and issues with clearing filters, which require human attention before merging.

You can customize Macroscope's approvability policy. Learn more.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
frontend/src/components/gallery-date-filter.tsx (1)

73-80: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Avoid emitting two parent updates for one date-filter action.

Line 75–76 and Line 172–176 still fire both callbacks per click. With current page wiring, that can trigger back-to-back router.push calls and drop either date_range or custom dates depending on timing/order.

Suggested direction
- onDateRangeChange: (preset: DateRangePreset | null) => void;
- onCustomDateChange: (start: string | null, end: string | null) => void;
+ onDateFilterChange: (payload: {
+   dateRange: DateRangePreset | null;
+   dateStart: string | null;
+   dateEnd: string | null;
+ }) => void;

Then emit exactly one callback in preset/apply/clear handlers so URL updates are atomic.

Also applies to: 170-177

🤖 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 `@frontend/src/components/gallery-date-filter.tsx` around lines 73 - 80, The
handler currently calls both onDateRangeChange and onCustomDateChange which
causes duplicate parent updates; change handleCustomDateApply to emit a single
callback (choose one: call only onCustomDateChange(customStart||null,
customEnd||null) for apply and onCustomDateChange(null,null) for clear, or
alternatively call only onDateRangeChange("custom")/null and remove the other)
so only one parent update occurs; apply the same fix to the other
preset/apply/clear handlers (the blocks around lines where preset handlers call
both onDateRangeChange and onCustomDateChange) so each action invokes exactly
one callback (use the same chosen callback consistently).
🤖 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 `@backend/src/find_api/routers/gallery.py`:
- Around line 123-125: The date bounds logic must detect when both parsed dates
exist and start_date > end_date and normalize them (swap values) before
returning or building filters; update the branch that currently returns
start_date, end_date (the block using start_date/end_date derived from
date_start/date_end) to check "if start_date and end_date and start_date >
end_date" and swap the two variables (or raise a clear validation error) prior
to returning; apply the same normalization to the other identical block around
the code referenced at lines 181-189 so all date-range paths handle reversed
inputs consistently.

In `@frontend/src/app/gallery/page.tsx`:
- Around line 204-205: getDateRangeParam's signature and implementation must
accept nullable values to satisfy strictNullChecks: change the parameter type
from DateRangePreset | undefined to DateRangePreset | null | undefined and
ensure the function returns the string value or null (e.g., return dateRange ??
null) so callers like buildGalleryHref (and its nextState.dateRange /
nextDateRange) can pass null safely; update the function declaration for
getDateRangeParam and its return handling accordingly.

---

Duplicate comments:
In `@frontend/src/components/gallery-date-filter.tsx`:
- Around line 73-80: The handler currently calls both onDateRangeChange and
onCustomDateChange which causes duplicate parent updates; change
handleCustomDateApply to emit a single callback (choose one: call only
onCustomDateChange(customStart||null, customEnd||null) for apply and
onCustomDateChange(null,null) for clear, or alternatively call only
onDateRangeChange("custom")/null and remove the other) so only one parent update
occurs; apply the same fix to the other preset/apply/clear handlers (the blocks
around lines where preset handlers call both onDateRangeChange and
onCustomDateChange) so each action invokes exactly one callback (use the same
chosen callback consistently).
🪄 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

Run ID: dec92fae-752d-409f-9ece-c2ef2c5d6483

📥 Commits

Reviewing files that changed from the base of the PR and between 96dc739 and 5c0430e.

📒 Files selected for processing (9)
  • backend/src/find_api/models/person.py
  • backend/src/find_api/routers/gallery.py
  • backend/src/find_api/routers/vault.py
  • backend/tests/test_gallery.py
  • backend/tests/test_hybrid_embedding.py
  • frontend/src/__tests__/gallery-url-state.test.tsx
  • frontend/src/app/gallery/page.tsx
  • frontend/src/components/gallery-date-filter.tsx
  • frontend/src/lib/api.ts
💤 Files with no reviewable changes (1)
  • backend/tests/test_gallery.py
✅ Files skipped from review due to trivial changes (3)
  • backend/tests/test_hybrid_embedding.py
  • backend/src/find_api/routers/vault.py
  • backend/src/find_api/models/person.py

Comment thread backend/src/find_api/routers/gallery.py
Comment thread frontend/src/app/gallery/page.tsx Outdated
- Fix strict-null type mismatch: getDateRangeParam now accepts null in addition to undefined/DateRangePreset
- Handle reversed custom date bounds: normalize (swap) dates when start_date > end_date
Comment thread backend/src/find_api/routers/gallery.py
Priyanka and others added 3 commits May 26, 2026 22:02
When custom_start and custom_end are reversed and swapped, also correct
the time components so the earlier date has 00:00:00 (start of day) and
the later date has 23:59:59.999999 (end of day). Previously, time
components were not adjusted after swap, causing filters to exclude
records on boundary dates.
- Fix line wrapping for long function signatures and array literals
- Reorganize imports to group values before types
- Update test mock to use new onDateFilterChange callback signature
- Wrap long attribute values and conditional expressions
@Abhash-Chakraborty
Copy link
Copy Markdown
Owner

@Prriiiyankaaa Please dont push anything I will fix it

Priyanka and others added 2 commits May 26, 2026 22:17
- Wrap nextDateRange, nextDateStart, nextDateEnd ternary expressions
- Wrap dependency array across multiple lines for better readability
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
frontend/src/app/gallery/page.tsx (1)

277-286: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Guard dateStart/dateEnd behind dateRange === "custom" before calling getGallery.

Right now dateStart/dateEnd are forwarded even when the active range is not custom. That can leak malformed URL state into API calls and create inconsistent filtering behavior.

Suggested fix
       getGallery({
         page: typeof pageParam === "number" ? pageParam : 1,
         limit: GALLERY_LIMIT,
         status: filter === "all" ? undefined : filter,
         liked: likedOnly ? true : undefined,
         sortOrder,
         dateRange,
-        dateStart: dateStart || undefined,
-        dateEnd: dateEnd || undefined,
+        dateStart: dateRange === "custom" ? (dateStart || undefined) : undefined,
+        dateEnd: dateRange === "custom" ? (dateEnd || undefined) : undefined,
       }),
🤖 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 `@frontend/src/app/gallery/page.tsx` around lines 277 - 286, The call to
getGallery currently forwards dateStart and dateEnd regardless of dateRange,
which can leak invalid/malformed URL state; update the getGallery invocation
(the object passed into getGallery) to only include dateStart and dateEnd when
dateRange === "custom" (otherwise pass undefined or omit them), i.e., gate both
dateStart and dateEnd behind the condition dateRange === "custom" so they are
not forwarded for non-custom ranges.
🤖 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.

Outside diff comments:
In `@frontend/src/app/gallery/page.tsx`:
- Around line 277-286: The call to getGallery currently forwards dateStart and
dateEnd regardless of dateRange, which can leak invalid/malformed URL state;
update the getGallery invocation (the object passed into getGallery) to only
include dateStart and dateEnd when dateRange === "custom" (otherwise pass
undefined or omit them), i.e., gate both dateStart and dateEnd behind the
condition dateRange === "custom" so they are not forwarded for non-custom
ranges.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b6a021f5-5b14-4db4-8098-9c16b3098639

📥 Commits

Reviewing files that changed from the base of the PR and between 5c0430e and 5525fb9.

📒 Files selected for processing (5)
  • backend/src/find_api/routers/gallery.py
  • frontend/src/__tests__/gallery-url-state.test.tsx
  • frontend/src/app/gallery/page.tsx
  • frontend/src/components/gallery-date-filter.tsx
  • frontend/src/lib/api.ts

@Prriiiyankaaa
Copy link
Copy Markdown
Author

@Abhash-Chakraborty alright. Let me know if anything required from my side.

@github-actions github-actions Bot removed the needs linked issue Pull request needs to link a valid issue before review. label May 26, 2026
@Abhash-Chakraborty Abhash-Chakraborty added gssoc26 Related to GirlScript Summer of Code 2026. level:intermediate GSSoC difficulty level: intermediate. Base contributor points: 35. type:feature Feature PR. GSSoC type bonus. quality:clean Clean and maintainable PR. GSSoC contributor multiplier: 1.2x. under-review Maintainer needs to verify labels May 26, 2026
@github-actions
Copy link
Copy Markdown

@macroscope-app review

Please review this PR against its linked issue, local-first privacy rules, and the current Find repo instructions.
Linked issue(s): #215.
Trigger source: label-gated review (under-review).

@Abhash-Chakraborty Abhash-Chakraborty added ready-to-merge Fully approved, tested, and cleared for immediate merging. gssoc:approved Valid GSSoC contribution approved for scoring. and removed under-review Maintainer needs to verify labels May 26, 2026
@Abhash-Chakraborty
Copy link
Copy Markdown
Owner

Screenshot 2026-05-27 114939 Screenshot 2026-05-27 114932 You have not tested this??

@Abhash-Chakraborty
Copy link
Copy Markdown
Owner

Images are overlapping.

@Abhash-Chakraborty Abhash-Chakraborty added do-not-merge Blocks merging. Remove this label only when the PR is fully ready for production. and removed ready-to-merge Fully approved, tested, and cleared for immediate merging. labels May 27, 2026
@Abhash-Chakraborty Abhash-Chakraborty added frontend Frontend UI, state, and Next.js work backend FastAPI, database, storage, and API work api API contract, endpoint behavior, and response shape ui/ux User interface, interaction, and visual polish type:design UI/UX or design-related PR. GSSoC type bonus: +10 points. under-review Maintainer needs to verify labels May 27, 2026
const searchParams = useSearchParams();
const filter = getFilterFromStatusParam(searchParams.get("status"));
const likedOnly = searchParams.get("liked") === "true";
const filter = galleryStore((state) => state.filter);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Medium gallery/page.tsx:251

On initial render, useInfiniteQuery fires with store defaults (filter: "all", sortOrder: "newest") before useEffect (lines 270-272) syncs URL params to the store. This causes an incorrect network request and caches wrong data under the wrong query key, then immediately refetches with correct params when the effect runs. The query should read directly from parsedGalleryFilters (derived from searchParams) on first render instead of the store, ensuring the initial request uses URL state.

🤖 Copy this AI Prompt to have your agent fix this:
In file frontend/src/app/gallery/page.tsx around line 251:

On initial render, `useInfiniteQuery` fires with store defaults (`filter: "all"`, `sortOrder: "newest"`) before `useEffect` (lines 270-272) syncs URL params to the store. This causes an incorrect network request and caches wrong data under the wrong query key, then immediately refetches with correct params when the effect runs. The query should read directly from `parsedGalleryFilters` (derived from `searchParams`) on first render instead of the store, ensuring the initial request uses URL state.

Evidence trail:
frontend/src/app/gallery/page.tsx lines 251-256 (store selectors), lines 258-268 (parsedGalleryFilters useMemo from URL), lines 270-272 (useEffect syncing URL to store — runs after render), lines 276-284 (query key from store), lines 293-305 (useInfiniteQuery using store values). frontend/src/store/galleryStore.ts lines 20-27 (defaults: filter: 'all', sortOrder: 'newest').

@Abhash-Chakraborty Abhash-Chakraborty removed quality:clean Clean and maintainable PR. GSSoC contributor multiplier: 1.2x. gssoc:approved Valid GSSoC contribution approved for scoring. labels May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api API contract, endpoint behavior, and response shape backend FastAPI, database, storage, and API work do-not-merge Blocks merging. Remove this label only when the PR is fully ready for production. frontend Frontend UI, state, and Next.js work gssoc26 Related to GirlScript Summer of Code 2026. level:intermediate GSSoC difficulty level: intermediate. Base contributor points: 35. type:design UI/UX or design-related PR. GSSoC type bonus: +10 points. type:feature Feature PR. GSSoC type bonus. ui/ux User interface, interaction, and visual polish under-review Maintainer needs to verify

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add upload-date sorting and filtering to gallery

3 participants