Skip to content
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"@prisma/client": "^5.11.0",
"@radix-ui/react-avatar": "^1.1.1",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-menubar": "^1.0.4",
"@radix-ui/react-slot": "^1.0.2",
Expand Down
24 changes: 21 additions & 3 deletions src/app/elections/[electionId]/results/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
import { getCandidates } from "@packages/DAO/candidates.dao";
import ResultCard from "@packages/components/ResultCard";
const Home = () => {
return (
<div className="flex items-center justify-center h-[80vh] content-center">
<div>
<h1> Resultados da Eleição </h1>
<div>
<div className="flex items-center justify-center h-[80vh] content-center">
<div>
<h1 className="text-center text-xl p-16">Resultado da Eleição</h1>
{getCandidates().map(
({ image, candidate, vice, party, percentage, votes }) => (
<div key={candidate} className="p-4">
<ResultCard
image={image}
candidate={candidate}
vice={vice}
party={party}
percentagem={percentage}
votos={votes}
/>
</div>
),
)}
</div>
</div>
</div>
);
Expand Down
55 changes: 55 additions & 0 deletions src/packages/DAO/candidates.dao.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
type Candidate = {
image: string;
candidate: string;
vice: string;
party: string;
percentage: string;
votes: string;
};

const candidates: Candidate[] = [
{
image: "https://picsum.photos/id/237/200/300",
candidate: "Jiji Ping Png",
vice: "Xinguilingui",
party: "PCC",
percentage: "35.2%",
votes: "3,200,000",
},
{
image: "https://picsum.photos/id/444/200/300",
candidate: "Vladimir Putin",
vice: "Zelensky",
party: "ABC",
percentage: "28.1%",
votes: "2,550,000",
},
{
image: "https://picsum.photos/id/398/200/300",
candidate: "Lulão da massa",
vice: "Xuxu",
party: "DEF",
percentage: "18.4%",
votes: "1,670,000",
},
{
image: "https://picsum.photos/id/577/200/300",
candidate: "Biden",
vice: "Gagá",
party: "GHI",
percentage: "12.3%",
votes: "1,120,000",
},
{
image: "https://picsum.photos/id/610/200/300",
candidate: "Trump",
vice: "Bolsonaro",
party: "JKL",
percentage: "6.0%",
votes: "540,000",
},
];

export function getCandidates() {
return candidates;
}
45 changes: 45 additions & 0 deletions src/packages/components/ResultCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Avatar, AvatarImage } from "@packages/shadcn-ui/ui/avatar";
import { Card } from "@packages/shadcn-ui/ui/card";

interface ElectionResult {
image: string;
candidate: string;
vice: string;
party: string;
percentagem: string;
votos: string;
}
function ResultCard({
candidate,
vice,
party,
percentagem,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable in portuguese

votos,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

image,
}: ElectionResult) {
return (
<Card className="flex flex-row w-[60vw] p-4 shadow-md shadow-gray-200">
<div className="flex w-[40vw] gap-4">
<Avatar className="w-16 h-16">
<AvatarImage src={image} />
</Avatar>
<div>
<p className="font-bold">Presidente: {candidate}</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok to have portuguese on the text displayed to the user (we can enhance that with internationalization) but code and variables, always in colonizador language

<p className="text-sm">Vice: {vice}</p>
<p className="text-xs">{party}</p>
</div>
</div>
<div className="flex flex-col items-end justify-center w-1/2 gap-1">
<p className="text-sm">
Percentagem dos votos:{" "}
<span className="font-bold">{percentagem}</span>
</p>
<p className="text-sm">
Total de votos: <span className="font-bold">{votos}</span>
</p>
</div>
</Card>
);
}

export default ResultCard;
50 changes: 50 additions & 0 deletions src/packages/shadcn-ui/ui/avatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"use client";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this?


import * as AvatarPrimitive from "@radix-ui/react-avatar";
import * as React from "react";

import { cn } from "@packages/utils/shadcn-utils";

const Avatar = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>
>(({ className, ...props }, ref) => (
<AvatarPrimitive.Root
ref={ref}
className={cn(
"relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",
className,
)}
{...props}
/>
));
Avatar.displayName = AvatarPrimitive.Root.displayName;

const AvatarImage = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Image>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
>(({ className, ...props }, ref) => (
<AvatarPrimitive.Image
ref={ref}
className={cn("aspect-square h-full w-full", className)}
{...props}
/>
));
AvatarImage.displayName = AvatarPrimitive.Image.displayName;

