generated from scaffold-eth/scaffold-eth-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/labintsev/my-erc-tokens
- Loading branch information
Showing
7 changed files
with
133 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { cookies } from "next/headers"; | ||
import { fetchQuestionById, fetchVotingResult } from "~~/app/lib/actions"; | ||
import { connectedAddressKey } from "~~/app/lib/definitions"; | ||
import { VotingForm } from "~~/app/voting/_components/VotingForm"; | ||
import VotingResults from "~~/app/voting/_components/VotingResults"; | ||
|
||
type Params = { | ||
params: { id: string }; | ||
}; | ||
|
||
export default async function Page({ params }: Params) { | ||
console.log(params); | ||
|
||
const activeQuestion = await fetchQuestionById(params.id); | ||
if (activeQuestion === undefined) { | ||
return ( | ||
<> | ||
<h1>Error to fetch question</h1> | ||
</> | ||
); | ||
} | ||
const votingResult = await fetchVotingResult(activeQuestion.id); | ||
if (votingResult === undefined) { | ||
return ( | ||
<> | ||
<h1>Error to fetch results</h1> | ||
</> | ||
); | ||
} | ||
const cookieStore = cookies(); | ||
const connectedAddress = cookieStore.get(connectedAddressKey)?.value; | ||
if (connectedAddress) { | ||
return ( | ||
<div className="container mx-auto grid grid-cols-2 gap-4"> | ||
<div className="card bg-base-100 border-base-300 border text-primary-content shadow-xl w-128 mx-8 my-4"> | ||
<div className="card-body"> | ||
<div className="card-title">{activeQuestion.question}</div> | ||
</div> | ||
<VotingForm question={activeQuestion} /> | ||
</div> | ||
|
||
<div className="card bg-base-100 border-base-300 border text-primary-content shadow-xl w-96 mx-8 my-4"> | ||
<div className="card-body"> | ||
<h2 className="card-title">Voting results</h2> | ||
<VotingResults voting_result={votingResult} /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} else | ||
return ( | ||
<> | ||
<h1>Connect to wallet for voting!</h1> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,24 @@ | ||
import { cookies } from "next/headers"; | ||
import { fetchQuestions, fetchVotingResult } from "../lib/actions"; | ||
import { connectedAddressKey } from "../lib/definitions"; | ||
import { VotingForm } from "./_components/VotingForm"; | ||
import VotingResults from "./_components/VotingResults"; | ||
import Link from "next/link"; | ||
import { fetchQuestions } from "~~/app/lib/actions"; | ||
|
||
export default async function Page() { | ||
const questions = await fetchQuestions(); | ||
const activeQuestion = questions[1]; | ||
const votingResult = await fetchVotingResult(activeQuestion.id); | ||
|
||
const cookieStore = cookies(); | ||
const connectedAddress = cookieStore.get(connectedAddressKey)?.value; | ||
if (connectedAddress) { | ||
return ( | ||
<div className="container"> | ||
<div className="card bg-base-100 border-base-300 border text-primary-content shadow-xl w-96 mx-8 my-4"> | ||
<div className="card-body"> | ||
<h2 className="card-title">{activeQuestion.question}</h2> | ||
<VotingForm question={activeQuestion} /> | ||
</div> | ||
</div> | ||
|
||
<div className="card bg-base-100 border-base-300 border text-primary-content shadow-xl w-96 mx-8"> | ||
<div className="card-body"> | ||
<h2 className="card-title">Voting results</h2> | ||
<VotingResults voting_result={votingResult} /> | ||
</div> | ||
return ( | ||
<div> | ||
<div className="card bg-base-100 border-base-300 border text-primary-content shadow-xl mx-8 my-4"> | ||
<div className="card-body"> | ||
<div className="card-title">Questions</div> | ||
<ul> | ||
{questions.map((question, index) => ( | ||
<li key={index}> | ||
<div className="m-8"> | ||
<Link href={`/voting/${question.id}`}>{question.question}</Link> | ||
</div> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
</div> | ||
); | ||
} else | ||
return ( | ||
<> | ||
<h1>Connect to wallet for voting!</h1> | ||
</> | ||
); | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters