1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00

fix: Display message if there are no items on search

This commit is contained in:
Juan Picado @jotadeveloper 2017-07-22 19:32:32 +02:00
parent 19490ffc51
commit 3a187945dc
No known key found for this signature in database
GPG Key ID: 18AC54485952D158
4 changed files with 44 additions and 4 deletions

@ -0,0 +1,18 @@
import React from 'react';
import PropTypes from 'prop-types';
import classes from './noItems.scss';
const NoItems = (props) => {
return (
<div className={classes.noItems}>
<h2>{props.text}</h2>
</div>
);
};
NoItems.propTypes = {
text: PropTypes.string.isRequired
};
export default NoItems;

@ -0,0 +1,3 @@
.noItems {
margin: 5em 0;
}

@ -4,13 +4,15 @@ import isEmpty from 'lodash/isEmpty';
import Package from '../Package'; import Package from '../Package';
import Help from '../Help'; import Help from '../Help';
import NoItems from '../NoItems';
import classes from './packageList.scss'; import classes from './packageList.scss';
export default class PackageList extends React.Component { export default class PackageList extends React.Component {
static propTypes = { static propTypes = {
packages: PropTypes.array packages: PropTypes.array,
help: PropTypes.bool
} }
render() { render() {
@ -18,7 +20,7 @@ export default class PackageList extends React.Component {
<div> <div>
<div className={classes.pkgContainer}> <div className={classes.pkgContainer}>
{this.renderTitle()} {this.renderTitle()}
{this.isTherePackages() ? this.renderList(): this.renderHelp()} {this.isTherePackages() ? this.renderList(): this.renderOptions()}
</div> </div>
</div> </div>
); );
@ -38,7 +40,22 @@ export default class PackageList extends React.Component {
)); ));
} }
renderOptions() {
if (this.isTherePackages() === false && this.props.help) {
return this.renderHelp();
} else {
return this.renderNoItems();
}
}
renderNoItems() {
return <NoItems text={'No items were found with that query'}/>;
}
renderHelp() { renderHelp() {
if (this.props.help === false) {
return;
}
return <Help/>; return <Help/>;
} }

@ -19,6 +19,7 @@ export default class Home extends React.Component {
state = { state = {
loading: true, loading: true,
fistTime: true,
query: '' query: ''
} }
@ -74,6 +75,7 @@ export default class Home extends React.Component {
if (this.state.query === query) { if (this.state.query === query) {
this.setState({ this.setState({
packages: this.req.data, packages: this.req.data,
fistTime: false,
loading: false loading: false
}); });
} }
@ -106,7 +108,7 @@ export default class Home extends React.Component {
} }
renderSearchBar() { renderSearchBar() {
if (this.isTherePackages()) { if (this.isTherePackages() && this.state.fistTime) {
return; return;
} }
return <Search handleSearchInput={ this.handleSearchInput } />; return <Search handleSearchInput={ this.handleSearchInput } />;
@ -117,7 +119,7 @@ export default class Home extends React.Component {
} }
renderPackageList() { renderPackageList() {
return <PackageList packages={this.state.packages} />; return <PackageList help={this.state.fistTime} packages={this.state.packages} />;
} }
} }