import * as React from 'react' import * as Popover from '@radix-ui/react-popover' import { ThumbsDown, ThumbsUp, X } from 'phosphor-react' import { useLocation, useFetcher } from '@remix-run/react' import { Heading } from '~/components/Text/Heading' import { Copy } from '~/components/Text/Copy' import { GradientButton } from '~/components/Buttons/GradientButton' import { useIsDarkTheme } from '~/hooks/useIsDarkTheme' import { EventNames, firePlausibleEvent } from '~/helpers/analytics' import { heading, outbound, popoverButton, popoverClose, popoverContent, popoverFormFooter, popoverHeader, popoverInput, popoverInputLabel, stack, trigger, } from './Feedback.css' import { visuallyHidden } from '../../styles/utilities.css' interface FeedbackProps { location?: string } export const Feedback = ({ location }: FeedbackProps) => { const [pageTitle, setPageTitle] = React.useState('') const [selected, setSelected] = React.useState<'upvote' | 'downvote' | null>( null ) const isDarkMode = useIsDarkTheme() const handleClick = (type: 'upvote' | 'downvote') => () => { setSelected(type) const name = type === 'upvote' ? EventNames.DocLiked : EventNames.DocDisliked if (location) { firePlausibleEvent({ name, additionalProps: { location, title: pageTitle, }, }) } } React.useEffect(() => { const element = document.querySelector('h1 > a') if (element) { setPageTitle(element.innerHTML) } }, []) React.useEffect(() => { setSelected(null) /** * if the location changes, reset the selected state * otherwise you vote once somewhere and can never do it again */ }, [location]) return (