feat(mannschaften): align public pages with season query logic
This commit is contained in:
@@ -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()
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user