Added a guest haptics preference and surfaced it in both the settings sheet and /settings, with safe device detection

and a reduced‑motion guard. Haptics now honor the toggle and still fall back gracefully on iOS (switch disabled when
  navigator.vibrate isn’t available).

  What changed

  - Haptics preference storage + gating: resources/js/guest/lib/haptics.ts
  - Preference hook: resources/js/guest/hooks/useHapticsPreference.ts
  - Settings UI toggle in sheet + page: resources/js/guest/components/settings-sheet.tsx, resources/js/guest/pages/
    SettingsPage.tsx
  - i18n labels: resources/js/guest/i18n/messages.ts
  - Tests: resources/js/guest/lib/__tests__/haptics.test.ts
This commit is contained in:
Codex Agent
2025-12-27 14:00:12 +01:00
parent 3e3a2c49d6
commit fa5a1fa367
11 changed files with 241 additions and 1 deletions

View File

@@ -14,12 +14,15 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com
import { Alert, AlertDescription } from '@/components/ui/alert';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Switch } from '@/components/ui/switch';
import { Settings, ArrowLeft, FileText, RefreshCcw, ChevronRight, UserCircle, LifeBuoy } from 'lucide-react';
import { useOptionalGuestIdentity } from '../context/GuestIdentityContext';
import { LegalMarkdown } from './legal-markdown';
import { useLocale, type LocaleContextValue } from '../i18n/LocaleContext';
import { useTranslation } from '../i18n/useTranslation';
import type { LocaleCode } from '../i18n/messages';
import { useHapticsPreference } from '../hooks/useHapticsPreference';
import { triggerHaptic } from '../lib/haptics';
const legalPages = [
{ slug: 'impressum', translationKey: 'settings.legal.section.impressum' },
@@ -262,6 +265,7 @@ function HomeView({
helpHref,
}: HomeViewProps) {
const { t } = useTranslation();
const { enabled: hapticsEnabled, setEnabled: setHapticsEnabled, supported: hapticsSupported } = useHapticsPreference();
const legalLinks = React.useMemo(
() =>
legalPages.map((page) => ({
@@ -355,6 +359,32 @@ function HomeView({
</Card>
)}
<Card>
<CardHeader className="pb-3">
<CardTitle>{t('settings.haptics.title')}</CardTitle>
<CardDescription>{t('settings.haptics.description')}</CardDescription>
</CardHeader>
<CardContent className="space-y-2">
<div className="flex items-center justify-between gap-4">
<span className="text-sm font-medium">{t('settings.haptics.label')}</span>
<Switch
checked={hapticsEnabled}
onCheckedChange={(checked) => {
setHapticsEnabled(checked);
if (checked) {
triggerHaptic('selection');
}
}}
disabled={!hapticsSupported}
aria-label={t('settings.haptics.label')}
/>
</div>
{!hapticsSupported && (
<div className="text-xs text-muted-foreground">{t('settings.haptics.unsupported')}</div>
)}
</CardContent>
</Card>
<Card>
<CardHeader className="pb-3">
<CardTitle>