feat(mannschaften): align public pages with season query logic
Some checks failed
Code Analysis and Production Deploy / deploy-production (push) Has been cancelled
Code Analysis and Production Deploy / deploy-test (push) Has been cancelled
Code Analysis and Production Deploy / analyze (push) Has been cancelled

This commit is contained in:
Torsten Schulz (local)
2026-05-20 18:01:07 +02:00
parent cfd9365d07
commit 11ff823fe2
4 changed files with 97 additions and 11 deletions

View File

@@ -361,6 +361,9 @@
<script setup>
import { ref, onMounted } from 'vue'
const route = useRoute()
const router = useRouter()
useHead({
title: 'Spielpläne - Mannschaften - Harheimer TC'
})
@@ -378,6 +381,19 @@ const seasons = ref([])
const selectedSeason = ref('')
const hasLoadedSpielplan = ref(false)
function getCurrentSeasonSlug() {
const now = new Date()
const year = now.getFullYear()
const startYear = now.getMonth() >= 6 ? year : year - 1
const endYear = startYear + 1
return `${String(startYear).slice(-2)}--${String(endYear).slice(-2)}`
}
function normalizeSeasonOrDefault(value) {
const season = String(value || '').trim()
return /^\d{2}--\d{2}$/.test(season) ? season : getCurrentSeasonSlug()
}
async function fetchCsvText(url) {
const attempt = async () => {
const withBuster = `${url}${url.includes('?') ? '&' : '?'}_t=${Date.now()}`
@@ -405,7 +421,7 @@ const loadData = async () => {
const [spielplanResponse, mannschaftenResponse] = await Promise.all([
fetch(`/api/spielplan${params.toString() ? `?${params.toString()}` : ''}`),
fetchCsvText('/api/mannschaften')
fetchCsvText(`/api/mannschaften${params.toString() ? `?${params.toString()}` : ''}`)
])
const spielplanResult = await spielplanResponse.json()
@@ -494,11 +510,13 @@ const applyMannschaftenResponse = async (csvText) => {
}
const onSeasonChange = () => {
router.replace({ query: { ...route.query, season: selectedSeason.value } })
spielplanData.value = []
filteredData.value = []
headers.value = []
lastUpdated.value = ''
hasLoadedSpielplan.value = false
loadData()
}
const filterData = () => {
@@ -841,6 +859,7 @@ const getWettbewerbText = () => {
}
onMounted(() => {
selectedSeason.value = normalizeSeasonOrDefault(route.query.season)
loadData()
})