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,
};
export default function ShortUrlVisitsHeader({ shortUrlDetail, shortUrlVisits, goBack }) {
const ShortUrlVisitsHeader = ({ shortUrlDetail, shortUrlVisits, goBack }) => {
const { shortUrl, loading } = shortUrlDetail;
const { visits } = shortUrlVisits;
const shortLink = shortUrl && shortUrl.shortUrl ? shortUrl.shortUrl : '';
@ -47,6 +47,8 @@ export default function ShortUrlVisitsHeader({ shortUrlDetail, shortUrlVisits, g
</div>
</VisitsHeader>
);
}
};
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 { bindToMercureTopic } from '../mercure/helpers';
import { TagVisitsType } from './reducers/tagVisits';
import TagVisitsHeader from './TagVisitsHeader';
const propTypes = {
history: PropTypes.shape({
@ -37,8 +38,6 @@ const TagVisits = (VisitsStats) => {
const { tag } = params;
const loadVisits = (dates) => getTagVisits(tag, dates);
console.log(history);
useEffect(
bindToMercureTopic(
mercureInfo,
@ -52,7 +51,7 @@ const TagVisits = (VisitsStats) => {
return (
<VisitsStats getVisits={loadVisits} cancelGetVisits={cancelGetTagVisits} visitsInfo={tagVisits}>
<span>{tag} - {tagVisits.visits.length}</span>
<TagVisitsHeader tagVisits={tagVisits} goBack={history.goBack} />
</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 }) => (
<header>
<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}>
<FontAwesomeIcon icon={faArrowLeft} />
</Button>
<span className="text-center d-none d-sm-block">
{title}
<small>{title}</small>
</span>
<span className="badge badge-main ml-3">
Visits:{' '}
<ShortUrlVisitsCount visitsCount={visits.length} shortUrl={shortUrl} />
</span>
</h2>
<h3 className="text-center d-block d-sm-none mb-0">{title}</h3>
{children}
<h3 className="text-center d-block d-sm-none mb-0 mt-2">
<small>{title}</small>
</h3>
{children && <div className="mt-md-2">{children}</div>}
</Card>
</header>
);