From f84f7fcf8b1d7e40af5def33125fecb6c40a3791 Mon Sep 17 00:00:00 2001 From: cdricms <36056008+cdricms@users.noreply.github.com> Date: Tue, 11 Feb 2025 10:21:45 +0100 Subject: [PATCH] Fixed no shortcode --- frontend/app/(main)/page.tsx | 10 +++++----- frontend/lib/getShortcode.ts | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/frontend/app/(main)/page.tsx b/frontend/app/(main)/page.tsx index c11cb27..b15426e 100644 --- a/frontend/app/(main)/page.tsx +++ b/frontend/app/(main)/page.tsx @@ -15,7 +15,7 @@ export default async function Home() { const res = await fetch(query); videos = await res.json(); } - const hero = await getShortcode("hero_image"); + const hero = await getShortcode("foo"); const systemEvolution = await getShortcode("evolution_systeme"); const fondations = await getShortcode("fondements"); const todaysPrinciples = await getShortcode("aujourdhui"); @@ -23,7 +23,7 @@ export default async function Home() {
@@ -46,7 +46,7 @@ export default async function Home() { title="Les Fondements de Latosa Escrima Concepts" position="left" image={ - fondations.media?.url ?? + fondations?.media?.url ?? "https://shadcnblocks.com/images/block/placeholder-2.svg" } > @@ -85,7 +85,7 @@ export default async function Home() { title="L’Évolution du Système" position="right" image={ - systemEvolution.media?.url ?? + systemEvolution?.media?.url ?? "https://shadcnblocks.com/images/block/placeholder-2.svg" } > @@ -133,7 +133,7 @@ export default async function Home() { title="Les Principes du Système Aujourd’hui" position="left" image={ - todaysPrinciples.media?.url ?? + todaysPrinciples?.media?.url ?? "https://shadcnblocks.com/images/block/placeholder-2.svg" } > diff --git a/frontend/lib/getShortcode.ts b/frontend/lib/getShortcode.ts index fb93924..59d6ab1 100644 --- a/frontend/lib/getShortcode.ts +++ b/frontend/lib/getShortcode.ts @@ -1,13 +1,14 @@ import IShortcode from "@/interfaces/IShortcode"; import request from "./request"; -export default async function getShortcode(code: string): Promise { +export default async function getShortcode( + code: string, +): Promise { const res = await request(`/shortcodes/${code}`, { method: "GET", requiresAuth: false, }); - if (res.status === "Error" || !res.data) - throw new Error("Shortcode doesn't exist."); + if (res.status === "Error") throw new Error("Shortcode doesn't exist."); - return res.data; + return res.data ?? null; }