2020-11-14 00:44:26 +03:00
|
|
|
import { FC, useEffect, useState } from 'react';
|
2020-12-12 12:56:10 +03:00
|
|
|
import { Card } from 'reactstrap';
|
2020-08-30 20:45:17 +03:00
|
|
|
import Paginator from './Paginator';
|
2020-12-07 13:17:19 +03:00
|
|
|
import { ShortUrlsListProps } from './ShortUrlsList';
|
2020-08-30 20:45:17 +03:00
|
|
|
|
2020-12-07 13:17:19 +03:00
|
|
|
const ShortUrls = (SearchBar: FC, ShortUrlsList: FC<ShortUrlsListProps>) => (props: ShortUrlsListProps) => {
|
2020-08-30 20:45:17 +03:00
|
|
|
const { match, shortUrlsList } = props;
|
|
|
|
const { page = '1', serverId = '' } = match?.params ?? {};
|
2020-12-07 13:17:19 +03:00
|
|
|
const { pagination } = shortUrlsList?.shortUrls ?? {};
|
2020-08-30 20:45:17 +03:00
|
|
|
const [ urlsListKey, setUrlsListKey ] = useState(`${serverId}_${page}`);
|
|
|
|
|
|
|
|
// Using a key on a component makes react to create a new instance every time the key changes
|
|
|
|
// Without it, pagination on the URL will not make the component to be refreshed
|
|
|
|
useEffect(() => {
|
|
|
|
setUrlsListKey(`${serverId}_${page}`);
|
|
|
|
}, [ serverId, page ]);
|
|
|
|
|
|
|
|
return (
|
2020-11-14 00:44:26 +03:00
|
|
|
<>
|
2020-08-30 20:45:17 +03:00
|
|
|
<div className="form-group"><SearchBar /></div>
|
2020-12-12 12:56:10 +03:00
|
|
|
<Card body className="pb-1">
|
2020-12-07 13:17:19 +03:00
|
|
|
<ShortUrlsList {...props} key={urlsListKey} />
|
2020-08-30 20:45:17 +03:00
|
|
|
<Paginator paginator={pagination} serverId={serverId} />
|
2020-12-12 12:56:10 +03:00
|
|
|
</Card>
|
2020-11-14 00:44:26 +03:00
|
|
|
</>
|
2020-08-30 20:45:17 +03:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ShortUrls;
|