diff --git a/src/components/SearchStories.js b/src/components/SearchStories.js index 2f14850..24c20de 100644 --- a/src/components/SearchStories.js +++ b/src/components/SearchStories.js @@ -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 = ''; } diff --git a/src/components/Stories.js b/src/components/Stories.js index 639cbf6..3d5fe6d 100644 --- a/src/components/Stories.js +++ b/src/components/Stories.js @@ -29,6 +29,8 @@ const Stories = ({ storyStore }) =>
+ { storyStore.error &&

Something went wrong ...

} + {(storyStore.readableStories || []).map(story => (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;