diff --git a/src/app/_components/services/page.tsx b/src/app/_components/services/page.tsx index 5688e7a..6b4a2ec 100644 --- a/src/app/_components/services/page.tsx +++ b/src/app/_components/services/page.tsx @@ -1,46 +1,72 @@ -import React from "react"; +"use client"; + +import { useEffect, useState } from "react"; +import Skeleton from "react-loading-skeleton"; +import "react-loading-skeleton/dist/skeleton.css"; -// تعریف یک نوع برای سرویس‌ها type Service = { + id: number; // افزودن id برای شناسایی هر سرویس title: string; description: string; imageSrc: string; altText: string; }; -// لیست سرویس‌ها به عنوان یک آرایه از آبجکت‌ها -const services: Service[] = [ - { - title: "UI/UX", - description: - "Lorem ipsum dolor sit amet consectetur. Morbi diam nisi nam diam interdum", - imageSrc: "/images/ui-ux-vector.svg", - altText: "UI/UX Vector", - }, - { - title: "Web Design", - description: - "Lorem ipsum dolor sit amet consectetur. Morbi diam nisi nam diam interdum", - imageSrc: "/images/web-design-vector.svg", - altText: "Web Design Vector", - }, - { - title: "App Design", - description: - "Lorem ipsum dolor sit amet consectetur. Morbi diam nisi nam diam interdum", - imageSrc: "/images/app-design-vector.svg", - altText: "App Design Vector", - }, - { - title: "Graphic Design", - description: - "Lorem ipsum dolor sit amet consectetur. Morbi diam nisi nam diam interdum", - imageSrc: "/images/graphic-design-vector.svg", - altText: "Graphic Design Vector", - }, -]; - export default function Services() { + const [services, setServices] = useState([]); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + + useEffect(() => { + const fetchServices = async () => { + try { + const response = await fetch("/api/services", { + cache: "no-store", // غیرفعال کردن کش + }); + + if (!response.ok) { + throw new Error("Failed to fetch services"); + } + + const data: Service[] = await response.json(); + setServices(data); + } catch (err: any) { + setError(err.message); + } finally { + setLoading(false); + } + }; + + fetchServices(); + + }, []); + + if (loading) { + return ( +
+

Services

+

+ Lorem ipsum dolor sit amet consectetur. Tristique amet sed massa nibh + lectus netus in. Aliquet donec morbi convallis pretium +

+
+ {Array.from({ length: 4 }).map((_, index) => ( +
+ + + +
+ ))} +
+
+ ); + } + + if (error) return

Error: {error}

; + return (

Services

@@ -49,9 +75,9 @@ export default function Services() { lectus netus in. Aliquet donec morbi convallis pretium

- {services.map((service, index) => ( + {services.map((service) => (
@@ -69,3 +95,6 @@ export default function Services() {
); } +{ + /* */ +} diff --git a/src/app/api/services/route.ts b/src/app/api/services/route.ts new file mode 100644 index 0000000..3a8736d --- /dev/null +++ b/src/app/api/services/route.ts @@ -0,0 +1,11 @@ +import { NextResponse } from "next/server"; + +export async function GET() { + const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/services`, { + cache: "no-store", // غیرفعال کردن کش + }); + + const services = await res.json(); + + return NextResponse.json(services); +}