-
Notifications
You must be signed in to change notification settings - Fork 22
fix: crisp voting ux fixes [skip-line-limit] #1053
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a45bc5a
chore: CRISP voting UX fixes
hmzakhalid 89db76b
chore: run prettier
hmzakhalid 9b5398a
chore: add header
hmzakhalid c3f87ef
chore: fix review items
hmzakhalid 62de6fc
chore: fix review items
hmzakhalid 5e1b3db
chore: fix review items
hmzakhalid e3a5137
chore: fix review items
hmzakhalid 1ce8f20
chore: use latest sdk and add previous ciphertext
ctrlc03 0c9c93b
chore: remove user from db only if first time voting
ctrlc03 b931d01
fix: update UI vote
hmzakhalid f61ce3c
Merge branch 'main' into chore/crisp-fixes
hmzakhalid 40080ca
fix: update ciphertext after vote update
hmzakhalid 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
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
105 changes: 105 additions & 0 deletions
105
examples/CRISP/client/src/components/VotingStepIndicator.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,105 @@ | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
| // | ||
| // This file is provided WITHOUT ANY WARRANTY; | ||
| // without even the implied warranty of MERCHANTABILITY | ||
| // or FITNESS FOR A PARTICULAR PURPOSE. | ||
|
|
||
| import React from 'react' | ||
| import { VotingStep } from '@/hooks/voting/useVoteCasting' | ||
| import { CheckIcon, CircleNotchIcon, WarningIcon, PencilSimpleIcon, LockIcon, BroadcastIcon, ShieldCheckIcon } from '@phosphor-icons/react' | ||
|
|
||
| type VotingStepIndicatorProps = { | ||
| step: VotingStep | ||
| message: string | ||
| lastActiveStep?: VotingStep | null | ||
| } | ||
|
|
||
| const steps: { key: VotingStep; label: string; icon: React.ElementType }[] = [ | ||
| { key: 'signing', label: 'Sign', icon: PencilSimpleIcon }, | ||
| { key: 'encrypting', label: 'Encrypt', icon: LockIcon }, | ||
| { key: 'generating_proof', label: 'Proof', icon: ShieldCheckIcon }, | ||
| { key: 'broadcasting', label: 'Broadcast', icon: BroadcastIcon }, | ||
| ] | ||
|
|
||
| const VotingStepIndicator: React.FC<VotingStepIndicatorProps> = ({ step, message, lastActiveStep }) => { | ||
| const getStepStatus = (stepKey: VotingStep) => { | ||
| const stepOrder = steps.map((s) => s.key) | ||
| const currentIndex = step === 'error' ? stepOrder.indexOf(lastActiveStep ?? 'signing') : stepOrder.indexOf(step) | ||
| const stepIndex = stepOrder.indexOf(stepKey) | ||
|
|
||
| if (step === 'complete') return 'complete' | ||
| if (step === 'error') return stepIndex <= currentIndex ? 'error' : 'pending' | ||
| if (stepIndex < currentIndex) return 'complete' | ||
| if (stepIndex === currentIndex) return 'active' | ||
| return 'pending' | ||
| } | ||
|
hmzakhalid marked this conversation as resolved.
|
||
|
|
||
| const getStepStyles = (status: string) => { | ||
| switch (status) { | ||
| case 'complete': | ||
| return { | ||
| circle: 'bg-lime-500 border-lime-500 text-white', | ||
| text: 'text-lime-600', | ||
| line: 'bg-lime-500', | ||
| } | ||
| case 'active': | ||
| return { | ||
| circle: 'bg-white border-lime-500 text-lime-500 animate-pulse', | ||
| text: 'text-lime-600 font-bold', | ||
| line: 'bg-slate-200', | ||
| } | ||
| case 'error': | ||
| return { | ||
| circle: 'bg-red-500 border-red-500 text-white', | ||
| text: 'text-red-600', | ||
| line: 'bg-red-300', | ||
| } | ||
| default: | ||
| return { | ||
| circle: 'bg-white border-slate-300 text-slate-400', | ||
| text: 'text-slate-400', | ||
| line: 'bg-slate-200', | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <div className='flex flex-col items-center justify-center space-y-4 py-4 w-full max-w-md'> | ||
| {/* Step indicators */} | ||
| <div className='flex items-center justify-between w-full px-4'> | ||
| {steps.map((s, index) => { | ||
| const status = getStepStatus(s.key) | ||
| const styles = getStepStyles(status) | ||
| const Icon = s.icon | ||
|
|
||
| return ( | ||
| <React.Fragment key={s.key}> | ||
| <div className='flex flex-col items-center'> | ||
| <div className={`w-10 h-10 rounded-full border-2 flex items-center justify-center ${styles.circle}`}> | ||
| {status === 'complete' ? ( | ||
| <CheckIcon size={20} weight='bold' /> | ||
| ) : status === 'active' ? ( | ||
| <CircleNotchIcon size={20} weight='bold' className='animate-spin' /> | ||
| ) : status === 'error' ? ( | ||
| <WarningIcon size={20} weight='bold' /> | ||
| ) : ( | ||
| <Icon size={20} weight='bold' /> | ||
| )} | ||
| </div> | ||
| <span className={`text-xs mt-1 ${styles.text}`}>{s.label}</span> | ||
| </div> | ||
| {index < steps.length - 1 && <div className={`flex-1 h-0.5 mx-2 ${styles.line}`} />} | ||
| </React.Fragment> | ||
| ) | ||
| })} | ||
| </div> | ||
|
|
||
| {/* Current step message */} | ||
| <div className='text-center'> | ||
| <p className='text-base font-bold uppercase text-slate-600/70'>{message}</p> | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default VotingStepIndicator | ||
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.