import { isEmpty } from 'ramda'; import { FC, useEffect, useRef } from 'react'; import Moment from 'react-moment'; import { ExternalLink } from 'react-external-link'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faCopy as copyIcon } from '@fortawesome/free-regular-svg-icons'; import CopyToClipboard from 'react-copy-to-clipboard'; import ColorGenerator from '../../utils/services/ColorGenerator'; import { StateFlagTimeout } from '../../utils/helpers/hooks'; import Tag from '../../tags/helpers/Tag'; import { SelectedServer } from '../../servers/data'; import { ShortUrl } from '../data'; import ShortUrlVisitsCount from './ShortUrlVisitsCount'; import { ShortUrlsRowMenuProps } from './ShortUrlsRowMenu'; import './ShortUrlsRow.scss'; export interface ShortUrlsRowProps { onTagClick?: (tag: string) => void; selectedServer: SelectedServer; shortUrl: ShortUrl; } const ShortUrlsRow = ( ShortUrlsRowMenu: FC, colorGenerator: ColorGenerator, useStateFlagTimeout: StateFlagTimeout, ) => ({ shortUrl, selectedServer, onTagClick }: ShortUrlsRowProps) => { const [ copiedToClipboard, setCopiedToClipboard ] = useStateFlagTimeout(); const [ active, setActive ] = useStateFlagTimeout(false, 500); const isFirstRun = useRef(true); const renderTags = (tags: string[]) => { if (isEmpty(tags)) { return No tags; } return tags.map((tag) => ( onTagClick?.(tag)} /> )); }; useEffect(() => { if (isFirstRun.current) { isFirstRun.current = false; } else { setActive(); } }, [ shortUrl.visitsCount ]); return ( {shortUrl.dateCreated} {renderTags(shortUrl.tags)} ); }; export default ShortUrlsRow;