const AvatarFallback = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Fallback>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
>(({ className, ...props }, ref) => (
<AvatarPrimitive.Fallback
ref={ref}
className={cn(
"flex h-full w-full items-center justify-center rounded-full bg-muted",
className,
)}
{...props}
/>
));
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName;
Comment on lines +35 to +48

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally found this code kind of ugly, code :(

Maybe we can use something like: https://www.npmjs.com/package/tailwind-styled-components

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue for the shared components bellow

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what shadcn components looks like. Then maybe choose something else? or just create the components from scratch?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, this is also code that we're not suposed to maintain, as zenha mentioned, this is shadcn's component, I don't see value on re-writing it.

Copy link

@marco-souza marco-souza Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is so sad I wanna die 😢

Warning

I don't like shadcn

Copy link

@marco-souza marco-souza Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me explain better my POV:

How can we see a displayName and think this is ok?

We intended to share some styles, but instead we created forwardRef components that feature complex and poorly readable types, utilizing spread operators - all of that do add some custom CSS 🤯

In my opinion, this code is challenging to maintain because it requires a deep understanding of the need for forwardRef to customize shadcn components - not easy for a fresh junior or a 5y person to maintain

Copy link

@marco-souza marco-souza Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you guys are saying that this is the shadcn way, I won't block this PR, BUT still ugly as hell

Let's at least create a wrapper to hide this ugliness

Copy link

@marco-souza marco-souza Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested style wrapper WithStyles:

Suggested change
const AvatarFallback = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Fallback>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
>(({ className, ...props }, ref) => (
<AvatarPrimitive.Fallback
ref={ref}
className={cn(
"flex h-full w-full items-center justify-center rounded-full bg-muted",
className,
)}
{...props}
/>
));
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName;
function WithStyles(ShadcnElement, styles) {
const CustomComponent = React.forwardRef<
React.ElementRef<typeof ShadcnElement>,
React.ComponentPropsWithoutRef<typeof ShadcnElement>
>(({ className, ...props }, ref) => (
<ShadcnElement
ref={ref}
className={cn(styles, className)}
{...props}
/>
));
CustomComponent.displayName = ShadcnElement.displayName;
return CustomComponent;
}

Then you can do something like

const AvatarFallback = WithStyles(
  AvatarPrimitive.Fallback,
  "flex h-full w-full items-center justify-center rounded-full bg-muted",
)

const Avatar = WithStyles(
  AvatarPrimitive.Root,
  "flex h-full w-full items-center justify-center rounded-full bg-muted",
)

const AvatarImage = WithStyles(
  AvatarPrimitive.Image,
  "flex h-full w-full items-center justify-center rounded-full bg-muted",
)


export { Avatar, AvatarImage, AvatarFallback };
86 changes: 86 additions & 0 deletions src/packages/shadcn-ui/ui/card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import * as React from "react";

import { cn } from "@packages/utils/shadcn-utils";

const Card = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
"rounded-lg border bg-card text-card-foreground shadow-sm",
className,
)}
{...props}
/>
));
Card.displayName = "Card";

const CardHeader = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex flex-col space-y-1.5 p-6", className)}
{...props}
/>
));
CardHeader.displayName = "CardHeader";

const CardTitle = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLHeadingElement>
>(({ className, ...props }, ref) => (
<h3
ref={ref}
className={cn(
"text-2xl font-semibold leading-none tracking-tight",
className,
)}
{...props}
/>
));
CardTitle.displayName = "CardTitle";

const CardDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<p
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
));
CardDescription.displayName = "CardDescription";

const CardContent = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
));
CardContent.displayName = "CardContent";

const CardFooter = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex items-center p-6 pt-0", className)}
{...props}
/>
));
CardFooter.displayName = "CardFooter";

export {
Card,
CardHeader,
CardFooter,
CardTitle,
CardDescription,
CardContent,
};
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,16 @@
"@babel/runtime" "^7.13.10"
"@radix-ui/react-primitive" "1.0.3"

"@radix-ui/react-avatar@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@radix-ui/react-avatar/-/react-avatar-1.1.1.tgz#5848d2ed5f34d18b36fc7e2d227c41fca8600ea1"
integrity sha512-eoOtThOmxeoizxpX6RiEsQZ2wj5r4+zoeqAwO0cBaFQGjJwIH3dIX0OCxNrCyrrdxG+vBweMETh3VziQG7c1kw==
dependencies:
"@radix-ui/react-context" "1.1.1"
"@radix-ui/react-primitive" "2.0.0"
"@radix-ui/react-use-callback-ref" "1.1.0"
"@radix-ui/react-use-layout-effect" "1.1.0"

"@radix-ui/react-collection@1.0.3":
version "1.0.3"
resolved "https://registry.npmjs.org/@radix-ui/react-collection/-/react-collection-1.0.3.tgz"
Expand Down Expand Up @@ -311,6 +321,11 @@
resolved "https://registry.npmjs.org/@radix-ui/react-context/-/react-context-1.1.0.tgz"
integrity sha512-OKrckBy+sMEgYM/sMmqmErVn0kZqrHPJze+Ql3DzYsDDp0hl0L62nx/2122/Bvps1qz645jlcu2tD9lrRSdf8A==

"@radix-ui/react-context@1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@radix-ui/react-context/-/react-context-1.1.1.tgz#82074aa83a472353bb22e86f11bcbd1c61c4c71a"
integrity sha512-UASk9zi+crv9WteK/NU4PLvOoL3OuE6BWVKNF6hPRBtYBDXQ2u5iu3O59zUlJiTVvkyuycnqrztsHVJwcK9K+Q==

"@radix-ui/react-dialog@^1.1.1":
version "1.1.1"
resolved "https://registry.npmjs.org/@radix-ui/react-dialog/-/react-dialog-1.1.1.tgz"
Expand Down
Loading