Skip to content
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

fix: no. of collaborators as integer #572

Merged
merged 2 commits into from
Dec 9, 2022
Merged
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
52 changes: 17 additions & 35 deletions src/components/Send.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,46 +70,37 @@ const CollaboratorsSelector = ({ numCollaborators, setNumCollaborators, minNumCo

const [usesCustomNumCollaborators, setUsesCustomNumCollaborators] = useState(false)

const defaultCollaboratorsSelection = useMemo(() => {
const start = Math.max(minNumCollaborators, 8)
return [start, start + 1, start + 2]
}, [minNumCollaborators])

const validateAndSetCustomNumCollaborators = (candidate) => {
if (isValidNumCollaborators(candidate, minNumCollaborators)) {
setNumCollaborators(candidate)
const parsed = parseInt(candidate, 10)
if (isValidNumCollaborators(parsed, minNumCollaborators)) {
setNumCollaborators(parsed)
} else {
setNumCollaborators(null)
}
}

var defaultCollaboratorsSelection = [8, 9, 10]
if (minNumCollaborators > 8) {
defaultCollaboratorsSelection = [minNumCollaborators, minNumCollaborators + 1, minNumCollaborators + 2]
}

return (
<rb.Form noValidate className={styles['collaborators-selector']} disabled={disabled}>
<rb.Form noValidate className={styles.collaboratorsSelector} disabled={disabled}>
<rb.Form.Group>
<rb.Form.Label className="mb-0">{t('send.label_num_collaborators', { numCollaborators })}</rb.Form.Label>
<div className="mb-2">
<rb.Form.Text className="text-secondary">{t('send.description_num_collaborators')}</rb.Form.Text>
</div>
<div className={`${styles['collaborators-selector-flex']} d-flex flex-row flex-wrap`}>
<div className="d-flex flex-row flex-wrap gap-2">
{defaultCollaboratorsSelection.map((number) => {
const isSelected = !usesCustomNumCollaborators && numCollaborators === number
return (
<rb.Button
key={number}
variant={settings.theme === 'light' ? 'white' : 'dark'}
className={classNames(
styles['collaborators-selector-button'],
'p-2',
'border',
'border-1',
'rounded',
'text-center',
{
'border-dark':
!usesCustomNumCollaborators && numCollaborators === number && settings.theme === 'light',
[styles['selected-dark']]:
!usesCustomNumCollaborators && numCollaborators === number && settings.theme !== 'light',
}
)}
className={classNames(styles.collaboratorsSelectorElement, 'border', 'border-1', {
[styles.selected]: isSelected,
})}
onClick={() => {
setUsesCustomNumCollaborators(false)
setNumCollaborators(number)
Expand All @@ -127,18 +118,9 @@ const CollaboratorsSelector = ({ numCollaborators, setNumCollaborators, minNumCo
isInvalid={!isValidNumCollaborators(numCollaborators, minNumCollaborators)}
placeholder={t('send.input_num_collaborators_placeholder')}
defaultValue=""
className={classNames(
styles['collaborators-selector-input'],
'p-2',
'border',
'border-1',
'rounded',
'text-center',
{
'border-dark': usesCustomNumCollaborators && settings.theme === 'light',
[styles['selected-dark']]: usesCustomNumCollaborators && settings.theme !== 'light',
}
)}
className={classNames(styles.collaboratorsSelectorElement, 'border', 'border-1', {
[styles.selected]: usesCustomNumCollaborators,
})}
onChange={(e) => {
setUsesCustomNumCollaborators(true)
validateAndSetCustomNumCollaborators(e.target.value)
Expand Down
24 changes: 11 additions & 13 deletions src/components/Send.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,26 @@ input[type='number'] {
width: 100%;
}

.collaborators-selector-button {
.collaboratorsSelectorElement {
min-width: 6rem;
flex: 1;
padding: 0.5rem;
text-align: center;
border-radius: var(--bs-border-radius);
}

.collaborators-selector-input {
min-width: 6rem;
flex: 1;
}

:root[data-theme='dark'] .collaborators-selector-input {
:root[data-theme='dark'] input.collaboratorsSelectorElement {
background-color: var(--bs-gray-800);
color: var(--bs-white);
}

:root[data-theme='dark'] .collaborators-selector .selected-dark {
background-color: var(--bs-gray-dark);
border-color: var(--bs-gray-dark) !important;
.collaboratorsSelectorElement.selected {
border-color: var(--bs-dark-rgb) !important;
}

.collaborators-selector-flex {
gap: 0.5rem;
:root[data-theme='dark'] .collaboratorsSelectorElement.selected {
background-color: var(--bs-gray-dark);
border-color: var(--bs-gray-dark) !important;
}

.input-loader {
Expand All @@ -146,7 +144,7 @@ input[type='number'] {
filter: blur(2px);
}

.service-running .collaborators-selector {
.service-running .collaboratorsSelector {
filter: blur(2px);
}

Expand Down