Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: footer in category detail #208

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions components/UI/iconsComponents/icons/checkIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { FunctionComponent } from "react";

const CheckIcon: FunctionComponent<IconProps> = ({ width, color }) => {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width={width}
height={width}
viewBox="0 0 24 24"
fill="none"
>
<path
d="M12 2C6.49 2 2 6.49 2 12C2 17.51 6.49 22 12 22C17.51 22 22 17.51 22 12C22 6.49 17.51 2 12 2ZM16.78 9.7L11.11 15.37C10.97 15.51 10.78 15.59 10.58 15.59C10.38 15.59 10.19 15.51 10.05 15.37L7.22 12.54C6.93 12.25 6.93 11.77 7.22 11.48C7.51 11.19 7.99 11.19 8.28 11.48L10.58 13.78L15.72 8.64C16.01 8.35 16.49 8.35 16.78 8.64C17.07 8.93 17.07 9.4 16.78 9.7Z"
fill={color}
/>
</svg>
);
};

export default CheckIcon;
1 change: 1 addition & 0 deletions components/pages/home/trending.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const TrendingQuests: FunctionComponent<TrendingQuestsProps> = ({
logoFavicon: quest.logo,
}}
reward={quest.rewards_title}
id={quest.id}
/>
);
})
Expand Down
26 changes: 23 additions & 3 deletions components/quests/quest.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React, { FunctionComponent } from "react";
import React, { FunctionComponent, useMemo } from "react";
import styles from "../../styles/quests.module.css";
import { useContext } from "react";
import { QuestsContext } from "../../context/QuestsProvider";
import CheckIcon from "../UI/iconsComponents/icons/checkIcon";

type QuestProps = {
onClick: () => void;
imgSrc: string;
title: string;
issuer: Issuer;
reward: string;
id: number;
};

const Quest: FunctionComponent<QuestProps> = ({
Expand All @@ -15,7 +19,14 @@ const Quest: FunctionComponent<QuestProps> = ({
title,
issuer,
reward,
id,
}) => {
const { completedQuestIds } = useContext(QuestsContext);
const isCompleted = useMemo(
() => completedQuestIds.includes(id),
[id, completedQuestIds]
);

return (
<>
<div className={styles.questCard} onClick={onClick}>
Expand All @@ -26,8 +37,17 @@ const Quest: FunctionComponent<QuestProps> = ({
<p className="text-gray-400">{issuer.name}</p>
</div>
<div className="flex mt-2 mb-1 items-center">
<img width={20} src={issuer.logoFavicon} />
<p className="text-white ml-2">{reward}</p>
{isCompleted ? (
<>
<p className="text-white mr-2">Done</p>
<CheckIcon width="24" color="#6AFFAF" />
</>
) : (
<>
<img width={20} src={issuer.logoFavicon} />
<p className="text-white ml-2">{reward}</p>
</>
)}
</div>
</div>
</div>
Expand Down
25 changes: 23 additions & 2 deletions context/QuestsProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { ReactNode, createContext, useMemo, useState } from "react";
import { QueryError, QuestDocument } from "../types/backTypes";
import { useAccount } from "@starknet-react/core";
import { hexToDecimal } from "../utils/feltService";

interface QuestsConfig {
quests: QuestDocument[];
featuredQuest?: QuestDocument;
categories: QuestCategory[];
trendingQuests: QuestDocument[];
completedQuestIds: number[];
}

type GetQuestsRes =
Expand All @@ -19,6 +22,7 @@ export const QuestsContext = createContext<QuestsConfig>({
featuredQuest: undefined,
categories: [],
trendingQuests: [],
completedQuestIds: [],
});

export const QuestsContextProvider = ({
Expand All @@ -32,6 +36,8 @@ export const QuestsContextProvider = ({
>();
const [categories, setCategories] = useState<QuestCategory[]>([]);
const [trendingQuests, setTrendingQuests] = useState<QuestDocument[]>([]);
const [completedQuestIds, setCompletedQuestIds] = useState<number[]>([]);
const { address } = useAccount();

useMemo(() => {
fetch(`${process.env.NEXT_PUBLIC_API_LINK}/get_quests`)
Expand Down Expand Up @@ -61,14 +67,29 @@ export const QuestsContextProvider = ({
});
}, []);

useMemo(() => {
if (!address) return;
fetch(
`${
process.env.NEXT_PUBLIC_API_LINK
}/get_completed_quests?addr=${hexToDecimal(address)}`
)
.then((response) => response.json())
.then((data: number[] | QueryError) => {
if ((data as QueryError).error) return;
setCompletedQuestIds(data as number[]);
});
}, [address]);

const contextValues = useMemo(() => {
return {
quests,
featuredQuest,
categories,
trendingQuests: trendingQuests,
trendingQuests,
completedQuestIds,
};
}, [quests, featuredQuest, categories, trendingQuests]);
}, [quests, featuredQuest, categories, trendingQuests, completedQuestIds]);

return (
<QuestsContext.Provider value={contextValues}>
Expand Down
9 changes: 7 additions & 2 deletions pages/categories/[category].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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";
import Blur from "../../components/shapes/blur";

const CategoriesPage: NextPage = () => {
const router = useRouter();
Expand All @@ -20,8 +21,11 @@ const CategoriesPage: NextPage = () => {
}, [categories, categoryName]);

return (
<div className={homeStyles.screen}>
<div className={homeStyles.backButton}>
<div className={styles.screen}>
<div className={homeStyles.blur1}>
<Blur />
</div>
<div className={styles.backButton}>
<BackButton onClick={() => router.back()} />
</div>
<h1 className={homeStyles.title}>Onboarding quests</h1>
Expand All @@ -38,6 +42,7 @@ const CategoriesPage: NextPage = () => {
logoFavicon: quest.logo,
}}
reward={quest.rewards_title}
id={quest.id}
/>
))}
</div>
Expand Down
2 changes: 2 additions & 0 deletions styles/Home.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
position: absolute;
left: 0;
top: 0;
z-index: -1;
}

.blur2 {
Expand All @@ -113,6 +114,7 @@

.backButton {
margin-left: 63px;
z-index: 10;
}

.controls {
Expand Down
19 changes: 19 additions & 0 deletions styles/category.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
.screen {
z-index: 0;
position: relative;
padding-top: 12vh;
background-color: var(--background);
width: 100%;
min-height: calc(100vh - 117px - 2em);
display: flex;
justify-content: center;
flex-direction: column;
}

.backButton {
position: absolute;
margin-left: 63px;
z-index: 10;
top: 12vh;
}

.questList {
display: flex;
gap: 1rem;
Expand Down