Skip to content

Commit

Permalink
Using a component rather than a page
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchand-Nicolas committed Aug 10, 2023
1 parent 4cae6b8 commit 5381724
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 179 deletions.
25 changes: 0 additions & 25 deletions components/quests/quizzes/step.tsx

This file was deleted.

10 changes: 9 additions & 1 deletion components/quests/task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import KeyboardArrowRightIcon from "@mui/icons-material/KeyboardArrowRight";
import Button from "../UI/button";
import { CircularProgress } from "@mui/material";
import { useAccount } from "@starknet-react/core";
import Quiz from "../quizzes/quiz";

const Task: FunctionComponent<Task> = ({
name,
Expand All @@ -22,6 +23,7 @@ const Task: FunctionComponent<Task> = ({
verifyEndpointType,
hasError,
verifyError,
setMenu,
}) => {
const [isClicked, setIsClicked] = useState(false);
const [isVerified, setIsVerified] = useState(false);
Expand Down Expand Up @@ -96,6 +98,12 @@ const Task: FunctionComponent<Task> = ({
setIsVerified(wasVerified);
}, [wasVerified]);

const openTask = () => {
if (verifyEndpointType === "quiz")
return setMenu(<Quiz setMenu={setMenu} name={name} />);
window.open(href);
};

return (
<div className={styles.task}>
<div
Expand Down Expand Up @@ -146,7 +154,7 @@ const Task: FunctionComponent<Task> = ({
<p className="mb-3">{description}</p>
<div className="flex w-full justify-center items-center">
<div className="w-2/3">
<Button onClick={() => window.open(href)}>{cta}</Button>
<Button onClick={() => openTask()}>{cta}</Button>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import React, { FunctionComponent } from "react";
import React, { Dispatch, FunctionComponent, SetStateAction } from "react";
import Menu from "./menu";
import styles from "../../../styles/components/quests/quizzes.module.css";
import Button from "../../UI/button";
import styles from "../../styles/components/quests/quizzes.module.css";
import Button from "../UI/button";

type EndScreenProps = {
quit: () => void;
setStep: Dispatch<SetStateAction<number>>;
};

const EndScreen: FunctionComponent<EndScreenProps> = ({ quit }) => {
const EndScreen: FunctionComponent<EndScreenProps> = ({ setStep }) => {
return (
<>
<div className={styles.content}>
<Menu
title="Well done !"
actionBar={<Button onClick={quit}>Go back to the quest</Button>}
actionBar={
<Button onClick={() => setStep(-2)}>Go back to the quest</Button>
}
highlightTitle={false}
>
<p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import React, { FunctionComponent } from "react";
import React, { Dispatch, FunctionComponent, SetStateAction } from "react";
import QuizControls from "./quizControls";
import Menu from "./menu";
import styles from "../../../styles/components/quests/quizzes.module.css";
import Button from "../../UI/button";
import styles from "../../styles/components/quests/quizzes.module.css";
import Button from "../UI/button";

type HomeScreenProps = {
move: (direction?: number) => void;
quit: () => void;
setStep: Dispatch<SetStateAction<number>>;
};

const HomeScreen: FunctionComponent<HomeScreenProps> = ({ move, quit }) => {
const HomeScreen: FunctionComponent<HomeScreenProps> = ({ setStep }) => {
return (
<>
<div className={styles.content}>
<Menu
title="Uniswap Oracle"
actionBar={<Button onClick={() => move()}>Start Quiz</Button>}
actionBar={
<Button onClick={() => setStep((step) => step + 1)}>
Start Quiz
</Button>
}
>
<p>
Welcome to the Uniswap Unraveled quiz – an exhilarating journey into
Expand All @@ -26,7 +29,7 @@ const HomeScreen: FunctionComponent<HomeScreenProps> = ({ move, quit }) => {
</p>
</Menu>
</div>
<QuizControls move={move} quit={quit} />
<QuizControls setStep={setStep} />
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FunctionComponent, ReactNode } from "react";
import styles from "../../../styles/components/quests/quizzes.module.css";
import styles from "../../styles/components/quests/quizzes.module.css";

type MenuProps = {
title: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FunctionComponent } from "react";
import styles from "../../../styles/components/quests/progressBar.module.css";
import CheckMarkIcon from "../../UI/iconsComponents/icons/checkMarkIcon";
import styles from "../../styles/components/quests/progressBar.module.css";
import CheckMarkIcon from "../UI/iconsComponents/icons/checkMarkIcon";

type ProgressBarProps = {
currentStep: number;
Expand Down
36 changes: 36 additions & 0 deletions components/quizzes/quiz.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from "next";
import HomeScreen from "./homeScreen";
import styles from "../../styles/components/quests/quizzes.module.css";
import { FunctionComponent, ReactNode, useEffect, useState } from "react";
import Step from "./step";
import EndScreen from "./endScreen";

type QuizProps = {
setMenu: (menu: ReactNode) => void;
name: string;
};

const Quiz: FunctionComponent<QuizProps> = ({ setMenu, name }) => {
const [step, setStep] = useState<number>(-1);

// TODO: Load data dynamically using quiz name
const steps: Array<QuizStep> = [{}, {}, {}, {}];

useEffect(() => {
if (step === -2) setMenu(null);
}, [step]);

return (
<div className={styles.mainContainer}>
{step === -1 ? (
<HomeScreen setStep={setStep} />
) : step === steps.length ? (
<EndScreen setStep={setStep} />
) : (
<Step setStep={setStep} step={step} steps={steps} />
)}
</div>
);
};

export default Quiz;
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React, { FunctionComponent } from "react";
import styles from "../../../styles/components/quests/quizzes.module.css";
import React, { Dispatch, FunctionComponent, SetStateAction } from "react";
import styles from "../../styles/components/quests/quizzes.module.css";

type QuizControlsProps = {
move: (direction?: number) => void;
quit: () => void;
setStep: Dispatch<SetStateAction<number>>;
};

const QuizControls: FunctionComponent<QuizControlsProps> = ({ move, quit }) => {
const QuizControls: FunctionComponent<QuizControlsProps> = ({ setStep }) => {
return (
<div className={styles.controls}>
<button onClick={() => move(-1)}>
<button onClick={() => setStep((step) => step - 1)}>
<svg
fill="none"
viewBox="0 0 24 24"
Expand All @@ -24,7 +23,7 @@ const QuizControls: FunctionComponent<QuizControlsProps> = ({ move, quit }) => {
</svg>
Back
</button>
<button onClick={() => quit()}>Cancel</button>
<button onClick={() => setStep(-2)}>Cancel</button>
</div>
);
};
Expand Down
24 changes: 24 additions & 0 deletions components/quizzes/step.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { Dispatch, FunctionComponent, SetStateAction } from "react";
import QuizControls from "./quizControls";
import styles from "../../styles/components/quests/quizzes.module.css";
import ProgressBar from "./progressBar";

type StepProps = {
setStep: Dispatch<SetStateAction<number>>;
step: number;
steps: Array<QuizStep>;
};

const Step: FunctionComponent<StepProps> = ({ setStep, step, steps }) => {
return (
<>
<ProgressBar currentStep={step} totalSteps={steps.length} />
<div className={styles.content}>
<button onClick={() => setStep((step) => step + 1)}>Ok</button>
</div>
<QuizControls setStep={setStep} />
</>
);
};

export default Step;
Loading

0 comments on commit 5381724

Please sign in to comment.