Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m54s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m0s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m54s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m50s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m48s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m38s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m56s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 7m5s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m17s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
67 lines
2.5 KiB
Vue
67 lines
2.5 KiB
Vue
<script setup>
|
||
import { onMounted, ref } from 'vue';
|
||
import { usePage } from '@inertiajs/vue3';
|
||
import { BellRing, LoaderCircle } from '@lucide/vue';
|
||
import { toast } from 'vue-sonner';
|
||
import { Switch } from '@/components/ui/switch';
|
||
import { http } from '@/lib/http';
|
||
import { currentSubscription, disablePush, enablePush, pushSupported } from '@/lib/push';
|
||
|
||
/**
|
||
* Schalter „Push-Benachrichtigungen auf diesem Gerät“.
|
||
*/
|
||
defineProps({
|
||
compact: { type: Boolean, default: false },
|
||
});
|
||
|
||
const page = usePage();
|
||
const supported = ref(false);
|
||
const enabled = ref(false);
|
||
const busy = ref(false);
|
||
const isIos = /iPhone|iPad|iPod/.test(navigator.userAgent) && !window.matchMedia('(display-mode: standalone)').matches;
|
||
|
||
onMounted(async () => {
|
||
supported.value = pushSupported() && !!page.props.push?.key;
|
||
|
||
if (supported.value) {
|
||
enabled.value = !!(await currentSubscription()) && Notification.permission === 'granted';
|
||
}
|
||
});
|
||
|
||
async function toggle(value) {
|
||
busy.value = true;
|
||
|
||
try {
|
||
if (value) {
|
||
await enablePush(page.props.push.key);
|
||
enabled.value = true;
|
||
await http.post('/push/test').catch(() => {});
|
||
toast.success('Push ist eingeschaltet – eine Testnachricht ist unterwegs.');
|
||
} else {
|
||
await disablePush();
|
||
enabled.value = false;
|
||
toast.success('Push auf diesem Gerät ausgeschaltet');
|
||
}
|
||
} catch (error) {
|
||
toast.error(error.message);
|
||
enabled.value = !!(await currentSubscription());
|
||
} finally {
|
||
busy.value = false;
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<div v-if="supported" class="flex items-center gap-3" :class="compact ? 'text-[13px]' : 'text-sm'">
|
||
<BellRing class="size-4 shrink-0 text-muted-foreground" />
|
||
<span class="min-w-0 flex-1">
|
||
Push auf diesem Gerät
|
||
<span v-if="!compact" class="block text-xs text-muted-foreground">Hinweise erscheinen auch, wenn das Portal nicht geöffnet ist.</span>
|
||
</span>
|
||
<LoaderCircle v-if="busy" class="size-4 animate-spin text-muted-foreground" />
|
||
<Switch :model-value="enabled" :disabled="busy" aria-label="Push-Benachrichtigungen auf diesem Gerät" @update:model-value="toggle" />
|
||
</div>
|
||
<p v-else-if="isIos && !compact" class="text-[13px] text-muted-foreground">
|
||
Auf iPhone und iPad gibt es Push-Benachrichtigungen, sobald das Portal über „Teilen → Zum Home-Bildschirm“ als App hinzugefügt wurde.
|
||
</p>
|
||
</template>
|