|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useEffect, useSyncExternalStore } from "react"; |
| 4 | + |
| 5 | +const DISMISSED_KEY = "desktop-tip-dismissed"; |
| 6 | + |
| 7 | +let listeners: Array<() => void> = []; |
| 8 | +function emitChange() { |
| 9 | + listeners.forEach((l) => l()); |
| 10 | +} |
| 11 | + |
| 12 | +export function DesktopTipModal() { |
| 13 | + const notDismissed = useSyncExternalStore( |
| 14 | + (listener) => { |
| 15 | + listeners.push(listener); |
| 16 | + return () => { |
| 17 | + listeners = listeners.filter((l) => l !== listener); |
| 18 | + }; |
| 19 | + }, |
| 20 | + () => { |
| 21 | + try { return !sessionStorage.getItem(DISMISSED_KEY); } |
| 22 | + catch { return false; } |
| 23 | + }, |
| 24 | + () => false, |
| 25 | + ); |
| 26 | + |
| 27 | + const dismiss = () => { |
| 28 | + try { sessionStorage.setItem(DISMISSED_KEY, "1"); } |
| 29 | + catch { /* privacy-restricted context */ } |
| 30 | + emitChange(); |
| 31 | + }; |
| 32 | + |
| 33 | + useEffect(() => { |
| 34 | + if (!notDismissed) return; |
| 35 | + const handleKeyDown = (e: KeyboardEvent) => { |
| 36 | + if (e.key === "Escape") dismiss(); |
| 37 | + }; |
| 38 | + document.addEventListener("keydown", handleKeyDown); |
| 39 | + return () => document.removeEventListener("keydown", handleKeyDown); |
| 40 | + }); |
| 41 | + |
| 42 | + if (!notDismissed) return null; |
| 43 | + |
| 44 | + return ( |
| 45 | + <div |
| 46 | + onClick={dismiss} |
| 47 | + className="fixed inset-0 z-[9999] flex items-center justify-center p-6 sm:hidden" |
| 48 | + style={{ |
| 49 | + background: "rgba(0,0,0,0.45)", |
| 50 | + backdropFilter: "blur(6px)", |
| 51 | + WebkitBackdropFilter: "blur(6px)", |
| 52 | + }} |
| 53 | + > |
| 54 | + <div |
| 55 | + onClick={(e) => e.stopPropagation()} |
| 56 | + style={{ |
| 57 | + background: "var(--color-glass-dark, rgba(255,255,255,0.9))", |
| 58 | + backdropFilter: "blur(16px)", |
| 59 | + WebkitBackdropFilter: "blur(16px)", |
| 60 | + border: "1px solid var(--color-border-glass, rgba(255,255,255,0.3))", |
| 61 | + borderRadius: "var(--radius-xl, 16px)", |
| 62 | + boxShadow: "var(--shadow-glass, 0 4px 30px rgba(0,0,0,0.1))", |
| 63 | + padding: "32px 28px", |
| 64 | + maxWidth: 340, |
| 65 | + width: "100%", |
| 66 | + textAlign: "center", |
| 67 | + fontFamily: "var(--font-family)", |
| 68 | + }} |
| 69 | + > |
| 70 | + {/* Monitor icon */} |
| 71 | + <div |
| 72 | + style={{ |
| 73 | + width: 56, |
| 74 | + height: 56, |
| 75 | + margin: "0 auto 20px", |
| 76 | + borderRadius: 14, |
| 77 | + background: "linear-gradient(135deg, rgba(190,194,255,0.15), rgba(133,224,206,0.12))", |
| 78 | + display: "flex", |
| 79 | + alignItems: "center", |
| 80 | + justifyContent: "center", |
| 81 | + }} |
| 82 | + > |
| 83 | + <svg |
| 84 | + width="28" |
| 85 | + height="28" |
| 86 | + viewBox="0 0 24 24" |
| 87 | + fill="none" |
| 88 | + stroke="var(--color-lilac-dark, #9599CC)" |
| 89 | + strokeWidth="1.8" |
| 90 | + strokeLinecap="round" |
| 91 | + strokeLinejoin="round" |
| 92 | + > |
| 93 | + <rect x="2" y="3" width="20" height="14" rx="2" /> |
| 94 | + <path d="M8 21h8" /> |
| 95 | + <path d="M12 17v4" /> |
| 96 | + </svg> |
| 97 | + </div> |
| 98 | + |
| 99 | + <h2 |
| 100 | + style={{ |
| 101 | + fontSize: 18, |
| 102 | + fontWeight: 700, |
| 103 | + color: "var(--text-primary, #374151)", |
| 104 | + margin: "0 0 8px", |
| 105 | + letterSpacing: "-0.01em", |
| 106 | + }} |
| 107 | + > |
| 108 | + Best viewed on desktop |
| 109 | + </h2> |
| 110 | + |
| 111 | + <p |
| 112 | + style={{ |
| 113 | + fontSize: 14, |
| 114 | + color: "var(--text-secondary, #6b7280)", |
| 115 | + margin: "0 0 24px", |
| 116 | + lineHeight: 1.5, |
| 117 | + }} |
| 118 | + > |
| 119 | + This experience includes interactive visualizations that work best on larger screens. |
| 120 | + </p> |
| 121 | + |
| 122 | + <button |
| 123 | + onClick={dismiss} |
| 124 | + style={{ |
| 125 | + width: "100%", |
| 126 | + padding: "10px 20px", |
| 127 | + borderRadius: 999, |
| 128 | + fontSize: 14, |
| 129 | + fontWeight: 600, |
| 130 | + fontFamily: "var(--font-family)", |
| 131 | + color: "#fff", |
| 132 | + background: "linear-gradient(135deg, var(--color-lilac-dark, #9599CC), var(--color-mint-dark, #1B936F))", |
| 133 | + border: "none", |
| 134 | + boxShadow: "0 1px 4px rgba(149,153,204,0.3)", |
| 135 | + cursor: "pointer", |
| 136 | + }} |
| 137 | + > |
| 138 | + Continue anyway |
| 139 | + </button> |
| 140 | + </div> |
| 141 | + </div> |
| 142 | + ); |
| 143 | +} |
0 commit comments