feat: add featured flag to project, display featured projects on home page
This commit is contained in:
+3
-1
@@ -1,6 +1,7 @@
|
||||
import { getDictionary } from "@/get-dictionary";
|
||||
import type { Locale } from "@/i18n-config";
|
||||
import HomeClient from "@/components/HomeClient";
|
||||
import { getFeaturedProjects } from "../actions";
|
||||
|
||||
export async function generateMetadata({ params }: { params: Promise<{ lang: Locale }> }) {
|
||||
const { lang } = await params;
|
||||
@@ -17,6 +18,7 @@ export async function generateMetadata({ params }: { params: Promise<{ lang: Loc
|
||||
export default async function Page({ params }: { params: Promise<{ lang: Locale }> }) {
|
||||
const { lang } = await params;
|
||||
const dict = await getDictionary(lang);
|
||||
const featuredProjects = await getFeaturedProjects();
|
||||
|
||||
return <HomeClient lang={lang} dict={dict} />;
|
||||
return <HomeClient lang={lang} dict={dict} featuredProjects={featuredProjects} />;
|
||||
}
|
||||
|
||||
+16
-1
@@ -19,9 +19,22 @@ export async function getProjects() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getFeaturedProjects() {
|
||||
try {
|
||||
return await prisma.project.findMany({
|
||||
where: { featured: true },
|
||||
orderBy: { num: "asc" },
|
||||
take: 4,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error fetching featured projects:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveProject(data: any) {
|
||||
try {
|
||||
const { id, num, slug, title, tag, desc, spec, year, client, duration, tech, challenge, solution, results, image, gallery, website } = data;
|
||||
const { id, num, slug, title, tag, desc, spec, year, client, duration, tech, challenge, solution, results, image, gallery, website, featured } = data;
|
||||
|
||||
let project;
|
||||
if (id) {
|
||||
@@ -45,6 +58,7 @@ export async function saveProject(data: any) {
|
||||
image: image || "",
|
||||
gallery: gallery || [],
|
||||
website: website || "",
|
||||
featured: featured || false,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
@@ -73,6 +87,7 @@ export async function saveProject(data: any) {
|
||||
image: image || "",
|
||||
gallery: gallery || [],
|
||||
website: website || "",
|
||||
featured: featured || false,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user