diff options
| author | Fuwn <[email protected]> | 2026-02-07 01:42:57 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-07 01:42:57 -0800 |
| commit | 5c5b1993edd890a80870ee05607ac5f088191d4e (patch) | |
| tree | a721b76bcd49ba10826c53efc87302c7a689512f /apps/web/lib/queries/use-entry-highlights.ts | |
| download | asa.news-5c5b1993edd890a80870ee05607ac5f088191d4e.tar.xz asa.news-5c5b1993edd890a80870ee05607ac5f088191d4e.zip | |
feat: asa.news RSS reader with developer tier, REST API, and webhooks
Full-stack RSS reader SaaS: Supabase + Next.js + Go worker.
Includes three subscription tiers (free/pro/developer), API key auth,
read-only REST API, webhook push notifications, Stripe billing with
proration, and PWA support.
Diffstat (limited to 'apps/web/lib/queries/use-entry-highlights.ts')
| -rw-r--r-- | apps/web/lib/queries/use-entry-highlights.ts | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/apps/web/lib/queries/use-entry-highlights.ts b/apps/web/lib/queries/use-entry-highlights.ts new file mode 100644 index 0000000..3fdada5 --- /dev/null +++ b/apps/web/lib/queries/use-entry-highlights.ts @@ -0,0 +1,56 @@ +"use client" + +import { useQuery } from "@tanstack/react-query" +import { createSupabaseBrowserClient } from "@/lib/supabase/client" +import { queryKeys } from "./query-keys" +import type { Highlight } from "@/lib/types/highlight" + +interface HighlightRow { + id: string + entry_id: string + highlighted_text: string + note: string | null + text_offset: number + text_length: number + text_prefix: string + text_suffix: string + color: string + created_at: string +} + +function mapRowToHighlight(row: HighlightRow): Highlight { + return { + identifier: row.id, + entryIdentifier: row.entry_id, + highlightedText: row.highlighted_text, + note: row.note, + textOffset: row.text_offset, + textLength: row.text_length, + textPrefix: row.text_prefix, + textSuffix: row.text_suffix, + color: row.color, + createdAt: row.created_at, + } +} + +export function useEntryHighlights(entryIdentifier: string | null) { + const supabaseClient = createSupabaseBrowserClient() + + return useQuery({ + queryKey: queryKeys.highlights.forEntry(entryIdentifier ?? ""), + enabled: !!entryIdentifier, + queryFn: async () => { + const { data, error } = await supabaseClient + .from("user_highlights") + .select( + "id, entry_id, highlighted_text, note, text_offset, text_length, text_prefix, text_suffix, color, created_at" + ) + .eq("entry_id", entryIdentifier!) + .order("text_offset", { ascending: true }) + + if (error) throw error + + return ((data as unknown as HighlightRow[]) ?? []).map(mapRowToHighlight) + }, + }) +} |