chore: fix a typo
All checks were successful
Deploy to Netlify / Deploy to Netlify (push) Successful in 1m34s

This commit is contained in:
Nathan Lamy 2025-08-19 22:48:33 +02:00
parent 8b57952344
commit 65e9c0fc19
2 changed files with 14 additions and 4 deletions

View file

@ -38,6 +38,9 @@ export default function NotificationSettings() {
.then(() => { .then(() => {
setPushEnabled(true); setPushEnabled(true);
}) })
.catch((error) => {
console.error("Failed to unregister notifications:", error);
})
.finally(() => { .finally(() => {
setIsRegistering(false); setIsRegistering(false);
}); });
@ -45,12 +48,15 @@ export default function NotificationSettings() {
// Register notifications // Register notifications
registerNotification() registerNotification()
.then((result) => { .then((result) => {
if ("error" in result) { if ("error" in result && result.error) {
console.error("Failed to register notifications:", result.error); console.error("Failed to register notifications:", result.error);
} else { } else {
setPushEnabled(false); setPushEnabled(false);
} }
}) })
.catch((error) => {
console.error("Failed to unregister notifications:", error);
})
.finally(() => { .finally(() => {
setIsRegistering(false); setIsRegistering(false);
}); });
@ -121,7 +127,7 @@ export default function NotificationSettings() {
</CardDescription> </CardDescription>
</CardHeader> </CardHeader>
<CardContent className="space-y-4"> <CardContent className="space-y-4">
{isInstalled() ? ( {!isInstalled() ? (
pushEnabled ? ( pushEnabled ? (
<div className="flex items-start sm:items-center justify-between gap-4"> <div className="flex items-start sm:items-center justify-between gap-4">
<div className="space-y-1 flex-1"> <div className="space-y-1 flex-1">

View file

@ -9,12 +9,16 @@ export async function registerNotification() {
error: "E_PERMISSION_DENIED", error: "E_PERMISSION_DENIED",
}; };
} }
if (!("serviceWorker" in navigator) || !("PushManager" in window)) {
return {
error: "E_UNSUPPORTED",
};
}
const registration = await navigator.serviceWorker.ready; const registration = await navigator.serviceWorker.ready;
try { try {
const subscription = await registration.pushManager.subscribe({ const subscription = await registration.pushManager.subscribe({
userVisibleOnly: true, userVisibleOnly: true,
applicationServerKey: process.env.VITE_PUBLIC_VAPID_KEY, applicationServerKey: import.meta.env.VITE_PUBLIC_VAPID_KEY,
}); });
await subscribe(subscription); await subscribe(subscription);
// Store to local storage // Store to local storage