diff --git a/src/App.tsx b/src/App.tsx index f3e7157..1595f82 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -20,6 +20,8 @@ import TypingPage from './pages/TypingPage'; import AdminDashboardModal from './components/AdminDashboardModal'; import LearningPage from './pages/LearningPage'; import LecturesPage from './pages/LecturesPage'; +import SettingsPage from './pages/SettingsPage'; +import { useGlobalHaptic } from './hooks/useGlobalHaptic'; // 🔧 ФИКС (25.09.2026): DEAD_CODE_GET_IS_ADMIN_FALLBACK — // getIsAdmin больше не нужен: registerUser гарантирует is_admin: boolean. import { registerUser, trackDailyLogin } from './api'; @@ -27,6 +29,8 @@ import { getUserId } from './telegram'; function AppContent() { const navigate = useNavigate(); + // 🔧 ФИКС (01.10.2026): глобальный haptic на всех кнопках + useGlobalHaptic(); const location = useLocation(); const { setLang } = useLanguage(); const [showDashboard, setShowDashboard] = useState(false); @@ -248,6 +252,7 @@ function AppContent() { } /> } /> } /> + } /> {/* Дашборд админа — открывается через событие "open-dashboard" из MenuPage */} diff --git a/src/haptic.ts b/src/haptic.ts new file mode 100644 index 0000000..57a2a33 --- /dev/null +++ b/src/haptic.ts @@ -0,0 +1,65 @@ +/** + * Haptic — глобальная утилита для тактильного отклика. + * + * Использует Telegram.WebApp.HapticFeedback. + * Проверяет настройку filwords_haptics (localStorage). + * - '0' → выключено + * - отсутствует / '1' → включено (по умолчанию) + */ + +const isEnabled = (): boolean => { + if (typeof window === 'undefined') return false; + try { + return localStorage.getItem('filwords_haptics') !== '0'; + } catch { + return false; + } +}; + +// 🔧 ФИКС (01.10.2026): telegram_types_outdated — +// типы WebApp в проекте не знают HapticFeedback.selectionChanged, +// notificationOccurred, isVersionAtLeast. Кастуем к any. +const getHaptic = (): any => { + if (typeof window === 'undefined') return null; + return (window.Telegram as any)?.WebApp?.HapticFeedback || null; +}; + +export const haptic = { + light: () => { + if (!isEnabled()) return; + getHaptic()?.impactOccurred('light'); + }, + medium: () => { + if (!isEnabled()) return; + getHaptic()?.impactOccurred('medium'); + }, + heavy: () => { + if (!isEnabled()) return; + getHaptic()?.impactOccurred('heavy'); + }, + selection: () => { + if (!isEnabled()) return; + getHaptic()?.selectionChanged(); + }, + success: () => { + if (!isEnabled()) return; + getHaptic()?.notificationOccurred('success'); + }, + warning: () => { + if (!isEnabled()) return; + getHaptic()?.notificationOccurred('warning'); + }, + error: () => { + if (!isEnabled()) return; + getHaptic()?.notificationOccurred('error'); + }, + + /** Проверка, включена ли вибрация сейчас */ + isEnabled, + + /** Проверка, поддерживается ли Haptic в этом Telegram */ + isSupported: () => { + if (typeof window === 'undefined') return false; + return !!(window.Telegram as any)?.WebApp?.isVersionAtLeast?.('6.1'); + }, +}; \ No newline at end of file diff --git a/src/hooks/useGlobalHaptic.ts b/src/hooks/useGlobalHaptic.ts new file mode 100644 index 0000000..fdf0382 --- /dev/null +++ b/src/hooks/useGlobalHaptic.ts @@ -0,0 +1,35 @@ +import { useEffect } from 'react'; +import { haptic } from '../haptic'; + +/** + * useGlobalHaptic — глобальный перехват touchstart на кнопках. + * + * Работает на всех страницах автоматически. + * Добавляет лёгкую вибрацию на любой + {/* 🔧 НОВОЕ (01.10.2026): Кнопка Настройки — между Поддержкой и Дашбордом */} + + {/* Кнопка Дашборд — только для админов */} {isAdmin && ( + + + {/* Заголовок */} +

+ {tr('title')} +

+ + {/* Карточка вибрации */} +
+
+
📳
+
+
+ {tr('haptics')} +
+
+ {tr('hapticsDesc')} +
+
+ + {/* Toggle switch */} +
+
+
+
+ +
+ {hapticsEnabled ? '✓ ' + tr('enabled') : '✕ ' + tr('disabled')} +
+
+ + {/* О приложении */} +
+
+
ℹ️
+
+
+ {tr('about')} +
+
+ Filwords PL · {tr('version')} 3.8.0 +
+
+
+
+ +
+ Filwords PL © 2026 +
+
+ + ); +}; + +export default SettingsPage; \ No newline at end of file