Skip to content

Commit

Permalink
Using separated pages insteads of components
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchand-Nicolas committed Sep 17, 2023
1 parent f4645f2 commit 8c8467f
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 177 deletions.
18 changes: 5 additions & 13 deletions components/quests/questCategory.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import React, { FunctionComponent, useState } from "react";
import React, { FunctionComponent } from "react";
import styles from "../../styles/Home.module.css";
import QuestCategoryDetails from "./questCategoryDetails";
import Link from "next/link";

type QuestCategoryProps = {
category: QuestCategory;
};

const QuestCategory: FunctionComponent<QuestCategoryProps> = ({ category }) => {
const [showMenu, setShowMenu] = useState(false);

return (
<>
<div className={styles.questCategory} onClick={() => setShowMenu(true)}>
<Link href={`/categories/${category.name}`}>
<div className={styles.questCategory}>
<div className={styles.categoryInfos}>
<h2 className="text-gray-200">{category.name} Quest</h2>
<p className="text-gray-200">
Expand All @@ -20,13 +18,7 @@ const QuestCategory: FunctionComponent<QuestCategoryProps> = ({ category }) => {
</div>
<img src={category.img} />
</div>
{showMenu && (
<QuestCategoryDetails
setShowMenu={setShowMenu}
quests={category.quests}
/>
)}
</>
</Link>
);
};

Expand Down
54 changes: 0 additions & 54 deletions components/quests/questCategoryDetails.tsx

This file was deleted.

35 changes: 0 additions & 35 deletions components/quests/questDetails.tsx

This file was deleted.

32 changes: 0 additions & 32 deletions components/quests/screenLayout.tsx

This file was deleted.

48 changes: 48 additions & 0 deletions pages/categories/[category].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { NextPage } from "next";
import React, { useContext, useEffect, useState } from "react";
import { useRouter } from "next/router";
import { QuestsContext } from "../../context/QuestsProvider";
import styles from "../../styles/category.module.css";
import homeStyles from "../../styles/Home.module.css";
import Quest from "../../components/quests/quest";
import BackButton from "../../components/UI/backButton";

const CategoriesPage: NextPage = () => {
const router = useRouter();
const { category: categoryName } = router.query;
const { categories } = useContext(QuestsContext);

const [category, setCategory] = useState<QuestCategory | undefined>();

useEffect(() => {
if (!categoryName) return;
setCategory(categories.find((cat) => cat.name === categoryName));
}, [categories, categoryName]);

return (
<div className={homeStyles.screen}>
<div className={homeStyles.backButton}>
<BackButton onClick={() => router.back()} />
</div>
<h1 className={homeStyles.title}>Onboarding quests</h1>
<div className={styles.questList}>
{category &&
category.quests.map((quest, index) => (
<Quest
key={index}
title={quest.title_card}
onClick={() => router.push(`/quest/${quest.id}`)}
imgSrc={quest.img_card}
issuer={{
name: quest.issuer,
logoFavicon: quest.logo,
}}
reward={quest.rewards_title}
/>
))}
</div>
</div>
);
};

export default CategoriesPage;
2 changes: 1 addition & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { QuestsContext } from "../context/QuestsProvider";

const Quests: NextPage = () => {
const router = useRouter();
const { quests, featuredQuest, categories, trendingQuests } =
const { featuredQuest, categories, trendingQuests } =
useContext(QuestsContext);

return (
Expand Down
42 changes: 0 additions & 42 deletions styles/Home.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,52 +111,10 @@
z-index: -1;
}

.categoryDetails {
position: fixed;
left: 0;
top: 0;
bottom: 0;
background-color: var(--background);
z-index: 10;
width: 100%;
padding-top: calc(12vh + 2em);
overflow-y: auto;
overflow-x: hidden;
}

.categoryDetails .content {
width: 100%;
min-height: calc(100% - 13vh - 4em);
max-width: calc(100% - 126px);
display: block;
margin: 0 auto;
padding: 25px;
}

.categoryDetails .footer {
width: 100%;
}

.backButton {
margin-left: 63px;
}

.categoryDetails .blur {
position: absolute;
left: 0;
top: 0;
z-index: -1;
}

.categoryDetails .questList {
display: flex;
gap: 1rem;
margin-top: 2rem;
flex-wrap: wrap;
display: flex;
justify-content: center;
}

.controls {
display: none;
gap: 1rem;
Expand Down
15 changes: 15 additions & 0 deletions styles/category.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.questList {
display: flex;
gap: 1rem;
margin-top: 2rem;
flex-wrap: wrap;
display: flex;
justify-content: center;
}

.blur {
position: absolute;
left: 0;
top: 0;
z-index: -1;
}

0 comments on commit 8c8467f

Please sign in to comment.