import { isEmpty } from 'ramda'; import React, { 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 { ShortUrlsListParams } from '../reducers/shortUrlsListParams'; 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 { refreshList: Function; shortUrlsListParams: ShortUrlsListParams; selectedServer: SelectedServer; shortUrl: ShortUrl; } const ShortUrlsRow = ( ShortUrlsRowMenu: FC, colorGenerator: ColorGenerator, useStateFlagTimeout: StateFlagTimeout, ) => ({ shortUrl, selectedServer, refreshList, shortUrlsListParams }: 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; } const selectedTags = shortUrlsListParams.tags ?? []; return tags.map((tag) => ( refreshList({ tags: [ ...selectedTags, tag ] })} /> )); }; useEffect(() => { if (isFirstRun.current) { isFirstRun.current = false; } else { setActive(); } }, [ shortUrl.visitsCount ]); return ( {shortUrl.dateCreated} {renderTags(shortUrl.tags)} ); }; export default ShortUrlsRow;