-
Notifications
You must be signed in to change notification settings - Fork 4
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: add collection vote table #525
Merged
ItsANameToo
merged 23 commits into
feat/collections-overview
from
feat/collections-vote-table
Dec 5, 2023
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
4658372
feat: add table
shahin-hq d1c2485
Optimize 1 SVG(s)
shahin-hq 41ac978
Optimize 1 SVG(s)
ItsANameToo b3f708b
feat: add table
shahin-hq c747166
Optimize 1 SVG(s)
shahin-hq 4f69487
Optimize 1 SVG(s)
ItsANameToo 78ac05b
style: resolve style guide violations
ItsANameToo f9a983b
feat: add table
shahin-hq 9dac46c
Merge branch 'feat/collections-overview' into feat/collections-vote-t…
shahin-hq cf5e372
feat: add table
shahin-hq 735cc8b
feat: add table
shahin-hq 19e9f46
style: resolve style guide violations
shahin-hq cb5511f
feat: add table
shahin-hq c412cf4
Merge remote-tracking branch 'origin/feat/collections-vote-table' int…
shahin-hq 8c8af38
style: resolve style guide violations
shahin-hq d2402eb
feat: add table
shahin-hq 28900f2
Merge remote-tracking branch 'origin/feat/collections-vote-table' int…
shahin-hq 09187b3
style: resolve style guide violations
shahin-hq d930bff
Merge branch 'feat/collections-overview' into feat/collections-vote-t…
shahin-hq 96f17f6
wip
shahin-hq 03e5b95
wip
shahin-hq 41c79ce
wip
shahin-hq 33e35fe
wip
ItsANameToo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,4 +165,5 @@ | |
'top' => 'Top', | ||
'all_chains' => 'All chains', | ||
'votes' => 'Votes', | ||
'vol' => 'Vol', | ||
]; |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
resources/js/Pages/Collections/Components/CollectionOfTheMonth/CollectionOfTheMonth.tsx
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
resources/js/Pages/Collections/Components/CollectionOfTheMonth/VoteCollection.tsx
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
resources/js/Pages/Collections/Components/CollectionOfTheMonth/index.tsx
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
resources/js/Pages/Collections/Components/CollectionVoting/VoteCollections.test.tsx
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,60 @@ | ||
import { within } from "@testing-library/react"; | ||
import { expect } from "vitest"; | ||
import { | ||
VoteCollection, | ||
type VoteCollectionProperties, | ||
VoteCollections, | ||
VoteCount, | ||
} from "@/Pages/Collections/Components/CollectionVoting/VoteCollections"; | ||
import { render, screen } from "@/Tests/testing-library"; | ||
|
||
const demoCollection: VoteCollectionProperties = { | ||
index: 1, | ||
name: "AlphaDogs", | ||
image: "https://i.seadn.io/gcs/files/4ef4a60496c335d66eba069423c0af90.png?w=500&auto=format", | ||
volume: "256.000000000000000000", | ||
volumeCurrency: "ETH", | ||
volumeDecimals: 18, | ||
votes: 15, | ||
}; | ||
|
||
const collections = Array.from({ length: 8 }).fill(demoCollection) as VoteCollectionProperties[]; | ||
|
||
describe("VoteCollections", () => { | ||
it("should render collections in two block, 4 collection in each", () => { | ||
render(<VoteCollections collections={collections} />); | ||
|
||
const leftBlock = screen.getByTestId("VoteCollections_Left"); | ||
const rightBlock = screen.getByTestId("VoteCollections_Right"); | ||
|
||
expect(within(leftBlock).getAllByText("AlphaDogs").length).toBe(4); | ||
expect(within(rightBlock).getAllByText("AlphaDogs").length).toBe(4); | ||
}); | ||
}); | ||
describe("VoteCollection", () => { | ||
it("should render the component", () => { | ||
render(<VoteCollection collection={demoCollection} />); | ||
|
||
expect(screen.getByText("AlphaDogs")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should render volume of the collection", () => { | ||
render(<VoteCollection collection={demoCollection} />); | ||
|
||
expect(screen.getByText(/Vol: 256 ETH/)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe("VoteCount", () => { | ||
it("should render without vote count", () => { | ||
render(<VoteCount />); | ||
|
||
expect(screen.getByTestId("icon-HiddenVote")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should render with vote count", () => { | ||
render(<VoteCount voteCount={15} />); | ||
|
||
expect(screen.getByText("15")).toBeInTheDocument(); | ||
}); | ||
}); |
172 changes: 172 additions & 0 deletions
172
resources/js/Pages/Collections/Components/CollectionVoting/VoteCollections.tsx
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,172 @@ | ||
import React from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { twMerge } from "tailwind-merge"; | ||
import { VoteCountdown } from "./VoteCountdown"; | ||
import { Heading } from "@/Components/Heading"; | ||
import { Icon } from "@/Components/Icon"; | ||
import { Img } from "@/Components/Image"; | ||
import { LinkButton } from "@/Components/Link"; | ||
import { Tooltip } from "@/Components/Tooltip"; | ||
import { FormatCrypto } from "@/Utils/Currency"; | ||
|
||
export interface VoteCollectionProperties { | ||
name: string; | ||
image: string; | ||
volume?: string; | ||
volumeCurrency?: string; | ||
volumeDecimals?: number; | ||
votes?: number; | ||
index: number; | ||
} | ||
|
||
export const VoteCollections = ({ collections }: { collections: VoteCollectionProperties[] }): JSX.Element => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<div className="flex w-full min-w-0 flex-col gap-4 rounded-xl border-theme-secondary-300 p-0 dark:border-theme-dark-700 lg:gap-6 lg:border lg:p-8"> | ||
<Heading level={2}>{t("pages.collections.vote.vote_for_top_collection")}</Heading> | ||
|
||
<div className="grid grid-cols-1 sm:grid-cols-2 sm:gap-x-2.5"> | ||
<div | ||
className="max-w-full flex-1 space-y-2" | ||
data-testid="VoteCollections_Left" | ||
> | ||
{collections.slice(0, 4).map((collection, index) => ( | ||
<VoteCollection | ||
key={index} | ||
collection={collection} | ||
/> | ||
))} | ||
</div> | ||
<div | ||
className="hidden flex-1 space-y-2 sm:block" | ||
data-testid="VoteCollections_Right" | ||
> | ||
{collections.slice(4, 8).map((collection, index) => ( | ||
<VoteCollection | ||
key={index} | ||
collection={collection} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
|
||
<div className="flex w-full flex-col items-center gap-4 sm:flex-row sm:justify-between"> | ||
<VoteCountdown /> | ||
|
||
<LinkButton | ||
onClick={(): void => { | ||
console.log("TODO: Implement or nominate collection"); | ||
}} | ||
variant="link" | ||
className="font-medium leading-6 dark:hover:decoration-theme-primary-400" | ||
fontSize="!text-base" | ||
textColor="!text-theme-primary-600 dark:!text-theme-primary-400" | ||
> | ||
{t("pages.collections.vote.or_nominate_collection")} | ||
</LinkButton> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export const VoteCollection = ({ collection }: { collection: VoteCollectionProperties }): JSX.Element => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<div | ||
tabIndex={0} | ||
className="cursor-pointer rounded-lg border border-theme-secondary-300 px-4 py-4 hover:outline hover:outline-theme-hint-100 focus:outline-none focus:ring focus:ring-theme-hint-100 dark:border-theme-dark-700 dark:border-theme-dark-700 dark:hover:outline-theme-dark-500 dark:hover:outline-theme-dark-500 dark:focus:ring-theme-dark-500 md:py-3" | ||
> | ||
<div className="flex items-center justify-between"> | ||
<div className="flex min-w-0 flex-1 items-center space-x-3"> | ||
<div className="flex"> | ||
<div className="relative flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-theme-secondary-100 dark:bg-theme-vote-background xs:h-12 xs:w-12"> | ||
<span className="font-medium text-theme-secondary-700 dark:text-theme-dark-200"> | ||
{collection.index} | ||
</span> | ||
</div> | ||
<div className="relative -ml-2 h-8 w-8 shrink-0 xs:h-12 xs:w-12"> | ||
<Img | ||
wrapperClassName="aspect-square" | ||
className="h-full w-full rounded-full rounded-full bg-white object-cover ring-4 ring-white dark:bg-theme-dark-700 dark:ring-theme-dark-900" | ||
isCircle | ||
src={collection.image} | ||
/> | ||
</div> | ||
</div> | ||
|
||
<div className="break-word-legacy min-w-0 space-y-0.5 "> | ||
<p | ||
data-testid="CollectionName__name" | ||
className="truncate text-base font-medium text-theme-secondary-900 dark:text-theme-dark-50 md-lg:text-base" | ||
> | ||
{collection.name} | ||
</p> | ||
<p className="hidden text-sm font-medium leading-5.5 text-theme-secondary-700 dark:text-theme-dark-200 md-lg:block"> | ||
{t("common.vol")}:{" "} | ||
<FormatCrypto | ||
value={collection.volume ?? "0"} | ||
token={{ | ||
symbol: collection.volumeCurrency ?? "ETH", | ||
name: collection.volumeCurrency ?? "ETH", | ||
decimals: collection.volumeDecimals ?? 18, | ||
}} | ||
/> | ||
</p> | ||
<div className="mt-0.5 md-lg:hidden"> | ||
<VoteCount | ||
iconClass="h-6 w-8" | ||
textClass="text-sm md:text-sm" | ||
voteCount={collection.votes} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div className="ml-2 hidden md-lg:block"> | ||
<VoteCount voteCount={collection.votes} /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export const VoteCount = ({ | ||
iconClass, | ||
textClass, | ||
voteCount, | ||
}: { | ||
iconClass?: string; | ||
textClass?: string; | ||
voteCount?: number; | ||
}): JSX.Element => { | ||
const { t } = useTranslation(); | ||
return ( | ||
<div className="flex items-center space-x-2"> | ||
<p | ||
className={twMerge( | ||
"text-sm font-medium leading-5.5 text-theme-secondary-700 dark:text-theme-dark-200 md:text-base md:leading-6", | ||
textClass, | ||
)} | ||
> | ||
Votes | ||
</p> | ||
{voteCount !== undefined ? ( | ||
<p className={twMerge("font-medium text-theme-secondary-900 dark:text-theme-dark-50", textClass)}> | ||
{voteCount} | ||
</p> | ||
) : ( | ||
<Tooltip content={t("pages.collections.vote.vote_to_reveal")}> | ||
<div> | ||
<Icon | ||
className={twMerge("h-7 w-9", iconClass)} | ||
name="HiddenVote" | ||
size="2xl" | ||
/> | ||
</div> | ||
</Tooltip> | ||
)} | ||
</div> | ||
); | ||
}; |
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
resources/js/Pages/Collections/Components/CollectionVoting/index.tsx
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,2 @@ | ||
export * from "./VoteCollections"; | ||
export * from "./VoteCountdown"; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dummy interface, should be linked with backend data