Skip to content

Commit

Permalink
style: more UI updates and package upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoEscaleira committed Mar 10, 2024
1 parent feb837f commit cde3374
Show file tree
Hide file tree
Showing 5 changed files with 341 additions and 307 deletions.
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@
"compile:gql": "graphql-codegen"
},
"dependencies": {
"@apollo/client": "^3.9.2",
"@apollo/client": "^3.9.6",
"@hookform/resolvers": "^3.3.4",
"@material-tailwind/react": "^2.1.9",
"@tanstack/react-table": "^8.13.2",
"@vercel/analytics": "^1.1.2",
"@vercel/analytics": "^1.2.2",
"d3-geo": "^3.1.0",
"date-fns": "^3.3.1",
"graphql": "^16.8.1",
"lucide-react": "^0.316.0",
"mapbox-gl": "^3.1.2",
"mapbox-gl": "^3.2.0",
"react": "^18.2.0",
"react-day-picker": "^8.10.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.50.0",
"react-hook-form": "^7.51.0",
"react-map-gl": "^7.1.7",
"react-modal": "^3.16.1",
"react-router-dom": "^6.22.0",
"react-router-dom": "^6.22.3",
"react-simple-maps": "^4.0.0-beta.6",
"react-tagsinput": "^3.20.3",
"react-timer-hook": "^3.0.7",
"react-toastify": "^10.0.4",
"use-breakpoint": "^4.0.1",
"use-react-countries": "^2.0.0",
"zod": "^3.22.4",
"zustand": "^4.5.0"
"zustand": "^4.5.2"
},
"devDependencies": {
"@graphql-codegen/cli": "^5.0.0",
"@graphql-codegen/client-preset": "^4.1.0",
"@graphql-codegen/cli": "^5.0.2",
"@graphql-codegen/client-preset": "^4.2.4",
"@graphql-typed-document-node/core": "^3.2.0",
"@hookform/devtools": "^4.3.1",
"@redux-devtools/extension": "^3.3.0",
Expand All @@ -54,11 +54,11 @@
"@types/react-modal": "3.16.3",
"@types/react-simple-maps": "3.0.4",
"@types/react-tagsinput": "^3.20.6",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.16",
"eslint": "^8.56.0",
"autoprefixer": "^10.4.18",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
Expand All @@ -71,10 +71,10 @@
"prettier": "^3.2.4",
"prettier-plugin-tailwindcss": "^0.5.11",
"react-simple-maps": "^4.0.0-beta.6",
"sass": "^1.70.0",
"sass": "^1.71.1",
"tailwindcss": "^3.4.1",
"typescript": "^5.3.3",
"typescript": "^5.4.2",
"vite": "5.1.5",
"vite-tsconfig-paths": "4.3.1"
}
}
}
11 changes: 6 additions & 5 deletions src/components/Quiz/QuizForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useLazyQuery, useMutation } from "@apollo/client";
import { zodResolver } from "@hookform/resolvers/zod";
import { Button, Input, Option, Select, Textarea, Typography } from "@material-tailwind/react";
import { FormProvider, SubmitHandler, useForm } from "react-hook-form";
import { useNavigate, useParams } from "react-router-dom";
import { useNavigate, useParams, useSearchParams } from "react-router-dom";
import { toast } from "react-toastify";
import { useCountries } from "use-react-countries";
import { z } from "zod";
Expand All @@ -20,10 +20,10 @@ import { GET_QUIZZES } from "@utils/queries/Quizzes.ts";
import { UPDATE_QUIZ } from "@utils/queries/UpdateQuiz.ts";
import { GET_USER_ATTEMPTS } from "@utils/queries/UserAttempts.ts";

