"use client"; import Link from "next/link"; import Image from "next/image"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card" import { Button } from "@/components/ui/button"; import { dataBloglist } from "@/app/api/fetch"; import { dataPagination } from "@/app/api/fetch"; import { useQuery, } from '@tanstack/react-query'; import { dehydrate } from '@tanstack/query-core'; import { ReactQueryDevtools } from '@tanstack/react-query-devtools' import { useSearchParams } from "next/navigation"; import { useState } from "react"; import PageButton from "@/components/PageButton"; import getQueryClient from "@/app/utils/getQueryClient"; import Hydrate from '@/app/utils/HydrateClient'; export interface Props { data: PropsDatum[]; meta: Meta; } export interface PropsDatum { id: number; attributes: PurpleAttributes; } export interface PurpleAttributes { title: string; slug: string; content: string; featured: boolean; createdAt: string; updatedAt: string; altthumbnail: string; descriptions: null | string; thumbnail: Thumbnail; tags: Propstags; } export interface Thumbnail { data: ThumbnailDatum[]; } export interface ThumbnailDatum { id: number; attributes: FluffyAttributes; } export interface FluffyAttributes { name: string; alternativeText: null | string; caption: null; width: number; height: number; formats: Formats; hash: string; ext: string; mime: string; size: number; url: string; previewUrl: null; provider: string; provider_metadata: null; createdAt: string; updatedAt: string; } export interface Formats { thumbnail: Small; small: Small; } export interface Small { name: string; hash: string; ext: string; mime: string; path: null; width: number; height: number; size: number; url: string; } export interface Meta { pagination: Pagination; } export interface Pagination { page: number; pageSize: number; pageCount: number; total: number; } export interface UpperPrpos { props: Props; } export interface Propstags { data: Datum[]; meta: Meta; } export interface Datum { id: number; attributes: Attributes; } export interface Attributes { name_tag: string; createdAt: Date; updatedAt: Date; } const BlogListWithPagination: React.FC = async () => { const queryClient = getQueryClient() const [page, setPage] = useState(1); const pageSize = 6; const fetchProjects = () => { // Function body return fetch(process.env.NEXT_PUBLIC_STRAPI_URL + `/api/posts?populate=*&pagination[page]=${page}&pagination[pageSize]=${pageSize}&sort=createdAt:desc`) .then((res) => res.json()); }; await queryClient.prefetchQuery(['projects', page]) const dehydratedState = dehydrate(queryClient) const { isLoading, isError, error, isPreviousData, isFetching, data } = useQuery({ queryKey: ['projects', page], queryFn: () => fetchProjects(), keepPreviousData: true }) if (isLoading) { return
Loading...
; } if (isError) { return
Error: {error.message}
; } const nextPage = () => setPage(prev => prev + 1); const prevPage = () => setPage(prev => prev - 1); const pagesArray = Array(data.meta.pagination.pageCount).fill(0).map((_, index) => index + 1); console.log("titit", data); console.log(isError) return (
{data.data.map((post) => (

{post.attributes.title}

{/* Wrap the tags in a single div with flex layout */} {post.attributes.tags.data.map((tag) => (
{/* Use a single div for each tag */}
))}

{post.attributes.content}

))}
{pagesArray.map(pg => )}
); }; export default BlogListWithPagination;