Improved tags list section

This commit is contained in:
Alejandro Celaya 2018-08-16 19:19:57 +02:00
parent 49290b56ee
commit f7f0d8c7c1
5 changed files with 79 additions and 28 deletions

View file

@ -29,6 +29,7 @@ export default function AsideMenu({ selectedServer, className, showOnMobile }) {
return ( return (
<aside className={asideClass}> <aside className={asideClass}>
<nav className="nav flex-column aside-menu__nav"> <nav className="nav flex-column aside-menu__nav">
<h4 className="aside-menu__nav-group-title">Short URLs</h4>
<NavLink <NavLink
className="aside-menu__item" className="aside-menu__item"
activeClassName="aside-menu__item--selected" activeClassName="aside-menu__item--selected"
@ -45,6 +46,8 @@ export default function AsideMenu({ selectedServer, className, showOnMobile }) {
<FontAwesomeIcon icon={createIcon} flip="horizontal" /> <FontAwesomeIcon icon={createIcon} flip="horizontal" />
<span className="aside-menu__item-text">Create short URL</span> <span className="aside-menu__item-text">Create short URL</span>
</NavLink> </NavLink>
<h4 className="aside-menu__nav-group-title">Tags</h4>
<NavLink <NavLink
className="aside-menu__item" className="aside-menu__item"
activeClassName="aside-menu__item--selected" activeClassName="aside-menu__item--selected"

View file

@ -1,5 +1,6 @@
@import '../utils/base'; @import '../utils/base';
@import '../utils/mixins/box-shadow'; @import '../utils/mixins/box-shadow';
@import '../utils/mixins/vertical-align';
$asideMenuMobileWidth: 280px; $asideMenuMobileWidth: 280px;
@ -74,3 +75,22 @@ $asideMenuMobileWidth: 280px;
.aside-menu__item-text { .aside-menu__item-text {
margin-left: 8px; margin-left: 8px;
} }
.aside-menu__nav-group-title {
font-size: .9rem;
text-align: center;
color: #bbb;
text-shadow: 1px 1px #ddd;
position: relative;
&:before {
@include vertical-align();
left: 0;
width: 100%;
height: 1px;
background: red;
}
}
.aside-menu__nav-group-title:not(:first-child) {
margin-top: 1rem;
}

View file

@ -10,15 +10,7 @@ import DateInput from '../common/DateInput'
import VisitsParser from '../visits/services/VisitsParser' import VisitsParser from '../visits/services/VisitsParser'
import { getShortUrlVisits } from './reducers/shortUrlVisits' import { getShortUrlVisits } from './reducers/shortUrlVisits'
import './ShortUrlVisits.scss' import './ShortUrlVisits.scss'
import MutedMessage from '../utils/MuttedMessage';
const MutedMessage = ({ children }) =>
<div className="col-md-10 offset-md-1">
<Card className="bg-light mt-4" body>
<h3 className="text-center text-muted mb-0">
{children}
</h3>
</Card>
</div>;
export class ShortUrlsVisits extends React.Component { export class ShortUrlsVisits extends React.Component {
state = { startDate: undefined, endDate: undefined }; state = { startDate: undefined, endDate: undefined };

View file

@ -5,6 +5,9 @@ import { listTags } from './reducers/tagsList';
import './TagsList.scss'; import './TagsList.scss';
import { Card } from 'reactstrap'; import { Card } from 'reactstrap';
import ColorGenerator from '../utils/ColorGenerator'; import ColorGenerator from '../utils/ColorGenerator';
import MuttedMessage from '../utils/MuttedMessage';
const { round } = Math;
export class TagsList extends React.Component { export class TagsList extends React.Component {
componentDidMount() { componentDidMount() {
@ -12,32 +15,48 @@ export class TagsList extends React.Component {
listTags(); listTags();
} }
render() { renderContent() {
const { tagsList, colorGenerator } = this.props; const { tagsList, colorGenerator } = this.props;
const tagsCount = Math.round(tagsList.tags.length); if (tagsList.loading) {
if (tagsCount < 1) { return <MuttedMessage>Loading...</MuttedMessage>
return <div>No tags</div>;
} }
const tagsGroups = splitEvery(Math.round(tagsCount / 4), tagsList.tags); if (tagsList.error) {
return <div className="bg-danger p-2 text-white text-center">Error loading tags :(</div>;
}
const tagsCount = tagsList.tags.length;
if (tagsCount < 1) {
return <MuttedMessage>No tags found</MuttedMessage>;
}
const tagsGroups = splitEvery(round(tagsCount / 4), tagsList.tags);
return (
<React.Fragment>
{tagsGroups.map((group, index) => (
<div key={index} className="col-md-6 col-xl-3">
{group.map(tag => (
<div
style={{ backgroundColor: colorGenerator.getColorForKey(tag) }}
className="tags-list__tag-container"
key={tag}
>
<Card body className="tags-list__tag-card">
<h5 className="tags-list__tag-title">{tag}</h5>
</Card>
</div>
))}
</div>
))}
</React.Fragment>
);
}
render() {
return ( return (
<div className="shlink-container"> <div className="shlink-container">
<div className="row"> <div className="row">
{tagsGroups.map((group, index) => ( {this.renderContent()}
<div key={index} className="col-md-6 col-xl-3">
{group.map(tag => (
<div
style={{ backgroundColor: colorGenerator.getColorForKey(tag) }}
className="tags-list__tag-container"
>
<Card body className="tags-list__tag-card">
<h5 className="tags-list__tag-title">{tag}</h5>
</Card>
</div>
))}
</div>
))}
</div> </div>
</div> </div>
); );

View file

@ -0,0 +1,17 @@
import React from 'react';
import { Card } from 'reactstrap';
import classnames from 'classnames';
export default function MutedMessage({ children, marginSize = 4 }) {
const cardClasses = classnames('bg-light', `mt-${marginSize}`);
return (
<div className="col-md-10 offset-md-1">
<Card className={cardClasses} body>
<h3 className="text-center text-muted mb-0">
{children}
</h3>
</Card>
</div>
);
}