From c0f4130edf7359247b9c805bad5adfaf556cc395 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 3 Aug 2022 11:42:54 -0500 Subject: [PATCH] Display popover in ad --- app/soapbox/features/ads/components/ad.tsx | 101 +++++++++++++-------- 1 file changed, 62 insertions(+), 39 deletions(-) diff --git a/app/soapbox/features/ads/components/ad.tsx b/app/soapbox/features/ads/components/ad.tsx index 7eb5ac892..fd7209eed 100644 --- a/app/soapbox/features/ads/components/ad.tsx +++ b/app/soapbox/features/ads/components/ad.tsx @@ -1,17 +1,13 @@ -import React, { useEffect } from 'react'; -import { FormattedMessage, defineMessages, useIntl } from 'react-intl'; +import React, { useState, useEffect } from 'react'; +import { FormattedMessage } from 'react-intl'; -import { Stack, HStack, Card, Tooltip, Avatar, Text, Icon } from 'soapbox/components/ui'; +import { Stack, HStack, Card, Avatar, Text, Icon } from 'soapbox/components/ui'; import IconButton from 'soapbox/components/ui/icon-button/icon-button'; import StatusCard from 'soapbox/features/status/components/card'; import { useAppSelector } from 'soapbox/hooks'; import type { Card as CardEntity } from 'soapbox/types/entities'; -const messages = defineMessages({ - tooltip: { id: 'sponsored.tooltip', defaultMessage: '{siteTitle} displays ads to help fund our service.' }, -}); - interface IAd { /** Embedded ad data in Card format (almost like OEmbed). */ card: CardEntity, @@ -21,9 +17,10 @@ interface IAd { /** Displays an ad in sponsored post format. */ const Ad: React.FC = ({ card, impression }) => { - const intl = useIntl(); const instance = useAppSelector(state => state.instance); + const [showInfo, setShowInfo] = useState(false); + // Fetch the impression URL (if any) upon displaying the ad. // It's common for ad providers to provide this. useEffect(() => { @@ -32,46 +29,72 @@ const Ad: React.FC = ({ card, impression }) => { } }, [impression]); + /** Toggle the info box on click. */ + const handleInfoButtonClick: React.MouseEventHandler = () => { + setShowInfo(!showInfo); + }; + return ( - - - - +
+ + + + - - - - {instance.title} - - - - - - - - - + + + + {instance.title} - - - - - + + + + + + + + + + + + + - - - + + - {}} horizontal /> - - + {}} horizontal /> + + + + {showInfo && ( +
+ + + + + + + + + + + +
+ )} +
); };