Switch Blog.tsx data loading from Builder to Supabase API
cgen-bc2ad223b3f84058abf6bd84818dccc0
This commit is contained in:
parent
5452ce8e56
commit
2d6bfd2ae1
1 changed files with 18 additions and 18 deletions
|
|
@ -12,7 +12,6 @@ import { Badge } from "@/components/ui/badge";
|
||||||
import LoadingScreen from "@/components/LoadingScreen";
|
import LoadingScreen from "@/components/LoadingScreen";
|
||||||
import { aethexToast } from "@/lib/aethex-toast";
|
import { aethexToast } from "@/lib/aethex-toast";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { fetchBuilderList } from "@/lib/builder";
|
|
||||||
import {
|
import {
|
||||||
PenTool,
|
PenTool,
|
||||||
Calendar,
|
Calendar,
|
||||||
|
|
@ -38,27 +37,28 @@ export default function Blog() {
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const list = await fetchBuilderList<any>("blog-post", { limit: 50 });
|
const res = await fetch("/api/blog?limit=50");
|
||||||
const mapped = (list.results || []).map((r) => ({
|
const data = res.ok ? await res.json() : [];
|
||||||
id: r.id,
|
if (!cancelled && Array.isArray(data)) {
|
||||||
slug: r.data?.slug || (r.name || "").toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, ""),
|
const mapped = data.map((r: any) => ({
|
||||||
title: r.data?.title || r.name,
|
id: r.id,
|
||||||
excerpt: r.data?.excerpt,
|
slug: r.slug,
|
||||||
author: r.data?.author,
|
title: r.title,
|
||||||
date: r.data?.date,
|
excerpt: r.excerpt,
|
||||||
readTime: r.data?.readTime,
|
author: r.author,
|
||||||
category: r.data?.category || "General",
|
date: r.date,
|
||||||
image: r.data?.image,
|
readTime: r.read_time,
|
||||||
likes: r.data?.likes || 0,
|
category: r.category || "General",
|
||||||
comments: r.data?.comments || 0,
|
image: r.image,
|
||||||
trending: r.data?.trending || false,
|
likes: r.likes || 0,
|
||||||
}));
|
comments: r.comments || 0,
|
||||||
if (!cancelled) {
|
trending: Boolean(r.trending),
|
||||||
|
}));
|
||||||
setPosts(mapped);
|
setPosts(mapped);
|
||||||
setFeaturedPost(mapped[0] || null);
|
setFeaturedPost(mapped[0] || null);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("Builder CMS blog fetch failed:", e);
|
console.warn("Blog fetch failed:", e);
|
||||||
} finally {
|
} finally {
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue