feat(mangas): per-field sort options + direction toggle on the catalog (0.88.0)
Sort the manga catalog by created / updated / title / author with an independent asc/desc direction control. An omitted `order` defaults per field (dates newest-first, text A→Z), matching the UI, so a bare `?sort=<field>` means the same thing in the browser and over the API; `sort=recent` remains a back-compat alias for `created`. - Backend: SortField/SortOrder parsed with validation (structured 422 on bad input), per-field default_order, NULLS LAST only on the nullable author key, and migration 0033 indexing mangas(updated_at DESC, id) to back the default sort and its id tie-break. - Frontend: catalog sort field + direction (SegmentedControl) on desktop and a mobile bottom sheet; pure helpers in $lib/mangaSort; keyboard-accessible direction control; visible Direction labels and a sheet "Done" button. - Tests: backend integration coverage (defaults, alias, invalid input, ascending-id tie-break), frontend unit + e2e. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { request, type Manga, type MangaStatus, type Page } from './client';
|
||||
import type { ContentWarning } from './page_tags';
|
||||
|
||||
export type MangaSort = 'recent' | 'title';
|
||||
export type MangaSort = 'created' | 'updated' | 'title' | 'author';
|
||||
export type SortOrder = 'asc' | 'desc';
|
||||
|
||||
export type AuthorRef = { id: string; name: string };
|
||||
export type GenreRef = { id: string; name: string };
|
||||
@@ -39,6 +40,7 @@ export type ListOptions = {
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
sort?: MangaSort;
|
||||
order?: SortOrder;
|
||||
};
|
||||
|
||||
export type MangasPage = {
|
||||
@@ -68,6 +70,7 @@ export async function listMangas(opts: ListOptions = {}): Promise<MangasPage> {
|
||||
if (opts.limit != null) params.set('limit', String(opts.limit));
|
||||
if (opts.offset != null) params.set('offset', String(opts.offset));
|
||||
if (opts.sort) params.set('sort', opts.sort);
|
||||
if (opts.order) params.set('order', opts.order);
|
||||
const qs = params.toString();
|
||||
return request<MangasPage>(`/v1/mangas${qs ? `?${qs}` : ''}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user