const getDefaultValues = (quiz?: QuizByIdQuery["quizById"]) => ({
const getDefaultValues = (searchParams: URLSearchParams, quiz?: QuizByIdQuery["quizById"]) => ({
title: quiz?.title || "",
description: quiz?.description || "",
country: quiz?.country || "",
country: quiz?.country || searchParams.get("country") || "",
image: quiz?.image || "",
questions: quiz?.questions || [
{
Expand All @@ -41,6 +41,7 @@ const getDefaultValues = (quiz?: QuizByIdQuery["quizById"]) => ({
});

export function QuizForm() {
const [searchParams] = useSearchParams();
const navigate = useNavigate();
const { countries } = useCountries();
const orderedCountries = useCallback(() => {
Expand All @@ -62,7 +63,7 @@ export function QuizForm() {

const form = useForm<z.infer<typeof quizFormSchema>>({
resolver: zodResolver(quizFormSchema),
defaultValues: getDefaultValues(quiz),
defaultValues: getDefaultValues(searchParams, quiz),
});
const {
register,
Expand All @@ -74,7 +75,7 @@ export function QuizForm() {

useEffect(() => {
if (quizId && quiz) {
reset(getDefaultValues(quiz));
reset(getDefaultValues(searchParams, quiz));
}
}, [quizId, quiz]);

Expand Down
57 changes: 57 additions & 0 deletions src/pages/Game/CountryQuizCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Button, Card, CardBody, CardFooter, CardHeader, Typography } from "@material-tailwind/react";
import { useNavigate } from "react-router-dom";
import { AttemptBadge } from "@components/AttemptBadge/AttemptBadge.tsx";
import { DifficultyChip } from "@components/DifficultyChip/DifficultyChip.tsx";
import { QuizRating } from "@components/QuizRating/QuizRating.tsx";
import { TimeLimitChip } from "@components/TimeLimitChip/TimeLimitChip.tsx";
import { Difficulty } from "@generated/graphql";

interface CountryQuizCardProps {
id: string;
title: string;
description: string;
image: string;
difficulty?: Difficulty;
timeLimit?: number;
}

export const CountryQuizCard = ({ id, image, title, description, difficulty, timeLimit }: CountryQuizCardProps) => {
const navigate = useNavigate();

return (
<Card
className="w-full max-w-[20rem] border border-gray-200 shadow-lg"
onClick={() => navigate(`/game/quiz/${id}`)}
>
<CardHeader floated={false} color="blue-gray" className="flex items-center justify-center pt-3">
<img src={image} alt="the background for the quiz" className="h-40" />
<div className="to-bg-black-10 absolute inset-0 h-full w-full bg-gradient-to-tr from-transparent via-transparent to-black/60 " />
<div className="!absolute bottom-2 left-2">
<QuizRating quizId={id} />
</div>
<div className="!absolute right-2 top-2">
<AttemptBadge quizId={id} />
</div>
</CardHeader>
<CardBody className="flex-grow">
<div className="mb-3 flex items-center justify-start">
<Typography variant="h5" color="blue-gray" className="font-medium">
{title}
</Typography>
</div>
<Typography color="gray" className="break-words">
{description}
</Typography>
<div className="mt-4 flex flex-wrap gap-3">
<DifficultyChip difficulty={difficulty} />
<TimeLimitChip timeLimit={timeLimit || 0} />
</div>
</CardBody>
<CardFooter className="px-6 pb-4 pt-0">
<Button size="md" color="blue" fullWidth={true} onClick={() => navigate(`/game/quiz/${id}`)}>
Go to quiz
</Button>
</CardFooter>
</Card>
);
};
65 changes: 16 additions & 49 deletions src/pages/Game/CountryQuizList.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { Button, Card, CardBody, CardFooter, CardHeader, Spinner, Tooltip, Typography } from "@material-tailwind/react";
import { Button, Spinner, Tooltip, Typography } from "@material-tailwind/react";
import { Plus } from "lucide-react";
import { useNavigate, useSearchParams } from "react-router-dom";
import { AttemptBadge } from "@components/AttemptBadge/AttemptBadge.tsx";
import { DifficultyChip } from "@components/DifficultyChip/DifficultyChip.tsx";
import { QuizRating } from "@components/QuizRating/QuizRating.tsx";
import { TimeLimitChip } from "@components/TimeLimitChip/TimeLimitChip.tsx";
import { CountryQuizzesQuery } from "@generated/graphql.ts";
import { CountryQuizzesQuery, Difficulty } from "@generated/graphql.ts";
import { CountryInfoModal } from "@pages/Game/CountryInfoModal.tsx";
import { useUserStore } from "@state/userStore.ts";
import { useCountryDetails } from "@utils/hooks/useCountryDetails.ts";
import { CountryQuizCard } from "./CountryQuizCard";

interface CountryQuizListProps {
quizList: CountryQuizzesQuery["quizzesByCountry"];
Expand All @@ -33,6 +30,8 @@ export const CountryQuizList = ({ quizList, isLoadingCountryQuizList }: CountryQ
);
}

const goToQuizForm = () => navigate(`/game/quiz/add?country=${countryDetails.name}`);

const headerContent = (
<div className="mb-4 mt-12 flex w-full items-center justify-between gap-3 border-b-2 pb-4 sm:justify-center sm:gap-14 md:mt-10 md:px-0 md:pb-6">
<Typography variant="h2" className="flex items-center gap-2 text-2xl">
Expand All @@ -46,13 +45,7 @@ export const CountryQuizList = ({ quizList, isLoadingCountryQuizList }: CountryQ

{isLoggedIn && (
<Tooltip content="Create a quiz">
<Button
variant="outlined"
color="green"
size="md"
onClick={() => navigate("/game/quiz/add")}
className="p-3"
>
<Button variant="outlined" color="green" size="md" onClick={goToQuizForm} className="p-3">
<Plus />
</Button>
</Tooltip>
Expand All @@ -77,7 +70,7 @@ export const CountryQuizList = ({ quizList, isLoadingCountryQuizList }: CountryQ
Sorry, no quizzes available for {searchParams.get("country") || "this country"} at the moment.
</Typography>
{isLoggedIn && (
<Button variant="text" color="green" size="md" onClick={() => navigate("/game/quiz/add")} className="mt-4">
<Button variant="text" color="green" size="md" onClick={goToQuizForm} className="mt-4">
Create a quiz
</Button>
)}
Expand All @@ -91,41 +84,15 @@ export const CountryQuizList = ({ quizList, isLoadingCountryQuizList }: CountryQ

<div className="flex w-full flex-wrap justify-center gap-8">
{quizList.map(({ id, title, image, description, timeLimit, difficulty }) => (
<Card
key={title}
className="w-full max-w-[20rem] border border-gray-200 shadow-lg"
onClick={() => navigate(`/game/quiz/${id}`)}
>
<CardHeader floated={false} color="blue-gray" className="items-ce nter flex justify-center pt-3">
<img src={image} alt="the background for the quiz" className="h-40" />
<div className="to-bg-black-10 absolute inset-0 h-full w-full bg-gradient-to-tr from-transparent via-transparent to-black/60 " />
<div className="!absolute bottom-2 left-2">
<QuizRating quizId={id} />
</div>
<div className="!absolute right-2 top-2">
<AttemptBadge quizId={id} />
</div>
</CardHeader>
<CardBody className="flex-grow">
<div className="mb-3 flex items-center justify-start">
<Typography variant="h5" color="blue-gray" className="font-medium">
{title}
</Typography>
</div>
<Typography color="gray" className="break-words">
{description}
</Typography>
<div className="mt-4 flex flex-wrap gap-3">
<DifficultyChip difficulty={difficulty} />
<TimeLimitChip timeLimit={timeLimit || 0} />
</div>
</CardBody>
<CardFooter className="px-6 pb-4 pt-2">
<Button size="md" color="blue" fullWidth={true} onClick={() => navigate(`/game/quiz/${id}`)}>
Go to quiz
</Button>
</CardFooter>
</Card>
<CountryQuizCard
key={id}
id={id}
title={title}
image={image}
description={description}
timeLimit={timeLimit || 0}
difficulty={difficulty || Difficulty.Unknown}
/>
))}
</div>
</>
Expand Down
Loading

0 comments on commit cde3374

Please sign in to comment.