feat(trails): default trail overview sort to newest first #52

Closed
maximus wants to merge 0 commits from feat/50-default-sort-created into deploy
Member

Closes #50

What changed

The trail overview (/trails, all display modes) now defaults to creation date, newest first. An explicit or saved choice still wins.

  • routes/trails/+page.ts / routes/map/+page.ts: default filter uses the new DEFAULT_TRAIL_SORT (created, -). The list used to default to created ascending.
  • lib/util/trail_filter_util.ts: new pure helpers resolveTrailSort, applyStoredTrailSort, readStoredTrailSort (throw-safe) and defaultTrailSortOrder. sanitizeTrailFilter now falls back to the default direction instead of hard-coding ascending, and validates sortOrder.
  • trail_list.svelte (cards/list/table): saved sort / sort_order from localStorage are resolved through the helpers.
    • A saved field with no saved direction gets that field's default: created is newest first, everything else ascending. So picking "Name" from the fresh default still gives A-Z rather than Z-A.
    • A table-header click on a new column picks that column's default direction and saves both keys, so a reload shows the same order.
  • map/+page.svelte: the map's side list already defaulted to newest first but ignored the saved choice on load. It now applies the saved choice too, and uses the same field-change rule.
  • TrailFilter.sort type widened to every option the UI offers. Before, values like duration and like_count were only allowed through casts.

Not changed / checked

  • Backend / Meilisearch: created is already in the trails index SortableAttributes (db/main.go searchIndexSettings, and migration 1749831369). It is indexed as a unix timestamp (db/util/meilisearch.go), so no migration or hook change is needed.
  • User settings: there is no server-side sort preference. The only persisted choice is localStorage sort / sort_order, which is left as is.
  • Profile trail lists (/profile/[handle]) keep their own default. The issue scopes this to the trail overview.
  • No i18n changes.

Tests

  • New src/lib/util/trail_filter_sort.test.ts: covers the default, saved field/order precedence, a saved field without a direction, invalid saved values, storage that is missing or throws, and the sanitizeTrailFilter sort fallback.
  • npm run check: 0 errors. The 2 warnings are already on deploy, in trail/edit.
  • vitest run: 846 passed, 13 skipped. There is 1 unhandled undici ReadableStream is already closed rejection attributed to src/lib/server/trail_analyze.test.ts, which this PR does not touch.

https://claude.ai/code/session_01XMf4EGfBC9xbQ6rjD6HxgP

🤖 Generated with Claude Code

Closes #50 ## What changed The trail overview (`/trails`, all display modes) now defaults to **creation date, newest first**. An explicit or saved choice still wins. - `routes/trails/+page.ts` / `routes/map/+page.ts`: default filter uses the new `DEFAULT_TRAIL_SORT` (`created`, `-`). The list used to default to `created` ascending. - `lib/util/trail_filter_util.ts`: new pure helpers `resolveTrailSort`, `applyStoredTrailSort`, `readStoredTrailSort` (throw-safe) and `defaultTrailSortOrder`. `sanitizeTrailFilter` now falls back to the default direction instead of hard-coding ascending, and validates `sortOrder`. - `trail_list.svelte` (cards/list/table): saved `sort` / `sort_order` from localStorage are resolved through the helpers. - A saved field with no saved direction gets that field's default: created is newest first, everything else ascending. So picking "Name" from the fresh default still gives A-Z rather than Z-A. - A table-header click on a new column picks that column's default direction and saves both keys, so a reload shows the same order. - `map/+page.svelte`: the map's side list already defaulted to newest first but ignored the saved choice on load. It now applies the saved choice too, and uses the same field-change rule. - `TrailFilter.sort` type widened to every option the UI offers. Before, values like `duration` and `like_count` were only allowed through casts. ## Not changed / checked - **Backend / Meilisearch:** `created` is already in the trails index `SortableAttributes` (`db/main.go` `searchIndexSettings`, and migration `1749831369`). It is indexed as a unix timestamp (`db/util/meilisearch.go`), so no migration or hook change is needed. - **User settings:** there is no server-side sort preference. The only persisted choice is localStorage `sort` / `sort_order`, which is left as is. - Profile trail lists (`/profile/[handle]`) keep their own default. The issue scopes this to the trail overview. - No i18n changes. ## Tests - New `src/lib/util/trail_filter_sort.test.ts`: covers the default, saved field/order precedence, a saved field without a direction, invalid saved values, storage that is missing or throws, and the `sanitizeTrailFilter` sort fallback. - `npm run check`: 0 errors. The 2 warnings are already on `deploy`, in `trail/edit`. - `vitest run`: 846 passed, 13 skipped. There is 1 unhandled undici `ReadableStream is already closed` rejection attributed to `src/lib/server/trail_analyze.test.ts`, which this PR does not touch. https://claude.ai/code/session_01XMf4EGfBC9xbQ6rjD6HxgP 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(trails): default trail overview sort to newest first
All checks were successful
CI / web (push) Successful in 1m22s
CI / go (push) Successful in 14m33s
fcf5872a5b
Sort the trail overview by creation date, newest first, when the user has
not chosen a sort. A saved field or direction (localStorage sort /
sort_order) still wins, and the map view now honours it too.

- Add DEFAULT_TRAIL_SORT and pure helpers (resolveTrailSort,
  applyStoredTrailSort, defaultTrailSortOrder) in trail_filter_util.
- A saved field without a saved direction gets that field's default
  (created: newest first, others: ascending), so picking "name" from the
  fresh default still sorts A-Z.
- sanitizeTrailFilter falls back to the default direction instead of
  hard-coding ascending.
- Widen TrailFilter.sort to every sort option offered in the UI.

Meilisearch already lists `created` as sortable (db/main.go index
settings), so no backend change is needed.

Closes #50

Claude-Session: https://claude.ai/code/session_01XMf4EGfBC9xbQ6rjD6HxgP
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Member

Shipped via batch PR #64 (deploy 0d0d85a4), which merged this branch head unchanged; live since 2026-11-05 ~19:30 CET in wanderer-web:deploy-676a7c62 (homelab-flux #843). Forgejo does not mark stacked PRs as merged, so I am closing this by hand.

🤖 Generated with Claude Code

Shipped via batch PR #64 (`deploy` 0d0d85a4), which merged this branch head unchanged; live since 2026-11-05 ~19:30 CET in `wanderer-web:deploy-676a7c62` (homelab-flux #843). Forgejo does not mark stacked PRs as merged, so I am closing this by hand. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
maximus closed this pull request 2026-11-05 19:10:43 +00:00
All checks were successful
CI / web (push) Successful in 1m22s
Required
Details
CI / go (push) Successful in 14m33s
Required
Details

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
public/wanderer!52
No description provided.