import React from 'react'; import { CopyToClipboard } from 'react-copy-to-clipboard'; import Moment from 'react-moment'; import { connect } from 'react-redux'; import { ButtonDropdown, DropdownItem, DropdownMenu, DropdownToggle } from 'reactstrap'; import { isEmpty } from 'ramda'; import caretUpIcon from '@fortawesome/fontawesome-free-solid/faCaretUp'; import caretDownIcon from '@fortawesome/fontawesome-free-solid/faCaretDown'; import pieChartIcon from '@fortawesome/fontawesome-free-solid/faChartPie'; import pictureIcon from '@fortawesome/fontawesome-free-regular/faImage'; import qrIcon from '@fortawesome/fontawesome-free-solid/faQrcode'; import copyIcon from '@fortawesome/fontawesome-free-regular/faCopy'; import menuIcon from '@fortawesome/fontawesome-free-solid/faEllipsisV'; import FontAwesomeIcon from '@fortawesome/react-fontawesome'; import Tag from '../utils/Tag'; import PreviewModal from './helpers/PreviewModal'; import QrCodeModal from './helpers/QrCodeModal'; import { listShortUrls } from './reducers/shortUrlsList'; import './ShortUrlsList.scss'; export class ShortUrlsList extends React.Component { refreshList = extraParams => { const { listShortUrls, shortUrlsListParams, match: { params } } = this.props; listShortUrls(params.serverId, { ...shortUrlsListParams, ...extraParams }); }; constructor(props) { super(props); const orderBy = props.shortUrlsListParams.orderBy; this.state = { orderField: orderBy ? Object.keys(orderBy)[0] : 'dateCreated', orderDir: orderBy ? Object.values(orderBy)[0] : 'ASC', } } componentDidMount() { const { match: { params } } = this.props; this.refreshList({ page: params.page }); } render() { const orderBy = field => { const newOrderDir = this.state.orderField !== field ? 'ASC' : (this.state.orderDir === 'DESC' ? 'ASC' : 'DESC'); this.setState({ orderField: field, orderDir: newOrderDir }); this.refreshList({ orderBy: { [field]: newOrderDir } }) }; const renderOrderIcon = field => { if (this.state.orderField !== field) { return null; } return ( ); }; return ( {this.renderShortUrls()}
orderBy('dateCreated')} > {renderOrderIcon('dateCreated')} Created at orderBy('shortCode')} > {renderOrderIcon('shortCode')} Short URL orderBy('originalUrl')} > {renderOrderIcon('originalUrl')} Original URL Tags orderBy('visits')} > {renderOrderIcon('visits')} Visits  
); } renderShortUrls() { const { shortUrlsList, selectedServer, loading, error } = this.props; if (error) { return Something went wrong while loading short URLs :(; } if (loading) { return Loading...; } if (! loading && isEmpty(shortUrlsList)) { return No results found; } return shortUrlsList.map(shortUrl => ( )); } static renderTags(tags) { if (isEmpty(tags)) { return No tags; } return tags.map(tag => ); } } class Row extends React.Component { state = { displayMenu: false, copiedToClipboard: false }; render() { const { shortUrl, selectedServer } = this.props; const completeShortUrl = !selectedServer ? shortUrl.shortCode : `${selectedServer.url}/${shortUrl.shortCode}`; return ( this.setState({ displayMenu: true })} onMouseLeave={() => this.setState({ displayMenu: false })} > {shortUrl.dateCreated} {completeShortUrl} {shortUrl.originalUrl} {ShortUrlsList.renderTags(shortUrl.tags)} {shortUrl.visitsCount} { this.setState({ copiedToClipboard: true }); setTimeout(() => this.setState({ copiedToClipboard: false }), 2000); }} /> ) } } class RowMenu extends React.Component { state = { isOpen: false, isQrModalOpen: false, isPreviewOpen: false }; toggle = () => this.setState({ isOpen: ! this.state.isOpen }); render () { const { display, shortUrl, onCopyToClipboard } = this.props; const baseClass = 'short-urls-list__dropdown-toggle'; const toggleClass = ! display ? `${baseClass} short-urls-list__dropdown-toggle--hidden` : baseClass; const toggleQrCode = () => this.setState({ isQrModalOpen: !this.state.isQrModalOpen }); const togglePreview = () => this.setState({ isPreviewOpen: !this.state.isPreviewOpen }); return (     Visit Stats  Preview  QR code  Copy to clipboard ); } } export default connect(state => ({ selectedServer: state.selectedServer, shortUrlsListParams: state.shortUrlsListParams, }), { listShortUrls })(ShortUrlsList);