Skip to content

Commit

Permalink
update search history strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
trazyn committed Aug 11, 2017
1 parent da95c97 commit 8a6b71e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
19 changes: 16 additions & 3 deletions src/js/pages/Home/SearchBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@ import { inject, observer } from 'mobx-react';
import classes from './style.css';

@inject(stores => ({
history: stores.search.history,
searching: stores.search.searching,
toggle: stores.search.toggle,
filter: stores.search.filter,
result: stores.search.result,
getHistory: () => {
var history = [];

stores.search.history.map(e => {
var user = stores.contacts.memberList.find(user => user.UserName === e);

if (user) {
history.push(user);
}
});
return history;
},
getPlaceholder: () => {
stores.contacts.filter();
return stores.contacts.filtered.result;
Expand Down Expand Up @@ -81,7 +92,8 @@ export default class SearchBar extends Component {
}

navigation(e) {
var { result, history, getPlaceholder } = this.props;
var { result, getHistory, getPlaceholder } = this.props;
var history = getHistory();

if (![
38, // Up
Expand Down Expand Up @@ -181,7 +193,8 @@ export default class SearchBar extends Component {
}

render() {
var { searching, history, result } = this.props;
var { searching, getHistory, result } = this.props;
var history = getHistory();

return (
<div className={classes.container}>
Expand Down
1 change: 0 additions & 1 deletion src/js/pages/Home/SearchBar/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
justify-content: flex-start;
align-items: center;
cursor: pointer;
transition: .2s ease-in-out;

& img {
height: 32px;
Expand Down
7 changes: 6 additions & 1 deletion src/js/stores/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,19 @@ class Search {
}

@action async addHistory(user) {
var history = [user, ...self.history.filter(e => e.UserName !== user.UserName)];
var history = [user.UserName, ...self.history.filter(e => e !== user.UserName)];

await storage.set('history', history);
self.history.replace(history);

return history;
}

@action async updateHistory(history) {
await storage.set('history', history);
self.history.replace(history);
}

@action reset() {
self.result = {
query: '',
Expand Down

0 comments on commit 8a6b71e

Please sign in to comment.