-
Notifications
You must be signed in to change notification settings - Fork 4
quick vote modal ux #2169
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
Merged
Merged
quick vote modal ux #2169
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
395d230
wip
ragnep e810d82
wip
ragnep 8e4f47f
wip
ragnep 74142c0
Merge branch 'main' into quick-vote-ux
ragnep 7997526
wip
ragnep d52a994
wip
ragnep de9f099
wip
ragnep fd0d28f
wip
ragnep c5bfb36
Merge branch 'main' into quick-vote-ux
ragnep 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 hidden or 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 hidden or 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 hidden or 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,28 @@ | ||
| "use client"; | ||
|
|
||
| import React from "react"; | ||
|
|
||
| type MemesWaveZapIconProps = React.SVGProps<SVGSVGElement>; | ||
|
|
||
| export default function MemesWaveZapIcon({ | ||
| className, | ||
| ...rest | ||
| }: MemesWaveZapIconProps) { | ||
| return ( | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| width="24" | ||
| height="24" | ||
| viewBox="0 0 24 24" | ||
| fill="currentColor" | ||
| stroke="currentColor" | ||
| strokeWidth="2" | ||
| strokeLinecap="round" | ||
| strokeLinejoin="round" | ||
| className={className} | ||
| {...rest} | ||
| > | ||
| <path d="M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z" /> | ||
| </svg> | ||
| ); | ||
| } |
169 changes: 169 additions & 0 deletions
169
components/brain/left-sidebar/waves/memes-quick-vote/MemesQuickVoteActionBar.tsx
This file contains hidden or 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,169 @@ | ||
| "use client"; | ||
|
|
||
| import MemesWaveZapIcon from "@/components/brain/left-sidebar/waves/MemesWaveZapIcon"; | ||
| import { formatNumberWithCommas } from "@/helpers/Helpers"; | ||
| import useHasTouchInput from "@/hooks/useHasTouchInput"; | ||
| import clsx from "clsx"; | ||
| import { useEffect, useRef } from "react"; | ||
| import MemesQuickVoteCustomAmountRow from "./MemesQuickVoteCustomAmountRow"; | ||
| import MemesQuickVoteQuickAmountsRow from "./MemesQuickVoteQuickAmountsRow"; | ||
|
|
||
| type VoteFeedbackSource = "custom-submit" | "quick-amount"; | ||
|
|
||
| interface MemesQuickVoteActionBarProps { | ||
| readonly customValue: string; | ||
| readonly feedbackAmount: number | null; | ||
| readonly feedbackSource: VoteFeedbackSource | null; | ||
| readonly isCustomOpen: boolean; | ||
| readonly isSubmitting: boolean; | ||
| readonly isVoteFeedbackActive: boolean; | ||
| readonly latestUsedAmount: number | null; | ||
| readonly quickAmounts: readonly number[]; | ||
| readonly uncastPower: number | null; | ||
| readonly votingLabel: string | null; | ||
| readonly onCustomChange: (value: string) => void; | ||
| readonly onCustomSubmit: () => void; | ||
| readonly onOpenCustom: () => void; | ||
| readonly onSkip: () => void; | ||
| readonly onVoteAmount: (amount: number) => void; | ||
| } | ||
|
|
||
| export default function MemesQuickVoteActionBar({ | ||
| customValue, | ||
| feedbackAmount, | ||
| feedbackSource, | ||
| isCustomOpen, | ||
| isSubmitting, | ||
| isVoteFeedbackActive, | ||
| latestUsedAmount, | ||
| quickAmounts, | ||
| uncastPower, | ||
| votingLabel, | ||
| onCustomChange, | ||
| onCustomSubmit, | ||
| onOpenCustom, | ||
| onSkip, | ||
| onVoteAmount, | ||
| }: MemesQuickVoteActionBarProps) { | ||
| const hasTouchInput = useHasTouchInput(); | ||
| const hasQuickAmounts = quickAmounts.length > 0; | ||
| const isCustomRowVisible = !hasQuickAmounts || isCustomOpen; | ||
| const customInputRef = useRef<HTMLInputElement | null>(null); | ||
| const previousCustomRowVisibleRef = useRef(isCustomRowVisible); | ||
| const customAmountLabel = | ||
| customValue.trim().length > 0 && Number.parseInt(customValue, 10) > 0 | ||
| ? formatNumberWithCommas(Number.parseInt(customValue, 10)) | ||
| : null; | ||
|
|
||
| useEffect(() => { | ||
| const wasCustomRowVisible = previousCustomRowVisibleRef.current; | ||
| previousCustomRowVisibleRef.current = isCustomRowVisible; | ||
|
|
||
| const justOpenedCustomRow = !wasCustomRowVisible && isCustomRowVisible; | ||
|
|
||
| if ( | ||
| hasTouchInput || | ||
| !hasQuickAmounts || | ||
| !justOpenedCustomRow || | ||
| isSubmitting | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| customInputRef.current?.focus(); | ||
| }, [hasQuickAmounts, hasTouchInput, isCustomRowVisible, isSubmitting]); | ||
|
|
||
| const handleToggleCustom = () => { | ||
| if (isSubmitting) { | ||
| return; | ||
| } | ||
|
|
||
| onOpenCustom(); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="tw-relative tw-bg-[linear-gradient(180deg,rgba(10,10,12,0.68),rgba(10,10,12,0.94))] tw-px-3 tw-pb-[calc(env(safe-area-inset-bottom,0px)+0.375rem)] tw-pt-1.5 tw-backdrop-blur-[28px] sm:tw-pb-[calc(env(safe-area-inset-bottom,0px)+0.5rem)] sm:tw-pt-2 md:tw-relative md:tw-z-20 md:tw-shrink-0 md:tw-p-0 md:tw-px-8 md:tw-pb-6 md:tw-pt-0"> | ||
| <div className="tw-relative tw-z-10 tw-flex tw-flex-col tw-gap-2 sm:tw-gap-3"> | ||
| <div className="tw-flex tw-flex-col tw-gap-2 tw-rounded-xl tw-border tw-border-solid tw-border-iron-900 tw-bg-iron-950 tw-p-3 tw-shadow-[inset_0_1px_0_rgba(255,255,255,0.04),0_12px_28px_rgba(0,0,0,0.22)] sm:tw-gap-3 sm:tw-p-4 md:tw-shadow-[0_20px_40px_rgba(0,0,0,0.18)]"> | ||
| <div className="tw-flex tw-flex-wrap tw-items-center tw-justify-between tw-gap-1.5 tw-px-0.5 sm:tw-gap-2 sm:tw-px-1 md:tw-flex-nowrap"> | ||
| <p className="tw-mb-0 tw-text-[11px] tw-font-bold tw-uppercase tw-tracking-widest tw-text-iron-500"> | ||
| Quick Vote | ||
| </p> | ||
|
|
||
| {typeof uncastPower === "number" && ( | ||
| <div className="tw-inline-flex tw-items-center tw-gap-1.5 tw-px-0.5 tw-py-0.5 tw-text-iron-300 sm:tw-gap-2 sm:tw-py-1"> | ||
| <MemesWaveZapIcon className="tw-size-3.5 tw-flex-shrink-0 tw-fill-primary-400/20 tw-text-primary-400" /> | ||
| <span className="tw-text-xs tw-font-bold tw-tracking-wide"> | ||
| <span className="tw-text-iron-300"> | ||
| {formatNumberWithCommas(uncastPower)}{" "} | ||
| {votingLabel ?? "votes"} remaining | ||
| </span> | ||
| </span> | ||
| </div> | ||
| )} | ||
| </div> | ||
|
|
||
| <div className="tw-relative tw-h-11 tw-overflow-hidden sm:tw-h-12 md:tw-h-12"> | ||
| {hasQuickAmounts && ( | ||
| <div | ||
| aria-hidden={isCustomOpen} | ||
| className={clsx( | ||
| "tw-absolute tw-inset-0 tw-h-full tw-w-full tw-transform-gpu tw-transition-all tw-duration-300 tw-ease-out motion-reduce:tw-transform-none motion-reduce:tw-transition-none", | ||
| isCustomOpen | ||
| ? "tw-pointer-events-none tw-z-0 tw-scale-[0.97] tw-opacity-0" | ||
| : "tw-z-10 tw-scale-100 tw-opacity-100" | ||
| )} | ||
| > | ||
| <MemesQuickVoteQuickAmountsRow | ||
| feedbackAmount={feedbackAmount} | ||
| feedbackSource={feedbackSource} | ||
| isSubmitting={isSubmitting} | ||
| isVoteFeedbackActive={isVoteFeedbackActive} | ||
| latestUsedAmount={latestUsedAmount} | ||
| onOpenCustom={handleToggleCustom} | ||
| onVoteAmount={onVoteAmount} | ||
| quickAmounts={quickAmounts} | ||
|
ragnep marked this conversation as resolved.
|
||
| /> | ||
| </div> | ||
| )} | ||
|
|
||
| <div | ||
| aria-hidden={hasQuickAmounts ? !isCustomOpen : undefined} | ||
| className={clsx( | ||
| "tw-absolute tw-inset-0 tw-h-full tw-w-full tw-transform-gpu tw-transition-all tw-duration-300 tw-ease-out motion-reduce:tw-transform-none motion-reduce:tw-transition-none", | ||
| !hasQuickAmounts || isCustomOpen ? "tw-z-10" : "tw-z-0", | ||
| !hasQuickAmounts || isCustomOpen | ||
| ? "tw-scale-100 tw-opacity-100" | ||
| : "tw-pointer-events-none tw-scale-[0.97] tw-opacity-0" | ||
| )} | ||
| > | ||
| <MemesQuickVoteCustomAmountRow | ||
| customAmountLabel={customAmountLabel} | ||
| customInputRef={customInputRef} | ||
| customValue={customValue} | ||
| feedbackSource={feedbackSource} | ||
| hasQuickAmounts={hasQuickAmounts} | ||
| isCustomRowVisible={isCustomRowVisible} | ||
| isSubmitting={isSubmitting} | ||
| isVoteFeedbackActive={isVoteFeedbackActive} | ||
| onCustomChange={onCustomChange} | ||
| onCustomSubmit={onCustomSubmit} | ||
| onToggleCustom={handleToggleCustom} | ||
| votingLabel={votingLabel} | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <button | ||
| type="button" | ||
| onClick={onSkip} | ||
| disabled={isSubmitting} | ||
| className="tw-inline-flex tw-h-11 tw-items-center tw-justify-center tw-rounded-xl tw-border tw-border-solid tw-border-iron-900 tw-bg-iron-950 tw-px-5 tw-text-sm tw-font-bold tw-text-iron-200 tw-shadow-[0_10px_24px_rgba(0,0,0,0.18)] tw-transition-all tw-duration-200 disabled:tw-cursor-not-allowed disabled:tw-opacity-60 desktop-hover:hover:tw-border-iron-900 desktop-hover:hover:tw-bg-iron-900 sm:tw-h-12" | ||
| > | ||
| Skip | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
73 changes: 73 additions & 0 deletions
73
components/brain/left-sidebar/waves/memes-quick-vote/MemesQuickVoteAmountButton.tsx
This file contains hidden or 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,73 @@ | ||
| "use client"; | ||
|
|
||
| import { formatNumberWithCommas } from "@/helpers/Helpers"; | ||
| import { CheckIcon } from "@heroicons/react/24/outline"; | ||
| import clsx from "clsx"; | ||
|
|
||
| type VoteFeedbackSource = "custom-submit" | "quick-amount"; | ||
|
|
||
| interface MemesQuickVoteAmountButtonProps { | ||
| readonly amount: number; | ||
| readonly feedbackAmount: number | null; | ||
| readonly feedbackSource: VoteFeedbackSource | null; | ||
| readonly isLatestUsed: boolean; | ||
| readonly isSubmitting: boolean; | ||
| readonly isVoteFeedbackActive: boolean; | ||
| readonly onVoteAmount: (amount: number) => void; | ||
| } | ||
|
|
||
| export default function MemesQuickVoteAmountButton({ | ||
| amount, | ||
| feedbackAmount, | ||
| feedbackSource, | ||
| isLatestUsed, | ||
| isSubmitting, | ||
| isVoteFeedbackActive, | ||
| onVoteAmount, | ||
| }: MemesQuickVoteAmountButtonProps) { | ||
| const isQuickVoteFeedbackTarget = | ||
| isVoteFeedbackActive && | ||
| feedbackSource === "quick-amount" && | ||
| feedbackAmount === amount; | ||
| let buttonToneClassName = | ||
| "tw-border-white/5 tw-bg-white/[0.03] tw-text-[14px] tw-font-bold tw-text-zinc-300 tw-shadow-sm tw-transition-colors desktop-hover:hover:tw-bg-white/[0.06] desktop-hover:hover:tw-text-white"; | ||
|
|
||
| if (isQuickVoteFeedbackTarget) { | ||
| buttonToneClassName = | ||
| "tw-border-emerald-500/35 tw-bg-emerald-500/15 tw-text-emerald-100 tw-shadow-[0_0_20px_rgba(16,185,129,0.15)]"; | ||
| } else if (isLatestUsed) { | ||
| buttonToneClassName = | ||
| "tw-border-blue-500/30 tw-bg-blue-500/15 tw-text-primary-300 tw-shadow-sm tw-transition-all desktop-hover:hover:tw-bg-blue-500/25 desktop-hover:hover:tw-text-primary-200"; | ||
| } | ||
|
|
||
| return ( | ||
| <button | ||
| type="button" | ||
| onClick={() => { | ||
| onVoteAmount(amount); | ||
| }} | ||
| disabled={isSubmitting} | ||
| className={clsx( | ||
| "tw-relative tw-inline-flex tw-h-full tw-min-w-14 tw-flex-none tw-items-center tw-justify-center tw-rounded-xl tw-border tw-border-solid tw-text-center active:tw-scale-95 disabled:tw-cursor-not-allowed disabled:tw-opacity-60 sm:tw-min-w-[4.5rem] sm:tw-flex-1 sm:tw-basis-0 lg:tw-min-w-14 lg:tw-flex-none", | ||
| buttonToneClassName, | ||
| isVoteFeedbackActive && !isQuickVoteFeedbackTarget && "tw-opacity-40" | ||
| )} | ||
| > | ||
| {isQuickVoteFeedbackTarget ? ( | ||
| <span className="tw-inline-flex tw-items-center tw-gap-1.5 tw-font-bold tw-leading-none"> | ||
| <CheckIcon className="tw-size-4 tw-shrink-0" /> | ||
| <span>{formatNumberWithCommas(amount)}</span> | ||
| </span> | ||
| ) : ( | ||
| <span | ||
| className={clsx( | ||
| "tw-font-bold tw-leading-none", | ||
| isLatestUsed && "tw-text-primary-300" | ||
| )} | ||
| > | ||
| {formatNumberWithCommas(amount)} | ||
| </span> | ||
| )} | ||
| </button> | ||
| ); | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.