Skip to content

Commit

Permalink
part 16
Browse files Browse the repository at this point in the history
  • Loading branch information
rwieruch committed Sep 1, 2017
1 parent 2f70cec commit 4a91d84
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/components/SearchStories.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ class SearchStories extends Component {

@action
onSubmit(event) {
const { storyStore } = this.props;

if (this.query) {
fetchStories(this.query)
.then(result => this.props.storyStore.setStories(result.hits))
.then(result => storyStore.setStories(result.hits))
.catch(storyStore.setError);

this.query = '';
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const Stories = ({ storyStore }) =>
<div className="stories">
<StoriesHeader columns={COLUMNS} />

{ storyStore.error && <p className="error">Something went wrong ...</p> }

{(storyStore.readableStories || []).map(story =>
<Story
key={story.objectID}
Expand Down
10 changes: 9 additions & 1 deletion src/stores/storyStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ const isNotArchived = (archivedStoryIds) => (story) =>

class StoryStore {
@observable stories = [];
@observable error = null;

constructor(rootStore) {
this.rootStore = rootStore;
}

@action setStories = stories =>
@action setStories = stories => {
this.stories = stories;
this.error = null;
}

@action setError = error => {
this.stories = [];
this.error = error;
}

@computed get readableStories() {
const { archivedStoryIds } = this.rootStore.archiveStore;
Expand Down

0 comments on commit 4a91d84

Please sign in to comment.