import React, { useEffect, useState } from 'react'; import { useTheme } from 'styled-components'; import { CommunityLibraryIcon } from '../../icons'; import { getImageSource } from '../../helpers/getImageSource'; import { usePrevious } from '../../hooks'; import FavoriteButton from '../FavoriteButton'; import FavoriteToast from '../FavoriteToast'; import Typography from '../Typography'; import UserAvatar from '../UserAvatar'; import { AssetDataCardProps, AssetDataCardVariant } from './interfaces'; import { Wrapper, Row, Description, AssetPreviewContainer, Column, CommunityLibraryHeader, CommunityLibraryIconWrapper, } from './styles'; import LinkBadge from '../LinkBadge'; const AssetDataCard = ({ title, addedBy, variant, description, link, thumbnailUrl, isFavorite, onFavoriteClick, isCommunityItem, onLinkClick, onProfileLinkClick, showFavorite = true, favoriteCount, }: AssetDataCardProps) => { const theme = useTheme(); const prevIsFavorite = usePrevious(isFavorite); const [showFavoriteToast, setShowFavoriteToast] = useState(false); const isCondensed = variant === AssetDataCardVariant.CONDENSED; useEffect(() => { if (isFavorite && prevIsFavorite === false) { // show favorite toast for 3 seconds setShowFavoriteToast(true); setTimeout(() => { setShowFavoriteToast(false); }, 3000); } }, [isFavorite]); const hasLink = Boolean(link?.length); const hasTitle = Boolean(title?.length); return ( hasLink && onLinkClick?.()} hasLink={hasLink} > {!isCondensed && thumbnailUrl && ( {showFavorite && ( { e.preventDefault(); e.stopPropagation(); onFavoriteClick?.(); }} /> )} )} {isCondensed && showFavorite && ( <> {!hasTitle && !hasLink && ( // placeholder row for favorite indicator because button has an absolute position // only needed if there is no title & no link
)} )} {isCondensed && !showFavorite && isCommunityItem && ( Community Library )} {(hasTitle || hasLink) && ( {hasTitle && ( {title} )} {hasLink && } )} {description && ( {description.content}
onProfileLinkClick?.(description.username)}> @{description.username}
)} Item Added by{' '} onProfileLinkClick?.(addedBy)} > @{addedBy} ); }; export default AssetDataCard;