Skip to content

Commit a326058

Browse files
committed
Loading ...
1 parent 9e2bdce commit a326058

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/App.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class App extends Component {
3232
searchKey: '',
3333
searchTerm: DEFAULT_QUERY,
3434
error: null,
35+
isLoading: false,
3536
};
3637

3738
this.needsToSearchTopStories = this.needsToSearchTopStories.bind(this);
@@ -63,11 +64,14 @@ class App extends Component {
6364
results: {
6465
...results,
6566
[searchKey]: { hits: updatedHits, page }
66-
}
67+
},
68+
isLoading: false
6769
});
6870
}
6971

7072
fetchSearchTopStories(searchTerm, page = 0) {
73+
this.setState({ isLoading: true });
74+
7175
axios(`${PATH_BASE}${PATH_SEARCH}?${PARAM_SEARCH}${searchTerm}&${PARAM_PAGE}${page}&${PARAM_HPP}${DEFAULT_HPP}`)
7276
.then(result => this.setSearchTopStories(result.data))
7377
.catch(error => this.setState({ error }));
@@ -114,7 +118,8 @@ class App extends Component {
114118
searchTerm,
115119
results,
116120
searchKey,
117-
error
121+
error,
122+
isLoading
118123
} = this.state;
119124

120125
const page = (
@@ -150,9 +155,14 @@ class App extends Component {
150155
/>
151156
}
152157
<div className="interactions">
153-
<Button onClick={() => this.fetchSearchTopStories(searchKey, page + 1)}>
154-
More
155-
</Button>
158+
{ isLoading
159+
? <Loading />
160+
: <Button
161+
onClick={() => this.fetchSearchTopStories(searchKey, page + 1)}
162+
>
163+
More
164+
</Button>
165+
}
156166
</div>
157167
</div>
158168
);
@@ -218,6 +228,9 @@ const Button = ({
218228
{children}
219229
</button>
220230

231+
const Loading = () =>
232+
<div>Loading ...</div>
233+
221234
export default App;
222235

223236
export {

0 commit comments

Comments
 (0)