generated from Blazity/next-enterprise
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from Blazity/client-queries
Client queries
- Loading branch information
Showing
6 changed files
with
95 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 33 additions & 16 deletions
49
src/components/RecommendedArticles/RecommendedArticles.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,43 @@ | ||
import { Locale } from "@/i18n/i18n" | ||
import { ArticlesGrid } from "../ArticlesGrid/ArticlesGrid" | ||
"use client" | ||
|
||
type imageInfo = { | ||
description?: { text: string } | null | ||
data: { url: string } | ||
} | ||
import { useQuery } from "@tanstack/react-query" | ||
import { Locale } from "@/i18n/i18n" | ||
import { getArticleRecommendedArticles } from "@/lib/client" | ||
import { ArticleCard, hygraphArticleToCardProps } from "../ArticleCard/ArticleCard" | ||
|
||
export type RecommendedArticle = { | ||
tags: string[] | ||
title: string | ||
slug: string | ||
id: string | ||
image?: imageInfo | null | ||
} | ||
type RecommendedArticlesProps = { id: string; lang: Locale } | ||
|
||
type RecommendedArticlesProps = { recommendedArticles: RecommendedArticle[]; lang: Locale } | ||
export function RecommendedArticles({ id, lang }: RecommendedArticlesProps) { | ||
const { data: recommendedArticles, isLoading } = useQuery({ | ||
queryKey: [`recommended-articles`, id], | ||
queryFn: () => getArticleRecommendedArticles({ locale: lang, id }), | ||
}) | ||
|
||
export async function RecommendedArticles({ recommendedArticles, lang }: RecommendedArticlesProps) { | ||
if (!isLoading && recommendedArticles?.length === 0) return null | ||
return ( | ||
<section className="w-full py-4"> | ||
<h2 className="mb-8 text-2xl font-bold">Related articles</h2> | ||
<ArticlesGrid locale={lang} articles={recommendedArticles} /> | ||
<div className={`grid grid-cols-3 gap-8`}> | ||
{isLoading && | ||
Array.from(Array(3).keys()).map((idx) => { | ||
return <ArticleSkeleton key={`skeleton-${idx}`} /> | ||
})} | ||
{!isLoading && | ||
recommendedArticles?.map((article) => { | ||
return ( | ||
<ArticleCard | ||
key={`trending-${article.id}`} | ||
article={hygraphArticleToCardProps(article)} | ||
tagsPosition="under" | ||
locale={lang} | ||
/> | ||
) | ||
})} | ||
</div> | ||
</section> | ||
) | ||
} | ||
|
||
function ArticleSkeleton() { | ||
return <div className=" h-[481px] animate-pulse rounded-xl bg-gray-100"></div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters