aboutMe data is serverside now
This commit is contained in:
1 parent
08fe8466ed
commit
e21c4fbe5a
5 files changed
+47
-33
No files matched your search
+1
-1
@@ -3,7 +3,7 @@
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"dev": "next dev --turbo",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
|
||||
@@ -4,7 +4,7 @@ import React, { useEffect, useState } from "react";
|
||||
import Skeleton from "react-loading-skeleton";
|
||||
import "react-loading-skeleton/dist/skeleton.css";
|
||||
|
||||
type Skill = {
|
||||
type SkillType = {
|
||||
id: 1;
|
||||
title: string;
|
||||
image: string;
|
||||
@@ -16,46 +16,36 @@ type Skill = {
|
||||
updated_at: string;
|
||||
};
|
||||
|
||||
type AboutMeData = {
|
||||
type AboutMeDataType = {
|
||||
id: number;
|
||||
title: string;
|
||||
description: string;
|
||||
image: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
skills: Skill[];
|
||||
skills: SkillType[];
|
||||
};
|
||||
|
||||
export default function AboutMe() {
|
||||
const [aboutMe, setAboutMe] = useState<AboutMeData | null>(null);
|
||||
useEffect(() => {
|
||||
const fetchAboutMeData = async () => {
|
||||
const res = await fetch("/api/about-me");
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
setAboutMe(data);
|
||||
} else {
|
||||
console.error("Failed to fetch about me data");
|
||||
}
|
||||
};
|
||||
fetchAboutMeData();
|
||||
}, []);
|
||||
type AboutMeProps = {
|
||||
data: AboutMeDataType;
|
||||
};
|
||||
|
||||
export default function AboutMe({ data }: AboutMeProps) {
|
||||
return (
|
||||
<div
|
||||
className="my-10 flex max-w-[90%] w-full flex-wrap items-center justify-center gap-10 pt-[120px]"
|
||||
className="my-10 flex w-full max-w-[90%] flex-wrap items-center justify-center gap-10 pt-[120px]"
|
||||
id="about-me"
|
||||
>
|
||||
<div className="flex flex-col w-full items-center md:w-[50%]">
|
||||
<div className="flex w-full flex-col items-center md:w-[50%]">
|
||||
<h2 className="mb-10 text-[55px] font-[800] text-black">
|
||||
{aboutMe?.title || <Skeleton width={300} height={100} />}
|
||||
{data?.title || <Skeleton width={300} height={100} />}
|
||||
</h2>
|
||||
<p className="text-justify text-[21px] font-[400] text-black">
|
||||
{aboutMe?.description || <Skeleton width={350} height={30} />}
|
||||
{data?.description || <Skeleton width={350} height={30} />}
|
||||
</p>
|
||||
<ul className="mt-10 flex w-full flex-col gap-10">
|
||||
{aboutMe?.skills ? (
|
||||
aboutMe?.skills.map((skill, key) => (
|
||||
{data?.skills ? (
|
||||
data?.skills.map((skill, key) => (
|
||||
<li key={key}>
|
||||
<h3 className="mb-2 text-[18px] font-[700]">{skill.title}</h3>
|
||||
<div className="h relative h-[12px] w-full rounded-lg bg-[#EDECEC]">
|
||||
@@ -76,9 +66,9 @@ export default function AboutMe() {
|
||||
)}
|
||||
</ul>
|
||||
</div>
|
||||
{aboutMe?.image ? (
|
||||
{data?.image ? (
|
||||
<div className="flex w-full max-w-[90%] items-center justify-center md:w-[40%]">
|
||||
<img src={aboutMe.image} alt="profile picture" className="" />
|
||||
<img src={data.image} alt="profile picture" className="" />
|
||||
</div>
|
||||
) : (
|
||||
<Skeleton circle={true} width={360} height={360} />
|
||||
|
||||
@@ -4,6 +4,6 @@ export async function GET() {
|
||||
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/about-me`, {
|
||||
cache: "no-store" // غیرفعال کردن کش
|
||||
});
|
||||
const data = await response.json();
|
||||
const data = await response.json();
|
||||
return NextResponse.json(data);
|
||||
}
|
||||
@@ -3,8 +3,6 @@ import Link from "next/link";
|
||||
|
||||
export default function NotFound() {
|
||||
const imageUrl = `/images/404/${Math.floor(Math.random() * 5) + 1}.jpg`;
|
||||
console.log(imageUrl);
|
||||
|
||||
return (
|
||||
<div className="mt-[120px] flex flex-col items-center justify-center gap-3">
|
||||
<Image src={imageUrl} width={500} height={500} alt="404 illustration" />
|
||||
|
||||
+30
-4
@@ -5,12 +5,39 @@ import AboutMe from "./_components/about-me/page";
|
||||
import Services from "./_components/services/page";
|
||||
import MyProjects from "./_components/my-projects/page";
|
||||
|
||||
export default function Home() {
|
||||
type SkillType = {
|
||||
id: 1;
|
||||
title: string;
|
||||
image: string;
|
||||
description: string;
|
||||
link: string;
|
||||
percentage: number;
|
||||
about_me_id: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
};
|
||||
|
||||
type AboutMeDataType = {
|
||||
id: number;
|
||||
title: string;
|
||||
description: string;
|
||||
image: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
skills: SkillType[];
|
||||
};
|
||||
|
||||
export default async function Home() {
|
||||
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/about-me`, {
|
||||
cache: "no-store", // غیرفعال کردن کش
|
||||
});
|
||||
let aboutMeData: AboutMeDataType = await response.json();
|
||||
|
||||
return (
|
||||
<div className="my-15 flex w-full max-w-[1420px] flex-col items-center gap-[50px]">
|
||||
{/* Home */}
|
||||
<div
|
||||
className="xl:gap-15 flex w-full flex-wrap justify-center gap-10 lg:flex-nowrap 2xl:gap-20 pt-[120px]"
|
||||
className="xl:gap-15 flex w-full flex-wrap justify-center gap-10 pt-[120px] lg:flex-nowrap 2xl:gap-20"
|
||||
id="home"
|
||||
>
|
||||
{/* start */}
|
||||
@@ -81,7 +108,7 @@ export default function Home() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AboutMe />
|
||||
<AboutMe data={aboutMeData} />
|
||||
|
||||
<Services />
|
||||
|
||||
@@ -93,4 +120,3 @@ export default function Home() {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user