diff --git a/src/App.js b/src/App.js
index b33bde0..1b1a378 100644
--- a/src/App.js
+++ b/src/App.js
@@ -18,17 +18,21 @@ export default class App extends Component {
apiKey = process.env.REACT_APP_NEWS_API_KEY
- state = {progress: 0}
+ state = {progress: 0, searchText: ''}
setProgress = (progress) => {
this.setState({progress: progress})
}
+ setSearchText = (searchText) => {
+ this.setState({searchText: searchText})
+ }
+
render() {
return (
-
+
}>
}>
}>
+ }>
diff --git a/src/components/NavBar.js b/src/components/NavBar.js
index 99a3cf4..e65c2d8 100644
--- a/src/components/NavBar.js
+++ b/src/components/NavBar.js
@@ -3,6 +3,11 @@ import {Link} from 'react-router-dom'
export class NavBar extends Component {
+ constructor(props) {
+ super(props) ;
+ this.textInput = React.createRef() ;
+ }
+
render() {
return (
@@ -24,6 +29,12 @@ export class NavBar extends Component {
Sports
Technology
+
diff --git a/src/components/News.js b/src/components/News.js
index f0a1c86..7732acd 100644
--- a/src/components/News.js
+++ b/src/components/News.js
@@ -50,12 +50,20 @@ export class News extends Component {
this.fetchNewsData(this.state.page - 1);
};
- async fetchNewsData(page) {
- this.props.setProgress(10) ;
+ getNewsAPIUrl(page) {
let todayDate = this.getCurrentDate();
- const url =
- `https://newsapi.org/v2/top-headlines?country=${this.props.country}&category=${this.props.category}&from=${todayDate}&sortBy=publishedAt&apiKey=${this.props.apiKey}&pageSize=${this.props.pageSize}&page=` +
- page;
+ console.log(this.props.searchText)
+ let url =
+ `https://newsapi.org/v2/top-headlines?country=${this.props.country}&category=${this.props.category}&from=${todayDate}&sortBy=publishedAt&apiKey=${this.props.apiKey}&pageSize=${this.props.pageSize}&page=` + page;
+ if (this.props.searchText) {
+ url = url + `&q=${this.props.searchText}`
+ }
+ return url;
+ }
+
+ async fetchNewsData() {
+ this.props.setProgress(10) ;
+ let url = this.getNewsAPIUrl(this.state.page);
console.log(url);
this.setState({ loading: true });
let data = await fetch(url);