feat(a11y): cross-platform hardening + modal focus-trap from impeccable audit

Responsive / viewport:
- add .min-h-viewport / .h-viewport utilities (100dvh + Telegram --tg-viewport-stable-height)
- migrate min-h-screen / h-screen / 100vh across 18 files
- reveal hover-only controls on focus-within + touch (desktop nav, admin settings)
- grid breakpoints (TopUpAmount, Contests), larger touch targets, nav aria-labels

Platform routing (Telegram WebView correctness):
- clipboard -> copyToClipboard util with execCommand fallback (10 files)
- window.open -> openTelegramLink / openLink (Profile, Referral, ChannelSubscriptionScreen)
- window.confirm -> useNativeDialog (admin pages); PromoOffersSection -> useDestructiveConfirm
- window.prompt -> usePrompt / PromptDialogHost (TipTap link editors)
- ESLint no-restricted-properties guard against regressions (adapters/clipboard util exempt)

Modal accessibility:
- new useFocusTrap hook (focus trap, Esc, scroll lock, focus restore)
- role=dialog / aria-modal / focus-trap: Polls, SuccessNotificationModal, AdminPolicies,
  AdminPromoGroups, AdminCampaigns, BroadcastPreview (Telegram + Email)
- new global usePrompt store + PromptDialogHost
This commit is contained in:
c0mrade
2026-05-25 23:16:07 +03:00
parent 2bcba3b60f
commit 8e0b63bac8
48 changed files with 584 additions and 173 deletions

View File

@@ -2,21 +2,10 @@ import { useState, useEffect, useCallback, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useBlockingStore } from '../../store/blocking';
import { apiClient, isChannelSubscriptionError } from '../../api/client';
import { usePlatform } from '../../platform';
const CHECK_COOLDOWN_SECONDS = 5;
function safeOpenUrl(url: string | undefined | null): void {
if (!url) return;
try {
const parsed = new URL(url);
if (parsed.protocol === 'https:' || parsed.protocol === 'http:') {
window.open(url, '_blank', 'noopener');
}
} catch {
// invalid URL, do nothing
}
}
export default function ChannelSubscriptionScreen() {
const { t } = useTranslation();
const channelInfo = useBlockingStore((state) => state.channelInfo);
@@ -25,6 +14,28 @@ export default function ChannelSubscriptionScreen() {
const [cooldown, setCooldown] = useState(0);
const [error, setError] = useState<string | null>(null);
const isCheckingRef = useRef(false);
const { openLink, openTelegramLink } = usePlatform();
// Route channel links through the platform adapter: inside the Telegram
// WebView a raw window.open is intercepted by the client and the link
// silently fails to open. t.me links use openTelegramLink; others openLink.
const openChannel = useCallback(
(url: string | undefined | null) => {
if (!url) return;
try {
const parsed = new URL(url);
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') return;
if (parsed.hostname === 't.me' || parsed.hostname.endsWith('.t.me')) {
openTelegramLink(url);
} else {
openLink(url);
}
} catch {
// invalid URL, do nothing
}
},
[openLink, openTelegramLink],
);
// Cooldown timer
useEffect(() => {
@@ -100,7 +111,7 @@ export default function ChannelSubscriptionScreen() {
<span className="text-sm font-medium text-white">{ch.title || ch.channel_id}</span>
{ch.channel_link && (
<button
onClick={() => safeOpenUrl(ch.channel_link)}
onClick={() => openChannel(ch.channel_link)}
className="rounded-lg bg-blue-500/20 px-3 py-1 text-xs font-medium text-blue-400 hover:bg-blue-500/30"
>
{t('blocking.channel.openChannel')}
@@ -114,7 +125,7 @@ export default function ChannelSubscriptionScreen() {
{/* Fallback: single channel (legacy) */}
{channels.length === 0 && channelInfo?.channel_link && (
<button
onClick={() => safeOpenUrl(channelInfo.channel_link)}
onClick={() => openChannel(channelInfo.channel_link)}
className="mb-6 flex w-full items-center justify-center gap-3 rounded-xl bg-gradient-to-r from-blue-500 to-cyan-500 px-6 py-4 font-semibold text-white transition-all duration-200 hover:from-blue-600 hover:to-cyan-600"
>
{t('blocking.channel.openChannel')}