"use client";
import Link from "next/link";
import { useState, useSyncExternalStore } from "react";
import { useLocale } from "@/components/locale-provider";
const key = "trycode:cookie-notice-dismissed";
const subscribe = () => () => {};
export function CookieNotice() {
const en = useLocale() === "en";
const hydrated = useSyncExternalStore(subscribe, () => true, () => false);
const [dismissed, setDismissed] = useState(false);
let storedDismissal = false;
if (hydrated) {
try { storedDismissal = localStorage.getItem(key) === "true"; }
catch { /* Show the notice when storage is unavailable. */ }
}
if (!hydrated || dismissed || storedDismissal) return null;
return <aside className="cookie-notice" aria-label={en ? "Cookie notice" : "Уведомление о cookies"}>
<span className="cookie-notice-icon" aria-hidden="true">🍪</span>
<div><strong>{en ? "We use cookies" : "Мы используем cookies"}</strong><p>{en ? "To make this site work." : "Для работы сайта."} <Link href="/cookies">{en ? "About cookies" : "О cookies"}</Link> · <Link href="/privacy">{en ? "Privacy" : "Конфиденциальность"}</Link></p></div>
<button type="button" onClick={() => { try { localStorage.setItem(key, "true"); } catch { /* The notice may reappear on the next visit. */ } setDismissed(true); }}>ОК</button>
</aside>;
}
Code will run automatically after changes.
Code runs in an isolated environment.
Code runs in an isolated environment.