gm4ebnr3j: Add three-column layout with featured experts and trending minnects rails

This commit is contained in:
2026-10-19 17:28:42 -06:00
parent 6201fb0d28
commit b97a77471b
7 changed files with 267 additions and 1 deletions
+32
View File
@@ -0,0 +1,32 @@
// Browser-side reader for the same-origin GET /api/discover route.
import type { DiscoverData } from "./discover";
export class DiscoverLoadError extends Error {
constructor() {
super("discover_unavailable");
}
}
const arr = <T>(v: unknown): T[] => (Array.isArray(v) ? (v as T[]) : []);
export async function fetchDiscover(
fetchImpl: typeof fetch = fetch,
): Promise<DiscoverData> {
let res: Response;
try {
res = await fetchImpl("/api/discover", { credentials: "same-origin" });
} catch {
throw new DiscoverLoadError();
}
if (!res.ok) throw new DiscoverLoadError();
try {
const body = (await res.json()) as Record<string, unknown>;
return {
featuredExperts: arr(body.featuredExperts),
trendingMinnects: arr(body.trendingMinnects),
categories: arr(body.categories),
};
} catch {
throw new DiscoverLoadError();
}
}