Implement CSV fetching utility across components for improved data handling
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 46s

This commit introduces a new utility function, fetchCsvText, to streamline the fetching of CSV data across multiple components. The function includes a cache-busting mechanism and retry logic to enhance reliability when retrieving data from the server. This change improves error handling and ensures consistent data retrieval in the Mannschaften overview, detail, and schedule pages, contributing to a more robust application.
This commit is contained in:
Torsten Schulz (local)
2026-01-18 23:40:59 +01:00
parent fa12bae426
commit 8043916129
4 changed files with 70 additions and 17 deletions

View File

@@ -140,12 +140,26 @@ import { Users } from 'lucide-vue-next'
const route = useRoute()
const mannschaft = ref(null)
async function fetchCsvText(url) {
const attempt = async () => {
const withBuster = `${url}${url.includes('?') ? '&' : '?'}_t=${Date.now()}`
const res = await fetch(withBuster, { cache: 'no-store' })
if (!res.ok) return null
return await res.text()
}
try {
return await attempt()
} catch (_e) {
await new Promise(resolve => setTimeout(resolve, 150))
return await attempt()
}
}
const loadMannschaften = async () => {
try {
const response = await fetch('/data/mannschaften.csv')
if (!response.ok) return
const csv = await response.text()
const csv = await fetchCsvText('/data/mannschaften.csv')
if (!csv) return
const lines = csv.split('\n').filter(line => line.trim() !== '')
if (lines.length < 2) return