Skip to content

Commit

Permalink
Revert "Winners tag"
Browse files Browse the repository at this point in the history
This reverts commit 40da76e.
  • Loading branch information
carletex committed Sep 6, 2024
1 parent 40da76e commit 5a28efd
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { Address } from "~~/components/scaffold-eth";
import { SubmissionWithWinnerTag } from "~~/services/database/repositories/submissions";
import { Submission } from "~~/services/database/repositories/submissions";

export const SubmissionCard = ({ submission }: { submission: SubmissionWithWinnerTag }) => {
export const SubmissionCard = ({ submission }: { submission: Submission }) => {
return (
<div key={submission.id} className="card bg-base-200 text-secondary-content border border-gray-300 rounded-none">
<div className="card-body p-4 pt-6">
{submission.winnerTag && (
<div className={`badge p-4 ${submission.winnerTag === "Winner" ? "badge-success" : "badge-warning"}`}>
{submission.winnerTag}
</div>
)}
<h2 className="card-title mb-3 xl:text-2xl">{submission.title}</h2>
<div className="flex flex-wrap justify-between items-center gap-4">
<div className="mt-1 flex shrink-0 gap-3">
Expand Down
21 changes: 3 additions & 18 deletions packages/nextjs/app/submissions/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { SubmissionCard } from "./_components/SubmissionCard";
import type { NextPage } from "next";
import scaffoldConfig from "~~/scaffold.config";
import { SubmissionWithWinnerTag, getAllSubmissions } from "~~/services/database/repositories/submissions";
import { getAllSubmissions } from "~~/services/database/repositories/submissions";
import { getMetadata } from "~~/utils/scaffold-eth/getMetadata";

export const metadata = getMetadata({
Expand All @@ -11,30 +10,16 @@ export const metadata = getMetadata({

const Submissions: NextPage = async () => {
const submissions = await getAllSubmissions();
const { winnersThreshold, runnersUpThreshold } = scaffoldConfig;

const submissionsWithAvgScore: SubmissionWithWinnerTag[] = submissions
.map(submission => {
const avgScore =
submission.votes.length > 0
? submission.votes.map(vote => vote.score).reduce((a, b) => a + b, 0) / submission.votes.length
: 0;

const winnerTag = avgScore >= winnersThreshold ? "Winner" : avgScore >= runnersUpThreshold ? "Runner Up" : null;

return { ...submission, avgScore, winnerTag };
})
.sort((a, b) => b.avgScore - a.avgScore);

return (
<div className="max-w-7xl container mx-auto px-6">
<div className="grid gap-6 md:grid-cols-2 xl:grid-cols-3 mt-6">
<div className="grid gap-6 md:grid-cols-2 xl:grid-cols-3">
{submissions.length === 0 && (
<div role="alert" className="alert col-span-2">
<span>No submissions yet.</span>
</div>
)}
{submissionsWithAvgScore.map((submission: SubmissionWithWinnerTag) => {
{submissions.map(submission => {
return <SubmissionCard key={submission.id} submission={submission} />;
})}
</div>
Expand Down
6 changes: 0 additions & 6 deletions packages/nextjs/scaffold.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ export type ScaffoldConfig = {
walletConnectProjectId: string;
onlyLocalBurnerWallet: boolean;
votingEnabled: boolean;
winnersThreshold: number;
runnersUpThreshold: number;
};

const scaffoldConfig = {
Expand Down Expand Up @@ -36,10 +34,6 @@ const scaffoldConfig = {

// Enable voting on submissions
votingEnabled: false,

// Score threshold for winners and runners up
winnersThreshold: 7,
runnersUpThreshold: 6,
} as const satisfies ScaffoldConfig;

export default scaffoldConfig;
3 changes: 0 additions & 3 deletions packages/nextjs/services/database/repositories/submissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ export type Submission = InferSelectModel<typeof submissions> & { comments: Comm
export type SubmissionWithAvg = Submission & {
avgScore: number;
};
export type SubmissionWithWinnerTag = Submission & {
winnerTag: string | null;
};

export async function getAllSubmissions() {
return await db.query.submissions.findMany({
Expand Down

0 comments on commit 5a28efd

Please sign in to comment.