From 696967d88e74bdd28ea9dda4b873341c6dbdaa6a Mon Sep 17 00:00:00 2001 From: Drobysh Date: Thu, 1 Oct 2026 12:40:52 +0300 Subject: [PATCH] =?UTF-8?q?feat(settings):=20=D1=81=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=86=D0=B0=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=B5=D0=BA=20+=20=D0=B3=D0=BB=D0=BE=D0=B1=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9=20haptic=20+=20toggle=20=D0=B2=D0=B8=D0=B1?= =?UTF-8?q?=D1=80=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 5 + src/haptic.ts | 65 +++++++++ src/hooks/useGlobalHaptic.ts | 35 +++++ src/pages/MenuPage.tsx | 9 ++ src/pages/SettingsPage.tsx | 247 +++++++++++++++++++++++++++++++++++ 5 files changed, 361 insertions(+) create mode 100644 src/haptic.ts create mode 100644 src/hooks/useGlobalHaptic.ts create mode 100644 src/pages/SettingsPage.tsx 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