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

feat: number of steps and participants #248

Merged
merged 4 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
56 changes: 56 additions & 0 deletions components/quests/questDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {
useEffect,
useState,
FunctionComponent,
useContext,
} from "react";
import styles from "../../styles/quests.module.css";
import Task from "./task";
Expand All @@ -23,6 +24,7 @@ import { generateCodeChallenge } from "../../utils/codeChallenge";
import Timer from "./timer";
import NftImage from "./nftImage";
import { splitByNftContract } from "../../utils/rewards";
import { StarknetIdJsContext } from "../../context/StarknetIdJsProvider";

type QuestDetailsProps = {
quest: QuestDocument;
Expand All @@ -45,6 +47,7 @@ const QuestDetails: FunctionComponent<QuestDetailsProps> = ({
const { provider } = useProvider();
const [tasks, setTasks] = useState<UserTask[]>([]);
const [rewardsEnabled, setRewardsEnabled] = useState<boolean>(false);
const { starknetIdNavigator } = useContext(StarknetIdJsContext);
const [eligibleRewards, setEligibleRewards] = useState<
Record<string, EligibleReward[]>
>({});
Expand All @@ -54,7 +57,44 @@ const QuestDetails: FunctionComponent<QuestDetailsProps> = ({
const [mintCalldata, setMintCalldata] = useState<Call[]>();
const [taskError, setTaskError] = useState<TaskError>();
const [showQuiz, setShowQuiz] = useState<ReactNode>();

const questId = quest.id.toString();
const [participants, setParticipants] = useState({
count: 0,
firstParticipants: [] as string[],
});

// This fetches the number of participants in the quest and up to 3 of their starknet ids
useEffect(() => {
if (questId && starknetIdNavigator) {
fetch(
`http://127.0.0.1:8080/get_quest_participants?quest_id=${questId}`,
irisdv marked this conversation as resolved.
Show resolved Hide resolved
{
method: "GET",
}
)
.then((response) => response.json())
.then(async (data) => {
setParticipants(data);
const addrs = data.firstParticipants;
const identities = addrs.map(async (addr: string) => {
const domain = await starknetIdNavigator
?.getStarkName(addr)
.catch(console.error);
return domain
? await starknetIdNavigator
?.getStarknetId(domain)
.catch(console.error)
: 0;
});
const identitiesResolved = await Promise.all(identities);
setParticipants({
count: data.count,
firstParticipants: identitiesResolved,
});
});
}
}, [questId, starknetIdNavigator]);

// this fetches all tasks of this quest from db
useEffect(() => {
Expand Down Expand Up @@ -272,6 +312,22 @@ const QuestDetails: FunctionComponent<QuestDetailsProps> = ({
<TasksSkeleton />
) : (
<>
<div className={styles.questStats}>
<p>{tasks.length} steps</p>
<div className="ml-auto flex">
<div className={styles.participantAvatars}>
{participants.firstParticipants.map((participant, index) => (
<img
src={`https://www.starknet.id/api/identicons/${participant}`}
alt="user icons"
width="24"
key={index}
/>
))}
</div>
<p>{participants.count || 0} participants</p>
</div>
</div>
{tasks.map((task) => {
return (
<Task
Expand Down
22 changes: 22 additions & 0 deletions styles/quests.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@
flex-grow: 0;
}

.questStats {
max-width: 90%;
width: 728px;
display: flex;
}

.taskTitle {
display: flex;
flex-direction: row;
Expand Down Expand Up @@ -261,6 +267,22 @@
align-items: flex-start;
}

.participantAvatars {
display: flex;
align-items: right;
justify-content: right;
margin-right: calc(1rem + 10px);
height: 24px;
min-width: 72px;
}

.participantAvatars img {
margin-right: -10px;
border-radius: 100px;
width: 24px;
height: 24px;
}

@media (max-width: 1024px) {
.verifyButton {
width: 100px;
Expand Down