shlink-web-client/src/short-urls/ShortUrlsList.js

35 lines
802 B
JavaScript
Raw Normal View History

2018-06-15 22:49:25 +03:00
import React from 'react';
import { connect } from 'react-redux';
import { listShortUrls } from './reducers/shortUrlsList';
2018-06-15 22:51:50 +03:00
import { isEmpty } from 'ramda';
2018-06-15 22:49:25 +03:00
export class ShortUrlsList extends React.Component {
componentDidMount() {
const { match } = this.props;
this.props.listShortUrls(match.params.serverId);
}
render() {
return (
<ul>
{this.renderShortUrls()}
</ul>
);
}
renderShortUrls() {
const { shortUrlsList } = this.props;
2018-06-15 22:51:50 +03:00
if (isEmpty(shortUrlsList)) {
return <li><i>Loading...</i></li>;
2018-06-15 22:49:25 +03:00
}
return shortUrlsList.map(shortUrl => (
<li key={shortUrl.shortCode}>{`${shortUrl.shortCode}`}</li>
));
}
}
export default connect(state => ({
shortUrlsList: state.shortUrlsList
}), { listShortUrls })(ShortUrlsList);