Skip to content

Commit

Permalink
Improve directory site (#583)
Browse files Browse the repository at this point in the history
* searching when user stops typeing

* hide horizontal scrollbar and alway show vertical scrollbar

* response  message 'not found'
  • Loading branch information
0xchimz authored and oblador committed Jan 8, 2018
1 parent bd4d7a9 commit 66bb0e0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
37 changes: 35 additions & 2 deletions directory/src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';

import './App.css';

import Entypo from '../../glyphmaps/Entypo.json';
import EvilIcons from '../../glyphmaps/EvilIcons.json';
import Feather from '../../glyphmaps/Feather.json';
Expand All @@ -9,8 +11,8 @@ import Foundation from '../../glyphmaps/Foundation.json';
import Ionicons from '../../glyphmaps/Ionicons.json';
import MaterialCommunityIcons from '../../glyphmaps/MaterialCommunityIcons.json';
import MaterialIcons from '../../glyphmaps/MaterialIcons.json';
import SimpleLineIcons from '../../glyphmaps/SimpleLineIcons.json';
import Octicons from '../../glyphmaps/Octicons.json';
import SimpleLineIcons from '../../glyphmaps/SimpleLineIcons.json';
import Zocial from '../../glyphmaps/Zocial.json';

const IconFamilies = {
Expand All @@ -27,6 +29,8 @@ const IconFamilies = {
Zocial,
};

const WAITING_INTERVAL = 300;

class Icon extends PureComponent {
static propTypes = {
family: PropTypes.string.isRequired,
Expand Down Expand Up @@ -55,11 +59,29 @@ const HeaderBar = (props) => {
};

class SearchBar extends PureComponent {
timer = null;

state = {
keyword: ''
};

handleSubmit = (e) => {
e.preventDefault();
this.props.onSubmit(this.inputRef.value);
};

handleChange = (e) => {
e.preventDefault();
clearInterval(this.timer);

this.setState({ keyword: this.inputRef.value });

this.timer = setTimeout(
() => this.props.onSubmit(this.state.keyword),
WAITING_INTERVAL
);
};

render() {
return (
<div className="Search-Container">
Expand All @@ -68,9 +90,11 @@ class SearchBar extends PureComponent {
<Icon family="FontAwesome" name="search" className="Search-Icon" />
<input
ref={ref => this.inputRef = ref}
onChange={this.handleChange}
placeholder="Search for an icon"
type="text"
className="Search-Input" />
className="Search-Input"
/>
</form>
</div>
</div>
Expand Down Expand Up @@ -142,13 +166,22 @@ class App extends PureComponent {
);
}

renderNotFound () {
return (
<div className="Result-Row">
<h2 className="Result-Title">Icon not found.</h2>
</div>
);
}

render() {
return (
<div className="App">
<HeaderBar />
<SearchBar onSubmit={this.handleSubmit} />
<div className="Container">
{this.state.matches.map(this.renderMatch)}
{this.state.matches.length === 0 && this.renderNotFound()}
</div>
</div>
);
Expand Down
2 changes: 2 additions & 0 deletions directory/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ body {
margin: 0;
padding: 0;
font-family: sans-serif;
overflow-x: hidden;
overflow-y: scroll;
}

0 comments on commit 66bb0e0

Please sign in to comment.