'use client'; import Modal from '@/components/Modal'; import { TbPhotoShare } from 'react-icons/tb'; import { clsx } from 'clsx/lite'; import { BiCopy } from 'react-icons/bi'; import { ReactNode, useEffect } from 'react'; import { shortenUrl } from '@/utility/url'; import { toastSuccess } from '@/toast'; import { PiXLogo } from 'react-icons/pi'; import { SHOW_SOCIAL } from '@/app/config'; import { generateXPostText } from '@/utility/social'; import { useAppState } from '@/state/AppState'; import useOnPathChange from '@/utility/useOnPathChange'; import { IoArrowUp } from 'react-icons/io5'; import MaskedScroll from '@/components/MaskedScroll'; import { useAppText } from '@/i18n/state/client'; export default function ShareModal({ title, pathShare, socialText, navigatorTitle, navigatorText, children, }: { title?: string pathShare: string socialText: string navigatorTitle: string navigatorText?: string children: ReactNode }) { const { setShareModalProps, setShouldRespondToKeyboardCommands, } = useAppState(); const appText = useAppText(); useEffect(() => { setShouldRespondToKeyboardCommands?.(false); return () => setShouldRespondToKeyboardCommands?.(true); }, [setShouldRespondToKeyboardCommands]); const renderIcon = ( icon: ReactNode, action: () => void, embedded?: boolean, ) =>
{icon}
; useOnPathChange(() => setShareModalProps?.(undefined)); return ( setShareModalProps?.(undefined)}>
{title &&
{title}
} {children}
{shortenUrl(pathShare)}
{renderIcon( , () => { navigator.clipboard.writeText(pathShare); toastSuccess(appText.photo.copied); }, true, )}
{typeof navigator !== 'undefined' && navigator.share && renderIcon( , () => navigator.share({ title: navigatorTitle, text: navigatorText, url: pathShare, }) .catch(() => console.log('Share canceled')), )} {SHOW_SOCIAL && renderIcon( , () => window.open( generateXPostText(pathShare, socialText), '_blank', ), )}
); };