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 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 { listShortUrls } from './reducers/shortUrlsList';
import './ShortUrlsList.scss';
export class ShortUrlsList extends React.Component {
componentDidMount() {
const { match: { params } } = this.props;
this.props.listShortUrls(params.serverId, {
...this.props.shortUrlsListParams,
page: params.page
});
}
render() {
return (
Created at |
Short URL |
Original URL |
Tags |
Visits |
|
{this.renderShortUrls()}
);
}
renderShortUrls() {
const { shortUrlsList, selectedServer, loading } = this.props;
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}
Copied short URL!
|
{ShortUrlsList.renderTags(shortUrl.tags)} |
{shortUrl.visitsCount} |
{
this.setState({ copiedToClipboard: true });
setTimeout(() => this.setState({ copiedToClipboard: false }), 2000);
}}
/>
|
)
}
}
class RowMenu extends React.Component {
state = { isOpen: 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;
return (
Visit Stats
Preview
QR code
Copy to clipboard
);
}
}
export default connect(state => ({
selectedServer: state.selectedServer,
shortUrlsListParams: state.shortUrlsListParams,
}), { listShortUrls })(ShortUrlsList);