diff --git a/src/components/ArticleCard/HeroArticleCard.tsx b/src/components/ArticleCard/HeroArticleCard.tsx index eb450678..924a8553 100644 --- a/src/components/ArticleCard/HeroArticleCard.tsx +++ b/src/components/ArticleCard/HeroArticleCard.tsx @@ -62,7 +62,7 @@ export function HeroArticleCard({ )}
-
+
{tags.map((tag) => { return {tag} })} diff --git a/src/components/CategoryArticles/CategoryArticlesInfinite.tsx b/src/components/CategoryArticles/CategoryArticlesInfinite.tsx index 63a6742a..5185a59b 100644 --- a/src/components/CategoryArticles/CategoryArticlesInfinite.tsx +++ b/src/components/CategoryArticles/CategoryArticlesInfinite.tsx @@ -52,7 +52,11 @@ export function RecentArticlesInfinite({ initialArticles, category }: CategoryAr articles={articles} /> {hasNextPage && ( - )} diff --git a/src/components/Navigation/Navigation.tsx b/src/components/Navigation/Navigation.tsx index 9f320163..50ffd52c 100644 --- a/src/components/Navigation/Navigation.tsx +++ b/src/components/Navigation/Navigation.tsx @@ -53,9 +53,11 @@ export function Navigation({ locale, navigation }: NavigationProps) { setIsSheetOpen((prev) => !prev)}> - +
  • + +
  • {navElements} diff --git a/src/components/Quiz/QuizLogic.tsx b/src/components/Quiz/QuizLogic.tsx index f78e2885..616f3da9 100644 --- a/src/components/Quiz/QuizLogic.tsx +++ b/src/components/Quiz/QuizLogic.tsx @@ -3,45 +3,35 @@ import { useQuery } from "@tanstack/react-query" import { ArrowRight, Check, XCircle } from "lucide-react" import { useState } from "react" -import { GetQuizQuestionsByIdQuery, QuizAnswer, QuizQuestion } from "@/gql/graphql" +import { QuizAnswer, QuizQuestion } from "@/gql/graphql" import { useLocale } from "@/i18n/useLocale" import { getQuizQuestionsById } from "@/lib/client" import { cn } from "@/utils/cn" import { RichText } from "../RichText/RichText" +import { Skeleton } from "../ui/Skeleton/Skeleton" type ExtendedQuizAnswer = QuizAnswer & { status?: "clicked" | null } type ExtendedQuizQuestion = QuizQuestion & { answer: ExtendedQuizAnswer[]; isAnswered?: boolean } -type Quiz = GetQuizQuestionsByIdQuery["quiz"] & { - isAnswered: boolean - question: ExtendedQuizQuestion[] - answer: ExtendedQuizAnswer[] - id: string -} - -export type QuizProps = { - initialQuiz: Quiz -} +export type QuizProps = { id: string } -export function QuizLogic({ initialQuiz }: QuizProps) { +export function QuizLogic({ id }: QuizProps) { const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0) - const [questions, setQuestions] = useState(initialQuiz?.question) + const [questions, setQuestions] = useState([]) const locale = useLocale() - const { data } = useQuery( - ["quiz-questions", initialQuiz?.id], - () => getQuizQuestionsById({ locale, id: initialQuiz.id || "", skip: 0 }), + const { data, isLoading } = useQuery( + ["quiz-questions", id], + () => getQuizQuestionsById({ locale, id: id || "", skip: 0 }), { - placeholderData: initialQuiz?.question, - enabled: !!initialQuiz, onSuccess: (data) => { setQuestions(data as QuizQuestion[]) }, } ) - const currentQuestion = questions[currentQuestionIndex] + const currentQuestion = questions?.[currentQuestionIndex] const pickAnswer = (id: string) => { setQuestions((prev) => { @@ -93,36 +83,36 @@ export function QuizLogic({ initialQuiz }: QuizProps) { setCurrentQuestionIndex((prev) => prev - 1) } + if (isLoading && !data) return + return (
    - {data && ( -
    -
    - -

    - {currentQuestionIndex + 1}/{data?.length} -

    -
    -
      - {currentQuestion.answer.map((answer: ExtendedQuizAnswer, index) => ( -
    • handleClickQuestion(answer.id)} - key={index} - className={cn( - answer.status && answer.isValid && "bg-black", - answer.status && !answer.isValid && "bg-custom-gray-200", - !answer.status && !currentQuestion.isAnswered && "cursor-pointer hover:bg-slate-50", - "flex items-center justify-between rounded-xl border-[1px] px-4 py-2" - )} - > - - {answer.status && answer.isValid && } - {answer.status && !answer.isValid && } -
    • - ))} -
    +
    +
    + +

    + {currentQuestionIndex + 1}/{data?.length} +

    - )} +
      + {currentQuestion?.answer?.map((answer: ExtendedQuizAnswer, index) => ( +
    • handleClickQuestion(answer.id)} + key={index} + className={cn( + answer.status && answer.isValid && "bg-black", + answer.status && !answer.isValid && "bg-custom-gray-200", + !answer.status && !currentQuestion.isAnswered && "cursor-pointer hover:bg-slate-50", + "flex items-center justify-between rounded-xl border-[1px] px-4 py-2" + )} + > + + {answer.status && answer.isValid && } + {answer.status && !answer.isValid && } +
    • + ))} +
    +
    {hasNextPage && ( - )} diff --git a/src/components/RecommendedArticles/RecommendedArticles.tsx b/src/components/RecommendedArticles/RecommendedArticles.tsx index 7e55bbc5..a9acfc18 100644 --- a/src/components/RecommendedArticles/RecommendedArticles.tsx +++ b/src/components/RecommendedArticles/RecommendedArticles.tsx @@ -17,7 +17,7 @@ export function RecommendedArticles({ id, lang }: RecommendedArticlesProps) { return (

    Related articles

    -
    +
    {isLoading && Array.from(Array(3).keys()).map((idx) => { return diff --git a/src/components/RichText/RichText.tsx b/src/components/RichText/RichText.tsx index 932e5f5a..2653862e 100644 --- a/src/components/RichText/RichText.tsx +++ b/src/components/RichText/RichText.tsx @@ -2,9 +2,9 @@ import { RichText as HygraphRichText } from "@graphcms/rich-text-react-renderer" import { EmbedReferences, RichTextContent } from "@graphcms/rich-text-types" import Image from "next/image" +import { cn } from "@/utils/cn" import { CodeSnippetDynamic } from "../CodeSnippet/CodeSnippetDynamic" import { QuizDynamic } from "../Quiz/QuizDynamic" -import { cn } from "@/utils/cn" export function RichText({ raw, @@ -46,7 +46,7 @@ export function RichText({ ), embed: { Quiz: (props) => { - return + return }, }, }} diff --git a/src/components/Search/SearchDialog.tsx b/src/components/Search/SearchDialog.tsx index 02c7a10e..a948051b 100644 --- a/src/components/Search/SearchDialog.tsx +++ b/src/components/Search/SearchDialog.tsx @@ -46,7 +46,7 @@ function SearchDialogContent() { - + diff --git a/src/components/TrendingArticles/TrendingArticles.tsx b/src/components/TrendingArticles/TrendingArticles.tsx index e1577845..b153cf25 100644 --- a/src/components/TrendingArticles/TrendingArticles.tsx +++ b/src/components/TrendingArticles/TrendingArticles.tsx @@ -28,7 +28,7 @@ export async function TrendingArticles({ locale, title }: TrendingArticlesProps)
    {mainArticle && ( -
    +
    ) { + return
    +} + +export { Skeleton } diff --git a/src/lib/queries/articles.ts b/src/lib/queries/articles.ts index acfdda55..20236d97 100644 --- a/src/lib/queries/articles.ts +++ b/src/lib/queries/articles.ts @@ -104,20 +104,6 @@ export const getArticleBySlugQuery = graphql(` references { ... on Quiz { id - question(first: 1) { - id - answer { - id - content { - raw - } - isValid - } - content { - raw - } - } - title } } }