Hide language switcher by default; unlock with 5 taps on top-right.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -15,12 +15,7 @@ export default function AboutPage() {
|
|||||||
paddingBottom: "max(2.5rem, calc(1.5rem + var(--safe-bottom)))",
|
paddingBottom: "max(2.5rem, calc(1.5rem + var(--safe-bottom)))",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<LanguageSwitcher />
|
||||||
className="absolute right-4 z-10"
|
|
||||||
style={{ top: "max(1rem, calc(0.75rem + var(--safe-top)))" }}
|
|
||||||
>
|
|
||||||
<LanguageSwitcher />
|
|
||||||
</div>
|
|
||||||
<div className="mx-auto w-full max-w-md">
|
<div className="mx-auto w-full max-w-md">
|
||||||
<h1 className="text-xl font-bold text-neutral-900">{t.about.title}</h1>
|
<h1 className="text-xl font-bold text-neutral-900">{t.about.title}</h1>
|
||||||
<p className="mt-4 text-sm leading-relaxed text-neutral-600">
|
<p className="mt-4 text-sm leading-relaxed text-neutral-600">
|
||||||
|
|||||||
@@ -15,12 +15,7 @@ export default function ContactPage() {
|
|||||||
paddingBottom: "max(2.5rem, calc(1.5rem + var(--safe-bottom)))",
|
paddingBottom: "max(2.5rem, calc(1.5rem + var(--safe-bottom)))",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<LanguageSwitcher />
|
||||||
className="absolute right-4 z-10"
|
|
||||||
style={{ top: "max(1rem, calc(0.75rem + var(--safe-top)))" }}
|
|
||||||
>
|
|
||||||
<LanguageSwitcher />
|
|
||||||
</div>
|
|
||||||
<div className="mx-auto w-full max-w-md">
|
<div className="mx-auto w-full max-w-md">
|
||||||
<h1 className="text-xl font-bold text-neutral-900">{t.contact.title}</h1>
|
<h1 className="text-xl font-bold text-neutral-900">{t.contact.title}</h1>
|
||||||
<p className="mt-4 text-sm leading-relaxed text-neutral-600">
|
<p className="mt-4 text-sm leading-relaxed text-neutral-600">
|
||||||
|
|||||||
@@ -10,15 +10,10 @@ export default function HomePage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="flex min-h-dvh flex-col"
|
className="relative flex min-h-dvh flex-col"
|
||||||
style={{ minHeight: "100dvh" }}
|
style={{ minHeight: "100dvh" }}
|
||||||
>
|
>
|
||||||
<div
|
<LanguageSwitcher />
|
||||||
className="absolute right-4 z-10"
|
|
||||||
style={{ top: "max(1rem, calc(0.75rem + var(--safe-top)))" }}
|
|
||||||
>
|
|
||||||
<LanguageSwitcher />
|
|
||||||
</div>
|
|
||||||
<main className="flex flex-1 flex-col">
|
<main className="flex flex-1 flex-col">
|
||||||
<Hero />
|
<Hero />
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
import { useLocale } from "~/components/locale-provider";
|
import { useLocale } from "~/components/locale-provider";
|
||||||
import type { Locale } from "~/lib/i18n";
|
import type { Locale } from "~/lib/i18n";
|
||||||
|
|
||||||
@@ -8,32 +9,86 @@ const OPTIONS: { value: Locale; label: string }[] = [
|
|||||||
{ value: "en", label: "English" },
|
{ value: "en", label: "English" },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const UNLOCK_CLICKS = 5;
|
||||||
|
const CLICK_WINDOW_MS = 2500;
|
||||||
|
const UNLOCK_KEY = "nomadro-lang-unlock";
|
||||||
|
|
||||||
export function LanguageSwitcher({ className = "" }: { className?: string }) {
|
export function LanguageSwitcher({ className = "" }: { className?: string }) {
|
||||||
const { locale, setLocale, t } = useLocale();
|
const { locale, setLocale, t } = useLocale();
|
||||||
|
const [visible, setVisible] = useState(false);
|
||||||
|
const clicksRef = useRef(0);
|
||||||
|
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
try {
|
||||||
|
if (window.sessionStorage.getItem(UNLOCK_KEY) === "1") {
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleSecretClick = useCallback(() => {
|
||||||
|
if (visible) return;
|
||||||
|
|
||||||
|
clicksRef.current += 1;
|
||||||
|
|
||||||
|
if (timerRef.current) clearTimeout(timerRef.current);
|
||||||
|
timerRef.current = setTimeout(() => {
|
||||||
|
clicksRef.current = 0;
|
||||||
|
}, CLICK_WINDOW_MS);
|
||||||
|
|
||||||
|
if (clicksRef.current >= UNLOCK_CLICKS) {
|
||||||
|
clicksRef.current = 0;
|
||||||
|
if (timerRef.current) clearTimeout(timerRef.current);
|
||||||
|
setVisible(true);
|
||||||
|
try {
|
||||||
|
window.sessionStorage.setItem(UNLOCK_KEY, "1");
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [visible]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<label
|
<div
|
||||||
className={`inline-flex items-center gap-2 text-xs text-neutral-500 ${className}`}
|
className={`absolute right-0 z-10 ${className}`}
|
||||||
|
style={{ top: "max(0.5rem, var(--safe-top))" }}
|
||||||
>
|
>
|
||||||
<span className="sr-only">{t.languageLabel}</span>
|
{/* Invisible hit area — tap 5 times to reveal */}
|
||||||
<select
|
<button
|
||||||
value={locale}
|
type="button"
|
||||||
onChange={(event) => setLocale(event.target.value as Locale)}
|
aria-hidden={!visible}
|
||||||
aria-label={t.languageLabel}
|
tabIndex={-1}
|
||||||
className="appearance-none rounded-lg border border-neutral-200 bg-white px-2.5 py-1.5 pr-7 text-xs font-medium text-neutral-700 shadow-sm outline-none transition hover:border-neutral-300 focus:border-neutral-400"
|
onClick={handleSecretClick}
|
||||||
style={{
|
className="absolute right-0 top-0 h-12 w-16 cursor-default border-0 bg-transparent p-0"
|
||||||
backgroundImage:
|
style={{ opacity: 0 }}
|
||||||
"url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a3a3a3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E\")",
|
/>
|
||||||
backgroundRepeat: "no-repeat",
|
|
||||||
backgroundPosition: "right 0.55rem center",
|
{visible ? (
|
||||||
}}
|
<label className="relative z-10 mr-4 mt-2 inline-flex items-center gap-2 text-xs text-neutral-500">
|
||||||
>
|
<span className="sr-only">{t.languageLabel}</span>
|
||||||
{OPTIONS.map((option) => (
|
<select
|
||||||
<option key={option.value} value={option.value}>
|
value={locale}
|
||||||
{option.label}
|
onChange={(event) => setLocale(event.target.value as Locale)}
|
||||||
</option>
|
aria-label={t.languageLabel}
|
||||||
))}
|
className="appearance-none rounded-lg border border-neutral-200 bg-white px-2.5 py-1.5 pr-7 text-xs font-medium text-neutral-700 shadow-sm outline-none transition hover:border-neutral-300 focus:border-neutral-400"
|
||||||
</select>
|
style={{
|
||||||
</label>
|
backgroundImage:
|
||||||
|
"url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a3a3a3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E\")",
|
||||||
|
backgroundRepeat: "no-repeat",
|
||||||
|
backgroundPosition: "right 0.55rem center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{OPTIONS.map((option) => (
|
||||||
|
<option key={option.value} value={option.value}>
|
||||||
|
{option.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,11 @@ export function LocaleProvider({ children }: { children: ReactNode }) {
|
|||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Prefer auto detection; only keep a locale if user unlocked and switched.
|
||||||
|
const unlocked = window.sessionStorage.getItem("nomadro-lang-unlock") === "1";
|
||||||
const saved = window.localStorage.getItem(STORAGE_KEY);
|
const saved = window.localStorage.getItem(STORAGE_KEY);
|
||||||
if (isLocale(saved)) {
|
|
||||||
|
if (unlocked && isLocale(saved)) {
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
setLocaleState(saved);
|
setLocaleState(saved);
|
||||||
setReady(true);
|
setReady(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user