Created header for visits by tag section

This commit is contained in:
Alejandro Celaya 2020-05-10 19:49:58 +02:00
parent 7a94b1730d
commit fb0f14fc16
4 changed files with 39 additions and 9 deletions

View file

@ -14,7 +14,7 @@ const propTypes = {
goBack: PropTypes.func.isRequired, goBack: PropTypes.func.isRequired,
}; };
export default function ShortUrlVisitsHeader({ shortUrlDetail, shortUrlVisits, goBack }) { const ShortUrlVisitsHeader = ({ shortUrlDetail, shortUrlVisits, goBack }) => {
const { shortUrl, loading } = shortUrlDetail; const { shortUrl, loading } = shortUrlDetail;
const { visits } = shortUrlVisits; const { visits } = shortUrlVisits;
const shortLink = shortUrl && shortUrl.shortUrl ? shortUrl.shortUrl : ''; const shortLink = shortUrl && shortUrl.shortUrl ? shortUrl.shortUrl : '';
@ -47,6 +47,8 @@ export default function ShortUrlVisitsHeader({ shortUrlDetail, shortUrlVisits, g
</div> </div>
</VisitsHeader> </VisitsHeader>
); );
} };
ShortUrlVisitsHeader.propTypes = propTypes; ShortUrlVisitsHeader.propTypes = propTypes;
export default ShortUrlVisitsHeader;

View file

@ -4,6 +4,7 @@ import { MercureInfoType } from '../mercure/reducers/mercureInfo';
import { SettingsType } from '../settings/reducers/settings'; import { SettingsType } from '../settings/reducers/settings';
import { bindToMercureTopic } from '../mercure/helpers'; import { bindToMercureTopic } from '../mercure/helpers';
import { TagVisitsType } from './reducers/tagVisits'; import { TagVisitsType } from './reducers/tagVisits';
import TagVisitsHeader from './TagVisitsHeader';
const propTypes = { const propTypes = {
history: PropTypes.shape({ history: PropTypes.shape({
@ -37,8 +38,6 @@ const TagVisits = (VisitsStats) => {
const { tag } = params; const { tag } = params;
const loadVisits = (dates) => getTagVisits(tag, dates); const loadVisits = (dates) => getTagVisits(tag, dates);
console.log(history);
useEffect( useEffect(
bindToMercureTopic( bindToMercureTopic(
mercureInfo, mercureInfo,
@ -52,7 +51,7 @@ const TagVisits = (VisitsStats) => {
return ( return (
<VisitsStats getVisits={loadVisits} cancelGetVisits={cancelGetTagVisits} visitsInfo={tagVisits}> <VisitsStats getVisits={loadVisits} cancelGetVisits={cancelGetTagVisits} visitsInfo={tagVisits}>
<span>{tag} - {tagVisits.visits.length}</span> <TagVisitsHeader tagVisits={tagVisits} goBack={history.goBack} />
</VisitsStats> </VisitsStats>
); );
}; };

View file

@ -0,0 +1,26 @@
import React from 'react';
import PropTypes from 'prop-types';
import VisitsHeader from './VisitsHeader';
import { TagVisitsType } from './reducers/tagVisits';
import './ShortUrlVisitsHeader.scss';
const propTypes = {
tagVisits: TagVisitsType.isRequired,
goBack: PropTypes.func.isRequired,
};
const TagVisitsHeader = ({ tagVisits, goBack }) => {
const { visits, tag } = tagVisits;
const visitsStatsTitle = (
<React.Fragment>
Visits for {tag}
</React.Fragment>
);
return <VisitsHeader title={visitsStatsTitle} goBack={goBack} visits={visits} />;
};
TagVisitsHeader.propTypes = propTypes;
export default TagVisitsHeader;

View file

@ -18,20 +18,23 @@ const propTypes = {
const VisitsHeader = ({ visits, goBack, shortUrl, children, title }) => ( const VisitsHeader = ({ visits, goBack, shortUrl, children, title }) => (
<header> <header>
<Card className="bg-light" body> <Card className="bg-light" body>
<h2 className="d-flex justify-content-between align-items-center"> <h2 className="d-flex justify-content-between align-items-center mb-0">
<Button color="link" size="lg" className="p-0 mr-3" onClick={goBack}> <Button color="link" size="lg" className="p-0 mr-3" onClick={goBack}>
<FontAwesomeIcon icon={faArrowLeft} /> <FontAwesomeIcon icon={faArrowLeft} />
</Button> </Button>
<span className="text-center d-none d-sm-block"> <span className="text-center d-none d-sm-block">
{title} <small>{title}</small>
</span> </span>
<span className="badge badge-main ml-3"> <span className="badge badge-main ml-3">
Visits:{' '} Visits:{' '}
<ShortUrlVisitsCount visitsCount={visits.length} shortUrl={shortUrl} /> <ShortUrlVisitsCount visitsCount={visits.length} shortUrl={shortUrl} />
</span> </span>
</h2> </h2>
<h3 className="text-center d-block d-sm-none mb-0">{title}</h3> <h3 className="text-center d-block d-sm-none mb-0 mt-2">
{children} <small>{title}</small>
</h3>
{children && <div className="mt-md-2">{children}</div>}
</Card> </Card>
</header> </header>
); );