From 02929fffd38b3c2605fe26af4cfb71f5fd5ff1cf Mon Sep 17 00:00:00 2001 From: Jared Schoeny Date: Thu, 19 Nov 2026 19:02:47 -0700 Subject: [PATCH] Merge pull request #128 from jschoeny/feat/curated-hacks Only show curated hacks on Discover and the homepage --- src/app/discover/actions.ts | 7 +- src/app/faq/entries.md | 2 +- src/app/hack/[slug]/approve/page.tsx | 15 +++- src/app/hack/[slug]/metadata.ts | 9 ++- src/app/hack/actions.ts | 68 ++++++++++++++++-- src/app/page.tsx | 4 +- src/components/Discover/DiscoverBrowser.tsx | 2 +- src/components/Discover/DiscoverFilters.tsx | 10 +-- src/components/Hack/CurateMenuItem.tsx | 62 ++++++++++++++++ src/components/Hack/DraftStatus.tsx | 2 +- src/components/Hack/HackDetailView.tsx | 2 + src/types/db.ts | 9 +++ src/types/discover.ts | 2 +- .../20261109000000_hack_curation.sql | 72 +++++++++++++++++++ supabase/seed.sql | 3 + .../database/security_boundaries.test.sql | 21 +++++- 16 files changed, 261 insertions(+), 29 deletions(-) create mode 100644 src/components/Hack/CurateMenuItem.tsx create mode 100644 supabase/migrations/20261109000000_hack_curation.sql diff --git a/src/app/discover/actions.ts b/src/app/discover/actions.ts index 620a473..2476b08 100644 --- a/src/app/discover/actions.ts +++ b/src/app/discover/actions.ts @@ -45,9 +45,10 @@ async function generateDiscoverData(): Promise { const { data: rows, error: hacksError } = await supabase .from("hacks") .select( - `slug,title,summary,base_rom,downloads,created_by,current_patch,custom_version_name,original_author,approved_at,is_archive,completion_status,${AI_SELECT}`, + `slug,title,summary,base_rom,downloads,created_by,current_patch,custom_version_name,original_author,curated_at,is_archive,completion_status,${AI_SELECT}`, ) .eq("approved", true) + .eq("curated", true) .eq("is_archive", false) .is("deleted_at", null); if (hacksError) throw hacksError; @@ -241,7 +242,7 @@ async function generateDiscoverData(): Promise { summary: row.summary, is_archive: false, completion_status: row.completion_status, - approvedAt: row.approved_at, + curatedAt: row.curated_at, publishedAt: currentPatch?.published_at ?? null, trendingScore: recentDownloads + 8 * Math.log(downloads + 1), ai: aiDisclosureFromRow(row)?.levels ?? null, @@ -259,7 +260,7 @@ async function generateDiscoverData(): Promise { const getCachedDiscoverData = cache( generateDiscoverData, // Bump the version when DiscoverHack's shape changes, so a deploy never reads the old shape. - ["discover-data", "v2"], + ["discover-data", "v3"], { revalidate: DISCOVER_REVALIDATE_SECONDS, tags: ["discover"], diff --git a/src/app/faq/entries.md b/src/app/faq/entries.md index daff893..fd24b07 100644 --- a/src/app/faq/entries.md +++ b/src/app/faq/entries.md @@ -112,7 +112,7 @@ Both formats support checksum verification so the patch is linked to the correct ### How does my hack gain visibility? We highly recommend linking to your romhack's Hackdex page from PokéCommunity, Reddit, or other social media platforms. Doing so can help boost your hack's visibility and outrank those sketchy ROM sharing sites that steal many creators' hard work. -Once approved, your hack can appear on Discover. "Newest" sorts by approval date, and "Recently updated" sorts by the publication date of your current patch. "Most popular" and "Trending" use download activity. These listings are ordered automatically and do not reflect staff preferences. +Once approved, your hack gets a public page. Staff choose which approved hacks appear on Discover and the homepage, and those listings are ordered automatically. "Newest" sorts by the date a hack was curated, and "Recently updated" sorts by the publication date of your current patch. "Most popular" and "Trending" use download activity. Here are some helpful tips for improving your hack's page to help increase visibility: - Include at least 3 screenshots that help make your hack stand out, with the first one being the most eye-catching. diff --git a/src/app/hack/[slug]/approve/page.tsx b/src/app/hack/[slug]/approve/page.tsx index 30db5fb..fe35299 100644 --- a/src/app/hack/[slug]/approve/page.tsx +++ b/src/app/hack/[slug]/approve/page.tsx @@ -25,7 +25,7 @@ export default async function ApprovePage({ params }: ApprovePageProps) { // Fetch hack data const { data: hack, error } = await supabase .from("hacks") - .select("title, approved, approved_at, approved_by, created_by, submitted_at, ai_disclosed_at") + .select("title, approved, approved_at, approved_by, created_by, submitted_at, ai_disclosed_at, is_archive") .eq("slug", slug) .maybeSingle(); @@ -67,7 +67,8 @@ export default async function ApprovePage({ params }: ApprovePageProps) { async function handleApprove(formData: FormData) { "use server"; const verified = creatorProfile?.verified ? undefined : formData.get("verified") === "on"; - await approveHack(slug, verified); + const curate = formData.get("curate") === "on"; + await approveHack(slug, { verified, curate }); } return ( @@ -126,6 +127,16 @@ export default async function ApprovePage({ params }: ApprovePageProps) { )} + {/* Discover and the homepage only list curated hacks. Archives are never curated. */} + {!hack.is_archive && ( +
+ + +
+ )}
- setAi({ ...value.ai, disclosedOnly: !value.ai.disclosedOnly })} - /> diff --git a/src/components/Hack/CurateMenuItem.tsx b/src/components/Hack/CurateMenuItem.tsx new file mode 100644 index 0000000..3ed67ef --- /dev/null +++ b/src/components/Hack/CurateMenuItem.tsx @@ -0,0 +1,62 @@ +"use client"; + +import { MenuItem } from "@headlessui/react"; +import { useRouter } from "next/navigation"; +import { useState } from "react"; +import { FaRegStar, FaStar } from "react-icons/fa6"; +import { toast } from "sonner"; + +import { setHackCurated } from "@/app/hack/actions"; + +interface CurateMenuItemProps { + slug: string; + curated: boolean; +} + +/** Admin menu item that adds a hack to, or removes it from, Discover and the homepage. */ +export default function CurateMenuItem({ slug, curated }: CurateMenuItemProps) { + const router = useRouter(); + const [isPending, setIsPending] = useState(false); + const StarIcon = curated ? FaStar : FaRegStar; + + const handleToggle = async () => { + if (isPending) return; + + setIsPending(true); + try { + const result = await setHackCurated(slug, !curated); + if (!result.ok) { + toast.error(result.error); + return; + } + + // The menu closes on click, so the star's pop plays in the toast. + if (curated) { + toast.success("Un-curated. It no longer appears on Discover or the homepage.", { icon: }); + } else { + toast.success("Curated. It now appears on Discover and the homepage.", { icon: }); + } + router.refresh(); + } catch { + toast.error("Failed to update this hack's curation."); + } finally { + setIsPending(false); + } + }; + + const label = curated ? "Un-curate" : "Curate"; + const pendingLabel = curated ? "Un-curating…" : "Curating…"; + + return ( + + + {isPending ? pendingLabel : label} + + ); +} diff --git a/src/components/Hack/DraftStatus.tsx b/src/components/Hack/DraftStatus.tsx index fda0043..990eb28 100644 --- a/src/components/Hack/DraftStatus.tsx +++ b/src/components/Hack/DraftStatus.tsx @@ -235,7 +235,7 @@ function NextSteps() { const steps = [ ["A volunteer reviews your page and patch", null], ["They may reach out to confirm it’s yours", "Using your verification contact."], - ["Once approved, it’s listed on Discover", "Edits you make now are included in the review."], + ["Once approved, it gets a public page you can share", "Edits you make now are included in the review."], ] as const; return (
    diff --git a/src/components/Hack/HackDetailView.tsx b/src/components/Hack/HackDetailView.tsx index 9bc3afd..76c9c6b 100644 --- a/src/components/Hack/HackDetailView.tsx +++ b/src/components/Hack/HackDetailView.tsx @@ -1,6 +1,7 @@ import Avatar from "@/components/Account/Avatar"; import CollapsibleTags from "@/components/Hack/CollapsibleTags"; import CreateReviewThreadMenuItem from "@/components/Hack/CreateReviewThreadMenuItem"; +import CurateMenuItem from "@/components/Hack/CurateMenuItem"; import DownloadsBadge from "@/components/Hack/DownloadsBadge"; import HackActions from "@/components/Hack/HackActions"; import HackOptionsMenu from "@/components/Hack/HackOptionsMenu"; @@ -308,6 +309,7 @@ export default function HackDetailView({ metadata, downloads, canEdit, canUpload Approve )} + {isAdmin && hack.approved && !isArchive && } {isAdmin && profile?.email && ( diff --git a/src/types/db.ts b/src/types/db.ts index db41388..aff96a5 100644 --- a/src/types/db.ts +++ b/src/types/db.ts @@ -223,6 +223,9 @@ export type Database = { | null created_at: string created_by: string + curated: boolean + curated_at: string | null + curated_by: string | null current_patch: number | null custom_version_name: string | null deleted_at: string | null @@ -274,6 +277,9 @@ export type Database = { | null created_at?: string created_by: string + curated?: boolean + curated_at?: string | null + curated_by?: string | null current_patch?: number | null custom_version_name?: string | null deleted_at?: string | null @@ -325,6 +331,9 @@ export type Database = { | null created_at?: string created_by?: string + curated?: boolean + curated_at?: string | null + curated_by?: string | null current_patch?: number | null custom_version_name?: string | null deleted_at?: string | null diff --git a/src/types/discover.ts b/src/types/discover.ts index e344a76..c44cf67 100644 --- a/src/types/discover.ts +++ b/src/types/discover.ts @@ -4,7 +4,7 @@ import type { AiLevels } from "@/utils/aiDisclosure"; export type DiscoverSortOption = "trending" | "popular" | "new" | "updated" | "alpha"; export interface DiscoverHack extends HackCardAttributes { - approvedAt: string | null; + curatedAt: string | null; publishedAt: string | null; trendingScore: number; /** The AI label's level per area, for the AI filter; null until the creator fills it in. */ diff --git a/supabase/migrations/20261109000000_hack_curation.sql b/supabase/migrations/20261109000000_hack_curation.sql new file mode 100644 index 0000000..5f40001 --- /dev/null +++ b/supabase/migrations/20261109000000_hack_curation.sql @@ -0,0 +1,72 @@ +-- Curated hacks are the ones shown on Discover and the homepage. Admins curate from a hack's menu; +-- an approved hack that isn't curated keeps its public page. Read and written with the service role, +-- so anon and authenticated get no SELECT grant on these columns. +alter table public.hacks + add column curated boolean not null default false, + add column curated_at timestamptz, + add column curated_by uuid references auth.users (id) on delete set null, + add constraint hacks_curated_has_date check (curated = (curated_at is not null)); + +-- The starting set: every listable hack with an AI label. Their approval date keeps the "New" order +-- as it was. curated_by stays null because no admin made this call. Skip the updated_at trigger so +-- the backfill doesn't stamp every hack with migration day. +alter table public.hacks disable trigger set_hacks_updated_at; +update public.hacks +set curated = true, curated_at = coalesce(approved_at, created_at) +where approved and ai_disclosed_at is not null and not is_archive and deleted_at is null; +alter table public.hacks enable trigger set_hacks_updated_at; + +-- Same as 20261006120000_hack_soft_delete.sql, plus the three curation columns. +create or replace function public.hacks_update_guard() +returns trigger +language plpgsql +as $function$ +begin + if current_user in ('postgres', 'dashboard_user', 'service_role') then + return new; + end if; + + if public.is_admin() then + return new; + end if; + + if tg_op = 'INSERT' then + if new.downloads <> 0 or new.is_archive or new.rejected or new.curated or num_nonnulls( + new.current_patch, new.original_author, new.permission_from, new.submitted_at, + new.approved_at, new.approved_by, new.rejected_at, new.rejected_reason, new.rejected_by, new.assigned_admin, + new.ai_graphics, new.ai_music, new.ai_story, new.ai_translation, new.ai_events, new.ai_code, new.ai_note, new.ai_disclosed_at, + new.deleted_at, new.deleted_by, new.redirect_url, + new.curated_at, new.curated_by + ) > 0 then + raise exception 'only Hackdex can set these hack fields'; + end if; + return new; + end if; + + if new.slug is distinct from old.slug then + raise exception 'non-admins cannot change slug'; + end if; + if new.created_by is distinct from old.created_by then + raise exception 'non-admins cannot change created_by'; + end if; + if new.approved is distinct from old.approved then + raise exception 'non-admins cannot change approved'; + end if; + if ( + new.downloads, new.is_archive, new.current_patch, new.original_author, new.permission_from, new.submitted_at, + new.approved_at, new.approved_by, new.rejected, new.rejected_at, new.rejected_reason, new.rejected_by, new.assigned_admin, + new.ai_graphics, new.ai_music, new.ai_story, new.ai_translation, new.ai_events, new.ai_code, new.ai_note, new.ai_disclosed_at, + new.deleted_at, new.deleted_by, new.redirect_url, + new.curated, new.curated_at, new.curated_by + ) is distinct from ( + old.downloads, old.is_archive, old.current_patch, old.original_author, old.permission_from, old.submitted_at, + old.approved_at, old.approved_by, old.rejected, old.rejected_at, old.rejected_reason, old.rejected_by, old.assigned_admin, + old.ai_graphics, old.ai_music, old.ai_story, old.ai_translation, old.ai_events, old.ai_code, old.ai_note, old.ai_disclosed_at, + old.deleted_at, old.deleted_by, old.redirect_url, + old.curated, old.curated_at, old.curated_by + ) then + raise exception 'only Hackdex can change these hack fields'; + end if; + return new; +end; +$function$; diff --git a/supabase/seed.sql b/supabase/seed.sql index ac9bf83..369c1fd 100644 --- a/supabase/seed.sql +++ b/supabase/seed.sql @@ -547,3 +547,6 @@ CROSS JOIN LATERAL generate_series(0, spec.cnt - 1) AS gs(n); -- Seeded hacks count as submitted (drafts are made in the app); otherwise the pending ones show up as private drafts. UPDATE public.hacks SET submitted_at = created_at WHERE slug LIKE 'seed-%' AND submitted_at IS NULL; + +-- Curated so Discover and the homepage have something to show locally. +UPDATE public.hacks SET curated = true, curated_at = coalesce(approved_at, created_at) WHERE slug LIKE 'seed-%' AND approved AND NOT is_archive; diff --git a/supabase/tests/database/security_boundaries.test.sql b/supabase/tests/database/security_boundaries.test.sql index 4512ac1..3d81d25 100644 --- a/supabase/tests/database/security_boundaries.test.sql +++ b/supabase/tests/database/security_boundaries.test.sql @@ -5,7 +5,7 @@ begin; create extension if not exists pgtap with schema extensions; -select plan(17); +select plan(21); insert into auth.users (id, email) values ('aaaaaaaa-0000-4000-8000-000000000001', 'owner@test.local'), @@ -58,6 +58,16 @@ select lives_ok( ); select is((select title from public.hacks where slug = 'owned-hack'), 'Renamed', 'hack edit applied'); +select throws_ok( + $$ update public.hacks set curated = true, curated_at = now() where slug = 'owned-hack' $$, + 'P0001', 'only Hackdex can change these hack fields', 'owner cannot curate their hack' +); +select throws_ok( + $$ insert into public.hacks (slug, title, summary, description, base_rom, patch_url, version, language, created_by, curated, curated_at) + values ('forged-curated', 'Forged', 's', 'd', 'poke_emerald', '', '1.0', 'English', auth.uid(), true, now()) $$, + 'P0001', 'only Hackdex can set these hack fields', 'owner cannot insert a curated hack' +); + -- An archiver who doesn't own the hack, so only the archiver policies apply. The role comes from -- protected app_metadata. select set_config('request.jwt.claims', '{"sub":"aaaaaaaa-0000-4000-8000-000000000002","role":"authenticated","app_metadata":{"archiver":true}}', true); @@ -99,6 +109,15 @@ select isnt( (select deleted_at from public.hacks where slug = 'owned-hack'), null, 'service role can soft-delete a hack' ); +update public.hacks set curated = true, curated_at = now() where slug = 'archive-hack'; +select ok( + (select curated from public.hacks where slug = 'archive-hack'), + 'service role can curate a hack' +); +select throws_ok( + $$ update public.hacks set curated_at = null where slug = 'archive-hack' $$, + '23514', null, 'a curated hack must have a curation date' +); -- A verified creator's own later edit doesn't drop their badge. reset role;