Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 1x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10x 10x 10x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 2x 2x 2x 2x 2x 2x 2x 3x 1x 1x 1x 1x 3x 1x 5x 5x 5x 5x 5x 5x 1x | <template>
<section class="preferences-card" data-testid="preferences-card">
<header class="preferences-header">
<h3>Preferences</h3>
<p class="preferences-subhead">
Saved to your account, so they follow you to every device.
</p>
</header>
<div class="preference-row">
<label for="default-age-group" class="preference-label">
Default age group
</label>
<p class="preference-help">
Table and Matches open on this age group. Picking a different one on
those pages still sticks there.
</p>
<select
id="default-age-group"
v-model="selected"
class="preference-select"
data-testid="default-age-group-select"
:disabled="saving || loadFailed"
@change="save"
>
<option value="">{{ automaticLabel }}</option>
<option v-for="ag in ageGroups" :key="ag.id" :value="String(ag.id)">
{{ ag.name }}
</option>
</select>
<p
v-if="status"
class="preference-status"
:class="{ 'is-error': statusIsError }"
role="status"
data-testid="preference-status"
>
{{ status }}
</p>
</div>
</section>
</template>
<script setup>
import { computed, onMounted, ref, watch } from 'vue';
import { useAuthStore } from '@/stores/auth';
import { getApiBaseUrl } from '@/config/api';
import { useFilterMemory } from '@/composables/useFilterMemory';
const authStore = useAuthStore();
const ageGroups = ref([]);
const loadFailed = ref(false);
const saving = ref(false);
const status = ref('');
const statusIsError = ref(false);
// '' = no preference. Kept as a string so the empty option compares cleanly.
const toSelected = id => (id === null || id === undefined ? '' : String(id));
const selected = ref(toSelected(authStore.preferredAgeGroupId?.value));
watch(
() => authStore.preferredAgeGroupId?.value,
id => {
if (!saving.value) selected.value = toSelected(id);
}
);
// Say what "automatic" resolves to, so the empty option is not a mystery.
const automaticLabel = computed(() => {
const teamAgeGroup = authStore.userAgeGroupId?.value;
const name = ageGroups.value.find(ag => ag.id === teamAgeGroup)?.name;
return name ? `Automatic (my team: ${name})` : 'Automatic (U14)';
});
// Same per-viewer key the Table and Matches tabs use.
const userKey = () =>
authStore.state?.profile?.id ?? authStore.state?.user?.id ?? null;
const save = async () => {
saving.value = true;
status.value = '';
const id = selected.value === '' ? null : Number(selected.value);
const result = await authStore.updatePreferences({
default_age_group_id: id,
});
saving.value = false;
if (result.success) {
// Last pick wins, so a remembered pick would hide the new preference on
// this device. Drop it here so the change shows on the next visit.
useFilterMemory('table', userKey).clear();
useFilterMemory('matches', userKey).clear();
useFilterMemory('tournament', userKey).clear();
statusIsError.value = false;
status.value = 'Saved';
} else {
selected.value = toSelected(authStore.preferredAgeGroupId?.value);
statusIsError.value = true;
status.value = result.error || 'Could not save. Please try again.';
}
};
onMounted(async () => {
try {
const data = await authStore.apiRequest(
`${getApiBaseUrl()}/api/age-groups`
);
ageGroups.value = [...data].sort((a, b) => a.name.localeCompare(b.name));
} catch (err) {
console.error('Error fetching age groups:', err);
loadFailed.value = true;
statusIsError.value = true;
status.value = 'Age groups could not be loaded.';
}
});
</script>
<style scoped>
.preferences-card {
background: rgb(var(--color-card));
border: 1px solid rgb(var(--color-line));
border-radius: 12px;
padding: 20px;
margin-top: 24px;
}
.preferences-header h3 {
margin: 0 0 4px;
font-size: 18px;
font-weight: 700;
color: rgb(var(--color-fg));
}
.preferences-subhead {
margin: 0 0 16px;
font-size: 14px;
color: rgb(var(--color-fg-muted));
line-height: 1.4;
}
.preference-label {
display: block;
font-size: 15px;
font-weight: 600;
color: rgb(var(--color-fg));
}
.preference-help {
margin: 4px 0 10px;
font-size: 13px;
color: rgb(var(--color-fg-muted));
line-height: 1.4;
}
.preference-select {
width: 100%;
max-width: 320px;
min-height: 44px; /* touch target */
padding: 0 12px;
border: 1px solid rgb(var(--color-line));
border-radius: 8px;
background: rgb(var(--color-card));
color: rgb(var(--color-fg));
font-size: 16px; /* 16px stops iOS zooming on focus */
}
.preference-status {
margin: 8px 0 0;
font-size: 13px;
color: rgb(var(--color-fg-muted));
}
.preference-status.is-error {
color: #b91c1c;
}
</style>
|