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

34 lines
764 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';
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;
if (! shortUrlsList) {
return '<li><i>Loading...</i></li>';
}
return shortUrlsList.map(shortUrl => (
<li key={shortUrl.shortCode}>{`${shortUrl.shortCode}`}</li>
));
}
}
export default connect(state => ({
shortUrlsList: state.shortUrlsList
}), { listShortUrls })(ShortUrlsList);