Skip to content

Commit

Permalink
fix: desktop & mobile dismissible defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
thechefpenguin committed Nov 7, 2024
1 parent 944dbb7 commit ee653e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
20 changes: 16 additions & 4 deletions apps/web/src/components/AdPanel/CardLayouts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ const AdSlides = memo(({ forceMobile, isDismissible = true }: AdPlayerProps) =>

/**
* For abstraction and use in pages where we need to
* directly render the Ads Card purely without any conditions
* directly render the Ads Card purely without any conditions.
* > Note that dismissing Ads elsewhere in the application via useShowAdPanel
* does not affect this component's visibility.
*/
export const AdPlayer = ({ forceMobile = true, isDismissible = false, ...props }: AdPlayerProps) => {
return <AdSlides forceMobile={forceMobile} isDismissible={isDismissible} {...props} />
Expand All @@ -118,15 +120,20 @@ interface DesktopCardProps extends AdPlayerProps {
/**
* Renders floating Ad banners on desktop
*/
export const DesktopCard = ({ shouldRender = true, ...props }: DesktopCardProps) => {
export const DesktopCard = ({
shouldRender = true,
isDismissible = true,
forceMobile = false,
...props
}: DesktopCardProps) => {
const portalRoot = getPortalRoot()
const { isDesktop } = useMatchBreakpoints()
const [show] = useShowAdPanel()

return portalRoot && shouldRender && isDesktop && show
? createPortal(
<FloatingContainer>
<AdPlayer {...props} />
<AdPlayer isDismissible={isDismissible} forceMobile={forceMobile} {...props} />
</FloatingContainer>,
portalRoot,
)
Expand All @@ -139,7 +146,12 @@ interface MobileCardProps extends BoxProps, AdPlayerProps {
/**
* Renders Ad banners on mobile and tablet
*/
export const MobileCard = ({ shouldRender = true, isDismissible, forceMobile, ...props }: MobileCardProps) => {
export const MobileCard = ({
shouldRender = true,
isDismissible = true,
forceMobile = false,
...props
}: MobileCardProps) => {
const { isDesktop } = useMatchBreakpoints()
const [show] = useShowAdPanel()

Expand Down
5 changes: 5 additions & 0 deletions apps/web/src/components/AdPanel/useShowAdPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ import { atom, useAtom } from 'jotai'

const showAdPanelAtom = atom<boolean>(true)

/**
* Hook to show/hide the AdPanel rendered by DesktopCard and MobileCard.
* This DOES NOT affect the visibility of cards rendered directly in the page
* via the AdPlayer component.
*/
export const useShowAdPanel = () => useAtom(showAdPanelAtom)

0 comments on commit ee653e2

Please sign in to comment.