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