diff --git a/convex/library.ts b/convex/library.ts
index e86ea60..0ad3bef 100644
--- a/convex/library.ts
+++ b/convex/library.ts
@@ -1,7 +1,9 @@
+import { paginationOptsValidator } from "convex/server"
import { mutation, query } from "./_generated/server"
import { v } from "convex/values"
import type { Doc, Id } from "./_generated/dataModel"
import type { QueryCtx } from "./_generated/server"
+import type { PaginationOptions, PaginationResult } from "convex/server"
export type BrowseArtist = {
id: Id<"artists">
@@ -268,6 +270,210 @@ export const browseSongs = query({
},
})
+export const songsSortKeyValidator = v.union(
+ v.literal("title"),
+ v.literal("artist"),
+ v.literal("album")
+)
+export const songsSortDirectionValidator = v.union(
+ v.literal("asc"),
+ v.literal("desc")
+)
+
+export type SongsSortKey = "title" | "artist" | "album"
+export type SongsSortDirection = "asc" | "desc"
+
+type GroupedSongsCursor = {
+ groupIndex: number
+ songIndex: number
+}
+
+function compareSongNames(
+ a: string,
+ b: string,
+ direction: SongsSortDirection
+): number {
+ const comparison = a.localeCompare(b)
+ return direction === "asc" ? comparison : -comparison
+}
+
+function mapSongToBrowse(
+ song: Doc<"songs">,
+ artistMap: Map