Strip Builder CMS from Projects page and point to Admin
cgen-ee4105c0cc1a47e58fd536a2839c3cfc
This commit is contained in:
parent
9865e97baf
commit
8a43039124
1 changed files with 5 additions and 48 deletions
|
|
@ -11,7 +11,6 @@ import { Button } from "@/components/ui/button";
|
||||||
import ShowcaseCard from "@/components/showcase/ShowcaseCard";
|
import ShowcaseCard from "@/components/showcase/ShowcaseCard";
|
||||||
import { SHOWCASE, type ShowcaseProject } from "@/data/showcase";
|
import { SHOWCASE, type ShowcaseProject } from "@/data/showcase";
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { fetchBuilderList, getBuilderApiKey } from "@/lib/builder";
|
|
||||||
import { useAuth } from "@/contexts/AuthContext";
|
import { useAuth } from "@/contexts/AuthContext";
|
||||||
import { supabase } from "@/lib/supabase";
|
import { supabase } from "@/lib/supabase";
|
||||||
|
|
||||||
|
|
@ -19,7 +18,6 @@ export default function Projects() {
|
||||||
const { roles } = useAuth();
|
const { roles } = useAuth();
|
||||||
const isOwner = Array.isArray(roles) && roles.includes("owner");
|
const isOwner = Array.isArray(roles) && roles.includes("owner");
|
||||||
const [dbItems, setDbItems] = useState<ShowcaseProject[] | null>(null);
|
const [dbItems, setDbItems] = useState<ShowcaseProject[] | null>(null);
|
||||||
const [cmsItems, setCmsItems] = useState<ShowcaseProject[] | null>(null);
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -51,39 +49,10 @@ export default function Projects() {
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (dbItems && dbItems.length) return; // Skip CMS if DB has content
|
|
||||||
const apiKey = getBuilderApiKey();
|
|
||||||
if (!apiKey) return;
|
|
||||||
setLoading(true);
|
|
||||||
fetchBuilderList<any>("showcase-project", { limit: 50 })
|
|
||||||
.then((res) => {
|
|
||||||
const items: ShowcaseProject[] = (res.results || []).map((r) => ({
|
|
||||||
id: r.id,
|
|
||||||
title: r.data?.title || r.name || "Untitled",
|
|
||||||
orgUnit: r.data?.orgUnit,
|
|
||||||
role: r.data?.role,
|
|
||||||
timeframe: r.data?.timeframe,
|
|
||||||
description: r.data?.description,
|
|
||||||
tags: r.data?.tags || [],
|
|
||||||
links: r.data?.links || [],
|
|
||||||
contributors: r.data?.contributors || [],
|
|
||||||
image: r.data?.image,
|
|
||||||
}));
|
|
||||||
setCmsItems(items);
|
|
||||||
})
|
|
||||||
.catch(() => setCmsItems(null))
|
|
||||||
.finally(() => setLoading(false));
|
|
||||||
}, [dbItems]);
|
|
||||||
|
|
||||||
const items = useMemo(
|
const items = useMemo(
|
||||||
() =>
|
() => (dbItems && dbItems.length ? dbItems : SHOWCASE),
|
||||||
dbItems && dbItems.length
|
[dbItems],
|
||||||
? dbItems
|
|
||||||
: cmsItems && cmsItems.length
|
|
||||||
? cmsItems
|
|
||||||
: SHOWCASE,
|
|
||||||
[dbItems, cmsItems],
|
|
||||||
);
|
);
|
||||||
const hasProjects = Array.isArray(items) && items.length > 0;
|
const hasProjects = Array.isArray(items) && items.length > 0;
|
||||||
|
|
||||||
|
|
@ -107,19 +76,8 @@ export default function Projects() {
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{isOwner && (
|
{isOwner && (
|
||||||
<Button
|
<Button asChild variant="outline" size="sm" title="Open Projects Admin">
|
||||||
asChild
|
<a href="/projects/admin">Open Admin</a>
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
title="Edit in Builder CMS"
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
href="https://builder.io/content"
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer noopener"
|
|
||||||
>
|
|
||||||
Open CMS
|
|
||||||
</a>
|
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -137,8 +95,7 @@ export default function Projects() {
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>No projects yet</CardTitle>
|
<CardTitle>No projects yet</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
Add entries in <code>code/client/data/showcase.ts</code> or
|
Add entries in <code>code/client/data/showcase.ts</code> or use /projects/admin.
|
||||||
manage them via CMS.
|
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex items-center gap-2 pt-0 pb-6">
|
<CardContent className="flex items-center gap-2 pt-0 pb-6">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue