import React, { useState, useEffect } from 'react'; import { useAuth } from '../../context/AuthContext'; import CryptID from './CryptID'; import '../../css/anonymous-banner.css'; interface AnonymousViewerBannerProps { /** Callback when user successfully signs up/logs in */ onAuthenticated?: () => void; /** Whether the banner was triggered by an edit attempt */ triggeredByEdit?: boolean; } /** * Banner shown to anonymous (unauthenticated) users viewing a board. * Explains CryptID and provides a smooth sign-up flow. */ const AnonymousViewerBanner: React.FC = ({ onAuthenticated, triggeredByEdit = false }) => { const { session } = useAuth(); const [isDismissed, setIsDismissed] = useState(false); const [showSignUp, setShowSignUp] = useState(false); const [isExpanded, setIsExpanded] = useState(triggeredByEdit); // Check if banner was previously dismissed this session useEffect(() => { const dismissed = sessionStorage.getItem('anonymousBannerDismissed'); if (dismissed && !triggeredByEdit) { setIsDismissed(true); } }, [triggeredByEdit]); // If user is authenticated, don't show banner if (session.authed) { return null; } // If dismissed and not triggered by edit, don't show if (isDismissed && !triggeredByEdit) { return null; } const handleDismiss = () => { sessionStorage.setItem('anonymousBannerDismissed', 'true'); setIsDismissed(true); }; const handleSignUpClick = () => { setShowSignUp(true); }; const handleSignUpSuccess = () => { setShowSignUp(false); if (onAuthenticated) { onAuthenticated(); } }; const handleSignUpCancel = () => { setShowSignUp(false); }; // Show CryptID modal when sign up is clicked if (showSignUp) { return (
); } return (
{triggeredByEdit ? (

Want to edit this board?

) : (

You're viewing this board anonymously

)} {isExpanded ? (

Sign in by creating a username as your CryptID — no password required!

  • 🔒 Secured with encrypted keys, right in your browser, by a W3C standard algorithm
  • 💾 Your session is stored for offline access, encrypted in browser storage by the same key
  • 📦 Full data portability — use your canvas securely any time you like
) : (

Create a free CryptID to edit this board — no password needed!

)}
{!triggeredByEdit && ( )} {!isExpanded && ( )}
{triggeredByEdit && (
This board is in read-only mode for anonymous viewers
)}
); }; export default AnonymousViewerBanner;