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

Add new "All submissions" tab to /admin view #86

Merged
merged 4 commits into from
Sep 17, 2024
Merged
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
10 changes: 5 additions & 5 deletions packages/nextjs/app/admin/_components/SubmissionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { SubmissionWithAvg } from "~~/services/database/repositories/submissions
import { postMutationFetcher } from "~~/utils/react-query";
import { notification } from "~~/utils/scaffold-eth";

export const SubmissionCard = ({ submission }: { submission: SubmissionWithAvg }) => {
export const SubmissionCard = ({ submission, tabName }: { submission: SubmissionWithAvg; tabName: string }) => {
const { votingEnabled } = scaffoldConfig;
const { address: connectedAddress } = useAccount();

Expand Down Expand Up @@ -91,16 +91,16 @@ export const SubmissionCard = ({ submission }: { submission: SubmissionWithAvg }
<div className="rating flex items-center">
<input
type="radio"
id={`rating_${submission.id}_0`}
name={`rating_${submission.id}`}
id={`rating_${tabName}_${submission.id}_0`}
name={`rating_${tabName}_${submission.id}`}
className="rating-hidden"
checked={score === 0}
onChange={() => vote(0)}
/>
{[...Array(10)].map((_e, i) => (
<input
type="radio"
name={`rating_${submission.id}`}
name={`rating_${tabName}_${submission.id}`}
className="mask mask-star-2 star bg-amber-500 peer peer-hover:bg-amber-400 disabled:bg-gray-200 disabled:pointer-events-none"
title={(i + 1).toString()}
checked={score === i + 1}
Expand All @@ -116,7 +116,7 @@ export const SubmissionCard = ({ submission }: { submission: SubmissionWithAvg }
className={clsx("ml-auto cursor-pointer underline text-sm hover:no-underline", {
"text-gray-400 cursor-not-allowed": isVotePending,
})}
htmlFor={`rating_${submission.id}_0`}
htmlFor={`rating_${tabName}_${submission.id}_0`}
>
Clear
</label>
Expand Down
29 changes: 25 additions & 4 deletions packages/nextjs/app/admin/_components/SubmissionTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ const skeletonClasses = "animate-pulse bg-gray-200 rounded-none w-full h-96";
export const SubmissionTabs = ({ submissions }: { submissions: Submission[] }) => {
const { address: connectedAddress } = useAccount();

const { voted, notVoted } = submissions.reduce(
const { voted, notVoted, all } = submissions.reduce(
(acc, submission) => {
// Connected address has voted
const currentVote = submission.votes.find(vote => vote.builder === connectedAddress);

const avgScore =
Expand All @@ -21,6 +20,8 @@ export const SubmissionTabs = ({ submissions }: { submissions: Submission[] }) =

const submissionWithAvg = { ...submission, avgScore };

acc.all.push(submissionWithAvg);

if (currentVote) {
acc.voted.push(submissionWithAvg);
} else {
Expand All @@ -32,15 +33,18 @@ export const SubmissionTabs = ({ submissions }: { submissions: Submission[] }) =
{
voted: [] as SubmissionWithAvg[],
notVoted: [] as SubmissionWithAvg[],
all: [] as SubmissionWithAvg[],
},
);

const votedLabel = connectedAddress ? `Voted (${voted.length})` : "Voted (-)";
const notVotedLabel = connectedAddress ? `Not Voted (${notVoted.length})` : "Not Voted (-)";
const allLabel = `All Submissions (${all.length})`;

return (
<div className="max-w-7xl container mx-auto px-6">
<div role="tablist" className="tabs tabs-bordered tabs-lg">
{/* Not Voted Tab */}
<input
type="radio"
name="submission_tabs"
Expand All @@ -59,7 +63,7 @@ export const SubmissionTabs = ({ submissions }: { submissions: Submission[] }) =
</>
) : (
notVoted.map(submission => {
return <SubmissionCard key={submission.id} submission={submission} />;
return <SubmissionCard key={submission.id} submission={submission} tabName="notVoted" />;
})
)}
{notVoted.length === 0 && (
Expand All @@ -70,6 +74,7 @@ export const SubmissionTabs = ({ submissions }: { submissions: Submission[] }) =
</div>
</div>

{/* Voted Tab */}
<input
type="radio"
name="submission_tabs"
Expand All @@ -87,10 +92,26 @@ export const SubmissionTabs = ({ submissions }: { submissions: Submission[] }) =
{voted
.sort((a, b) => b.avgScore - a.avgScore)
.map(submission => {
return <SubmissionCard key={submission.id} submission={submission} />;
return <SubmissionCard key={submission.id} submission={submission} tabName="voted" />;
})}
</div>
</div>

{/* All Submissions Tab */}
<input type="radio" name="submission_tabs" role="tab" className="tab whitespace-nowrap" aria-label={allLabel} />
<div role="tabpanel" className="tab-content py-6">
<div className="grid gap-6 md:grid-cols-2 xl:grid-cols-3">
{all.length === 0 ? (
<div role="alert" className="alert col-span-2">
<span>There are no submissions yet.</span>
</div>
) : (
all
.sort((a, b) => b.avgScore - a.avgScore)
.map(submission => <SubmissionCard key={submission.id} submission={submission} tabName="all" />)
)}
</div>
</div>
</div>
</div>
);
Expand Down
Loading