Skip to content

Commit 4a91d84

Browse files
committed
part 16
1 parent 2f70cec commit 4a91d84

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/components/SearchStories.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ class SearchStories extends Component {
2323

2424
@action
2525
onSubmit(event) {
26+
const { storyStore } = this.props;
27+
2628
if (this.query) {
2729
fetchStories(this.query)
28-
.then(result => this.props.storyStore.setStories(result.hits))
30+
.then(result => storyStore.setStories(result.hits))
31+
.catch(storyStore.setError);
2932

3033
this.query = '';
3134
}

src/components/Stories.js

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const Stories = ({ storyStore }) =>
2929
<div className="stories">
3030
<StoriesHeader columns={COLUMNS} />
3131

32+
{ storyStore.error && <p className="error">Something went wrong ...</p> }
33+
3234
{(storyStore.readableStories || []).map(story =>
3335
<Story
3436
key={story.objectID}

src/stores/storyStore.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@ const isNotArchived = (archivedStoryIds) => (story) =>
55

66
class StoryStore {
77
@observable stories = [];
8+
@observable error = null;
89

910
constructor(rootStore) {
1011
this.rootStore = rootStore;
1112
}
1213

13-
@action setStories = stories =>
14+
@action setStories = stories => {
1415
this.stories = stories;
16+
this.error = null;
17+
}
18+
19+
@action setError = error => {
20+
this.stories = [];
21+
this.error = error;
22+
}
1523

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

0 commit comments

Comments
 (0)