import React from 'react';
import Moment from 'react-moment';
import { connect } from 'react-redux';
import Tag from '../utils/Tag';
import { listShortUrls } from './reducers/shortUrlsList';
import { isEmpty } from 'ramda';
export class ShortUrlsList extends React.Component {
componentDidMount() {
const { match } = this.props;
this.props.listShortUrls(match.params.serverId, { page: match.params.page });
}
render() {
return (
Created at |
Short URL |
Original URL |
Tags |
Visits |
- |
{this.renderShortUrls()}
);
}
renderShortUrls() {
const { shortUrlsList, selectedServer } = this.props;
if (isEmpty(shortUrlsList)) {
return Loading...;
}
return shortUrlsList.map(shortUrl => (
{shortUrl.dateCreated} |
{`${selectedServer.url}/${shortUrl.shortCode}`}
|
{shortUrl.originalUrl}
|
{ShortUrlsList.renderTags(shortUrl.tags)} |
{shortUrl.visitsCount} |
|
));
}
static renderTags(tags) {
if (isEmpty(tags)) {
return No tags;
}
return tags.map(tag => );
}
}
export default connect(state => ({
shortUrlsList: state.shortUrlsList,
selectedServer: state.selectedServer,
}), { listShortUrls })(ShortUrlsList);