From 73bd348c458d4447e45f801f61f8b106475bc3dc Mon Sep 17 00:00:00 2001 From: Dominic H Date: Thu, 18 Jul 2024 16:33:48 +0200 Subject: [PATCH] Fix `navigator.vibrate` check, address review comments --- src/pages/Settings.tsx | 1 - src/pages/participant/ParticipantPage.tsx | 4 ++-- src/utils/haptics.ts | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/pages/Settings.tsx b/src/pages/Settings.tsx index e6724d7..00d7f2a 100644 --- a/src/pages/Settings.tsx +++ b/src/pages/Settings.tsx @@ -37,7 +37,6 @@ function MainSettings() { hapticFeedback, setHapticFeedback, } = useSettings(); - console.log('hapticFeedback', typeof hapticFeedback); const toggleDarkMode = () => { // Set the theme preference in localStorage and in the SettingsContext diff --git a/src/pages/participant/ParticipantPage.tsx b/src/pages/participant/ParticipantPage.tsx index 367e679..46f2b51 100644 --- a/src/pages/participant/ParticipantPage.tsx +++ b/src/pages/participant/ParticipantPage.tsx @@ -130,7 +130,7 @@ function ParticipantPageContent({ }); } } - }, [participant, errorModal]); + }, [participant, errorModal, hapticFeedback]); const accompanyingPersons = useMemo(() => { if (participant?.registrationData) { @@ -161,7 +161,7 @@ function ParticipantPageContent({ } finally { } }, - [offline, errorModal, soundEffect] + [offline, errorModal, soundEffect, hapticFeedback] ); useEffect(() => { diff --git a/src/utils/haptics.ts b/src/utils/haptics.ts index 3e4f8dd..82fba19 100644 --- a/src/utils/haptics.ts +++ b/src/utils/haptics.ts @@ -4,13 +4,13 @@ const patterns = { clear: [0], }; -export function vibrate(pattern: number[]) { - if (!navigator.vibrate || !navigator.userActivation.isActive) { +function vibrate(pattern: number[]) { + if (!('vibrate' in navigator) || !navigator.userActivation.isActive) { console.warn('Haptics not supported!'); return; } - navigator.vibrate(pattern); + return navigator.vibrate(pattern); } export const playVibration = {