2020-03-08 12:16:45 +03:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2019-01-06 00:54:54 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2018-06-17 19:13:55 +03:00
|
|
|
import Paginator from './Paginator';
|
2018-06-17 11:59:04 +03:00
|
|
|
|
2019-01-06 00:54:54 +03:00
|
|
|
const ShortUrls = (SearchBar, ShortUrlsList) => {
|
|
|
|
const propTypes = {
|
|
|
|
match: PropTypes.shape({
|
|
|
|
params: PropTypes.object,
|
|
|
|
}),
|
|
|
|
shortUrlsList: PropTypes.object,
|
|
|
|
};
|
2018-08-26 00:39:27 +03:00
|
|
|
|
2019-01-06 00:54:54 +03:00
|
|
|
const ShortUrlsComponent = (props) => {
|
|
|
|
const { match: { params }, shortUrlsList } = props;
|
|
|
|
const { page, serverId } = params;
|
|
|
|
const { data = [], pagination } = shortUrlsList;
|
2020-03-08 12:16:45 +03:00
|
|
|
const [ urlsListKey, setUrlsListKey ] = useState(`${serverId}_${page}`);
|
2018-07-18 20:01:43 +03:00
|
|
|
|
2019-01-06 00:54:54 +03:00
|
|
|
// Using a key on a component makes react to create a new instance every time the key changes
|
2020-03-08 12:16:45 +03:00
|
|
|
// Without it, pagination on the URL will not make the component to be refreshed
|
|
|
|
useEffect(() => {
|
|
|
|
setUrlsListKey(`${serverId}_${page}`);
|
|
|
|
}, [ serverId, page ]);
|
2019-01-06 00:54:54 +03:00
|
|
|
|
|
|
|
return (
|
2020-03-05 13:11:26 +03:00
|
|
|
<React.Fragment>
|
2019-01-06 00:54:54 +03:00
|
|
|
<div className="form-group"><SearchBar /></div>
|
2020-04-10 14:42:16 +03:00
|
|
|
<div>
|
|
|
|
<ShortUrlsList {...props} shortUrlsList={data} key={urlsListKey} />
|
|
|
|
<Paginator paginator={pagination} serverId={serverId} />
|
|
|
|
</div>
|
2020-03-05 13:11:26 +03:00
|
|
|
</React.Fragment>
|
2019-01-06 00:54:54 +03:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ShortUrlsComponent.propTypes = propTypes;
|
|
|
|
|
|
|
|
return ShortUrlsComponent;
|
2018-12-18 00:18:47 +03:00
|
|
|
};
|
2018-08-26 00:39:27 +03:00
|
|
|
|
|
|
|
export default ShortUrls;
|