ui cleanup
This commit is contained in:
parent
73aea84e8e
commit
a19b7883d6
2 changed files with 43 additions and 60 deletions
|
|
@ -215,11 +215,20 @@
|
|||
function cloneSignupConfig(config: TournamentSignupConfig | null | undefined): SignupConfigForm {
|
||||
if (!config) return createDefaultSignup();
|
||||
|
||||
const normalizedSize = Math.max(
|
||||
1,
|
||||
Math.floor(
|
||||
config.team_size?.max ??
|
||||
config.team_size?.min ??
|
||||
1
|
||||
)
|
||||
);
|
||||
|
||||
const signup: SignupConfigForm = {
|
||||
mode: config.mode === 'team' ? 'team' : 'solo',
|
||||
team_size: {
|
||||
min: config.team_size?.min ?? 1,
|
||||
max: config.team_size?.max ?? 1
|
||||
min: normalizedSize,
|
||||
max: normalizedSize
|
||||
},
|
||||
entry_fields: (config.entry_fields ?? []).map(cloneSignupField),
|
||||
participant_fields: (config.participant_fields ?? []).map(cloneSignupField)
|
||||
|
|
@ -280,14 +289,15 @@
|
|||
function setSignupMode(form: TournamentForm, mode: 'solo' | 'team') {
|
||||
form.signup.mode = mode;
|
||||
if (mode === 'solo') {
|
||||
form.signup.team_size.min = 1;
|
||||
form.signup.team_size.max = 1;
|
||||
setTeamSize(form, '1');
|
||||
form.signup.participant_fields = [];
|
||||
} else {
|
||||
if (form.signup.team_size.min < 1) form.signup.team_size.min = 1;
|
||||
if (form.signup.team_size.max < form.signup.team_size.min) {
|
||||
form.signup.team_size.max = form.signup.team_size.min;
|
||||
}
|
||||
const currentSize = Math.max(
|
||||
1,
|
||||
Number.isFinite(form.signup.team_size.min) ? form.signup.team_size.min : 1,
|
||||
Number.isFinite(form.signup.team_size.max) ? form.signup.team_size.max : 1
|
||||
);
|
||||
setTeamSize(form, String(currentSize));
|
||||
if (form.signup.participant_fields.length === 0) {
|
||||
form.signup.participant_fields = [createSignupField('Spelare')];
|
||||
}
|
||||
|
|
@ -295,11 +305,11 @@
|
|||
ensureAttendancePlacement(form.signup);
|
||||
}
|
||||
|
||||
function setTeamSize(form: TournamentForm, key: 'min' | 'max', value: string) {
|
||||
function setTeamSize(form: TournamentForm, value: string) {
|
||||
const parsed = Number.parseInt(value, 10);
|
||||
const fallback = key === 'min' ? 1 : form.signup.team_size.min;
|
||||
const numeric = Number.isNaN(parsed) ? fallback : Math.max(1, parsed);
|
||||
form.signup.team_size[key] = numeric;
|
||||
const numeric = Number.isNaN(parsed) ? 1 : Math.max(1, parsed);
|
||||
form.signup.team_size.min = numeric;
|
||||
form.signup.team_size.max = numeric;
|
||||
}
|
||||
|
||||
function slugify(value: string) {
|
||||
|
|
@ -404,17 +414,16 @@
|
|||
};
|
||||
|
||||
const mode = signup.mode === 'team' ? 'team' : 'solo';
|
||||
let min = toNumber(signup.team_size.min);
|
||||
let max = toNumber(signup.team_size.max);
|
||||
if (max < min) max = min;
|
||||
if (mode === 'solo') {
|
||||
min = 1;
|
||||
max = 1;
|
||||
let teamSize = toNumber(signup.team_size.min);
|
||||
if (mode === 'team') {
|
||||
teamSize = Math.max(teamSize, toNumber(signup.team_size.max));
|
||||
} else {
|
||||
teamSize = 1;
|
||||
}
|
||||
|
||||
const draft: SignupConfigForm = {
|
||||
mode,
|
||||
team_size: { min, max },
|
||||
team_size: { min: teamSize, max: teamSize },
|
||||
entry_fields: signup.entry_fields.map((field) => ({ ...field })),
|
||||
participant_fields: signup.participant_fields.map((field) => ({ ...field }))
|
||||
};
|
||||
|
|
@ -426,7 +435,7 @@
|
|||
|
||||
return {
|
||||
mode,
|
||||
team_size: { min, max },
|
||||
team_size: { min: teamSize, max: teamSize },
|
||||
entry_fields,
|
||||
participant_fields
|
||||
};
|
||||
|
|
@ -1153,9 +1162,9 @@
|
|||
</select>
|
||||
</label>
|
||||
{#if createState.form.signup.mode === 'team'}
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div class="grid gap-3">
|
||||
<label class="flex flex-col gap-1 text-sm font-medium text-slate-700">
|
||||
<span>Min. spelare</span>
|
||||
<span>Spelare per lag</span>
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
|
|
@ -1163,22 +1172,6 @@
|
|||
oninput={(event) =>
|
||||
setTeamSize(
|
||||
createState.form,
|
||||
'min',
|
||||
(event.currentTarget as HTMLInputElement).value
|
||||
)}
|
||||
class="rounded-md border border-slate-300 px-3 py-2 text-sm text-slate-900 focus:border-indigo-500 focus:ring focus:ring-indigo-100 focus:outline-none"
|
||||
/>
|
||||
</label>
|
||||
<label class="flex flex-col gap-1 text-sm font-medium text-slate-700">
|
||||
<span>Max. spelare</span>
|
||||
<input
|
||||
type="number"
|
||||
min={createState.form.signup.team_size.min}
|
||||
value={createState.form.signup.team_size.max}
|
||||
oninput={(event) =>
|
||||
setTeamSize(
|
||||
createState.form,
|
||||
'max',
|
||||
(event.currentTarget as HTMLInputElement).value
|
||||
)}
|
||||
class="rounded-md border border-slate-300 px-3 py-2 text-sm text-slate-900 focus:border-indigo-500 focus:ring focus:ring-indigo-100 focus:outline-none"
|
||||
|
|
|
|||
|
|
@ -545,17 +545,7 @@
|
|||
|
||||
{#if signupConfig.mode === 'team'}
|
||||
<div class="space-y-3">
|
||||
<div class="flex items-center justify-between">
|
||||
<h3 class="text-sm font-semibold tracking-wide text-slate-400 uppercase">Spelare</h3>
|
||||
<button
|
||||
type="button"
|
||||
onclick={addParticipant}
|
||||
disabled={!canAddParticipant() || signup.submitting}
|
||||
class="rounded-full border border-indigo-300 px-3 py-1 text-xs font-semibold text-indigo-200 transition hover:border-indigo-400 hover:bg-indigo-500/10 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
Lägg till spelare
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{#if signup.participants.length > 0}
|
||||
<div class="space-y-4">
|
||||
|
|
|
|||
Loading…
Reference in a new issue