|
@@ -1,7 +1,7 @@
|
|
|
import { FlatList, ScrollView, StyleSheet, Text, TouchableWithoutFeedback, View } from 'react-native'
|
|
|
import React from 'react'
|
|
|
import { navigateToArticle, useConstructor } from '../../constants/functions'
|
|
|
-import { getArticlesByCategory, getTrendingNews } from '../../api/data'
|
|
|
+import { getArticlesByCategory, getArticlesBySearch, getTrendingNews } from '../../api/data'
|
|
|
import LoadingScreen from '../../components/organisms/Sections/LoadingScreen'
|
|
|
import colors from '../../constants/colors'
|
|
|
import OctiIcon from 'react-native-vector-icons/Octicons'
|
|
@@ -33,31 +33,16 @@ const NewsListPage = props => {
|
|
|
setNews(prev => [...prev, ...res.data.body.results.map(item => item.articles[0])])
|
|
|
}).catch(err => console.error(err))
|
|
|
}
|
|
|
+
|
|
|
+ const fetchSearchResults = (text) => {
|
|
|
+ getArticlesBySearch(text).then(res => {
|
|
|
+ setNews(prev => [...prev, ...res.data.body.results])
|
|
|
+ }).catch(err => console.error(err))
|
|
|
+ }
|
|
|
const [headerName, setHeaderName] = React.useState("")
|
|
|
const [news, setNews] = React.useState([])
|
|
|
const [pagesLoaded, setPagesLoaded] = React.useState(0)
|
|
|
|
|
|
- const initializeNews = () => {
|
|
|
-
|
|
|
- if (type === "normal") {
|
|
|
- setHeaderName(title)
|
|
|
- switch (title) {
|
|
|
- case "Trending":
|
|
|
- fetchTrendingNews()
|
|
|
- setPagesLoaded(1)
|
|
|
- break;
|
|
|
- case "Bookmark":
|
|
|
- break
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
- } else if (type === "category") {
|
|
|
- setHeaderName(title)
|
|
|
- fetchNews(title,1)
|
|
|
- setPagesLoaded(1)
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
//FlatList Optimizations
|
|
|
|
|
@@ -76,9 +61,8 @@ const NewsListPage = props => {
|
|
|
|
|
|
const scrollPagination = () => {
|
|
|
|
|
|
-
|
|
|
+ setHeaderName(title)
|
|
|
if (type === "normal") {
|
|
|
- setHeaderName(title)
|
|
|
switch (title) {
|
|
|
case "Trending":
|
|
|
fetchTrendingNews()
|
|
@@ -89,9 +73,11 @@ const NewsListPage = props => {
|
|
|
break;
|
|
|
}
|
|
|
} else if (type === "category") {
|
|
|
- setHeaderName(title)
|
|
|
fetchNews(title,pagesLoaded + 1)
|
|
|
setPagesLoaded(pagesLoaded + 1)
|
|
|
+ }else if (type === "search"){
|
|
|
+ fetchSearchResults(title)
|
|
|
+ setPagesLoaded(pagesLoaded + 1)
|
|
|
}
|
|
|
console.log(pagesLoaded)
|
|
|
console.log(news.length)
|