From 893f0ffa36df2a082cf4acc908200a7ed4ae935e Mon Sep 17 00:00:00 2001 From: smartcalsystems-sketch Date: Tue, 13 Oct 2026 23:27:06 +0530 Subject: [PATCH] fix: stop labeling the unordered default sort as "Newest" (closes #702) SORT_LABELS.default was "Newest", but sortBounties's "default" case returns the array unchanged, and Bounty has no createdAt (or equivalent) field anywhere to sort by. The backend's listing query also has no ORDER BY, so order is whatever Postgres's heap returns and can change between requests. A real chronological sort needs a createdAt field exposed end-to-end from the backend first -- guessing at one here would be inventing a backend contract this repo doesn't control. Taking the issue's other suggested fix instead: stop the label from claiming an ordering that isn't there. --- src/lib/bounty-query.test.ts | 10 ++++++++++ src/lib/bounty-query.ts | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/lib/bounty-query.test.ts b/src/lib/bounty-query.test.ts index 9288c63..eb580e0 100644 --- a/src/lib/bounty-query.test.ts +++ b/src/lib/bounty-query.test.ts @@ -14,6 +14,7 @@ import { filterBounties, isFilterActive, parseBountyQuery, + SORT_LABELS, } from "./bounty-query"; import type { Bounty } from "@/types"; @@ -124,6 +125,15 @@ describe("filterBounties", () => { }); }); +describe("SORT_LABELS", () => { + it("doesn't label the unordered default sort as a real chronological sort (#702)", () => { + // `sortBounties`'s "default" case leaves the array unchanged, and Bounty + // has no createdAt (or equivalent) field to sort by — the label must not + // claim an ordering ("Newest", "Oldest", ...) that doesn't exist. + expect(SORT_LABELS.default.toLowerCase()).not.toMatch(/newest|oldest|recent/); + }); +}); + describe("applyBountyQuery", () => { const bounties = Array.from({ length: 25 }, (_, i) => bounty({ id: `b${i}`, reward: i, deadline: null }), diff --git a/src/lib/bounty-query.ts b/src/lib/bounty-query.ts index 8551bb7..24eff9a 100644 --- a/src/lib/bounty-query.ts +++ b/src/lib/bounty-query.ts @@ -36,7 +36,15 @@ export const SORT_VALUES = ["default", "reward-desc", "reward-asc", "deadline-as export type SortOption = (typeof SORT_VALUES)[number]; export const SORT_LABELS: Record = { - default: "Newest", + // Labelled "Newest" despite sortBounties leaving "default" unordered: there + // is no `createdAt` (or equivalent) field anywhere on `Bounty`, and the + // backend's listing query has no ORDER BY, so order is whatever Postgres's + // heap happens to return and can change between requests (#702). Fixing + // the label alone rather than sorting by a field that doesn't exist on + // this type — introducing one would be guessing at a backend contract this + // repo doesn't control. A real "Newest" sort needs a `createdAt` field + // exposed end-to-end first. + default: "Default order", "reward-desc": "Reward: high to low", "reward-asc": "Reward: low to high", "deadline-asc": "Deadline: soonest",