Skip to content

Commit f504176

Browse files
committed
feat: Add percentage input for share
1 parent 1e19049 commit f504176

File tree

1 file changed

+43
-15
lines changed

1 file changed

+43
-15
lines changed

src/routes/+page.svelte

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
name: string;
2828
description?: string;
2929
share?: number;
30+
percentage?: number;
3031
reason?: string;
3132
reasons?: string[];
3233
}[];
@@ -44,8 +45,6 @@
4445
confirmed: boolean;
4546
} | null = null;
4647
47-
let stakeDistributed = false;
48-
4948
$: totalAllocatedShares =
5049
currentSession?.participants.reduce((sum, p) => sum + (p.share || 0), 0) ||
5150
0;
@@ -413,18 +412,37 @@
413412
</ul>
414413
{/if}
415414
{:else if allDescriptionsSubmitted && currentParticipant}
416-
<input
417-
bind:value={participant.share}
418-
on:input={() => {
419-
stakeDistributed =
420-
totalAllocatedShares == currentSession.stake;
421-
}}
422-
type="number"
423-
step="0.01"
424-
min="0"
425-
placeholder="Share"
426-
class="input"
427-
/>
415+
<div id="share-inputs">
416+
<input
417+
bind:value={participant.share}
418+
on:input={() => {
419+
participant.percentage =
420+
((participant.share || 0) / currentSession.stake) * 100;
421+
}}
422+
type="number"
423+
step="0.01"
424+
min="0"
425+
placeholder="Share"
426+
class="share-input"
427+
/>
428+
429+
<input
430+
bind:value={participant.percentage}
431+
on:input={(e) => {
432+
const raw = parseFloat(
433+
(e.target as HTMLInputElement).value
434+
);
435+
const percentage = isNaN(raw) ? 0 : raw;
436+
participant.share =
437+
(currentSession.stake * percentage) / 100;
438+
}}
439+
type="number"
440+
step="0.01"
441+
min="0"
442+
placeholder="Percentage"
443+
class="share-input"
444+
/>
445+
</div>
428446
<textarea bind:value={participant.reason} placeholder="Reason"
429447
></textarea>
430448
{/if}
@@ -452,7 +470,7 @@
452470
updateCurrentParticipant()}>Confirm shares</button
453471
>
454472
{/if}
455-
{:else if currentParticipant && stakeDistributed}
473+
{:else if currentParticipant && totalAllocatedShares == currentSession.stake}
456474
<button on:click={submitVote}>Submit Vote</button>
457475
{/if}
458476
{:else if sessionKeys}
@@ -581,6 +599,16 @@
581599
}
582600
}
583601
602+
#share-inputs {
603+
display: flex;
604+
gap: 0.5rem;
605+
flex-wrap: wrap;
606+
607+
.share-input {
608+
flex: 1;
609+
}
610+
}
611+
584612
button {
585613
width: min-content;
586614
white-space: nowrap;

0 commit comments

Comments
 (0)