Frontend: Composables useConfirm/useChat/usePolling; Guide-Chat abbrechbar

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
team3
2026-06-12 08:12:11 +02:00
parent 601237bbbf
commit 5c35939eab
6 changed files with 178 additions and 94 deletions

View File

@@ -0,0 +1,44 @@
import { onUnmounted } from 'vue'
// Polling mit Visibility-Pause: Tab unsichtbar → stoppen; wieder sichtbar →
// sofortiger Tick, dann weiter, falls isActive(). Stoppt selbst, sobald
// isActive() nach einem Tick false liefert.
export function usePolling(tick, isActive, interval = 3000) {
let timer = null
function stop() {
if (timer) {
clearInterval(timer)
timer = null
}
}
function start() {
stop()
timer = setInterval(async () => {
await tick()
if (!isActive()) stop()
}, interval)
}
function running() {
return !!timer
}
async function onVisibility() {
if (document.hidden) {
stop()
} else {
await tick()
if (isActive()) start()
}
}
document.addEventListener('visibilitychange', onVisibility)
onUnmounted(() => {
stop()
document.removeEventListener('visibilitychange', onVisibility)
})
return { start, stop, running }
}