Browse Source

Integrated Trending API for Trending Tab

Savio Fernando 1 year ago
parent
commit
eb3f21c0a1
1 changed files with 19 additions and 4 deletions
  1. 19 4
      components/organisms/Sections/RecentNewsSection.js

+ 19 - 4
components/organisms/Sections/RecentNewsSection.js

@@ -9,6 +9,7 @@ import metrics from '../../../theme/metrics'
 import Carousel from 'react-native-reanimated-carousel';
 import MaterialComIcon from 'react-native-vector-icons/MaterialCommunityIcons'
 import { useConstructor } from '../../../utils/Constants/functions'
+import { PAGINATE_BY } from '../../../utils/Constants/constants'
 
 // import {Q} from '@nozbe/watermelondb';
 // import withObservables from '@nozbe/with-observables';
@@ -37,11 +38,24 @@ const RecentNewsSection = () => {
   const [posts,setPosts] = React.useState([{},{},{},{},{}])
 
   const fetchPosts = () => {
-    fetch("http://www.newscout.in/api/v1/article/search/?domain=newscout&category=Sector%20Updates")
+    fetch("http://www.newscout.in/api/v1/trending?domain=newscout")
     .then((res) => res.json())
     .then((json) => {
-      const postData = json.body.results
-      const finalPostData = postData.slice(0,5).map((item)=> ({
+      let postData = json.body.results
+      // const finalPostData = postData.slice(0,5).map((item)=> ({
+      //   image:item.cover_image,
+      //   author: item.author,
+      //   headline: item.title,
+      //   id: item.id,
+      // }))
+      let buffer = []
+      postData.slice(0,PAGINATE_BY).forEach((item) => buffer.push(...item.articles))
+      // let buffer = [] 
+      // for (const item of postData.slice(0,PAGINATE_BY)) {
+      //   buffer.push(...item.articles)
+      // }
+      // console.log(`Bruh ` + buffer)
+      const finalPostData = buffer.map((item)=> ({
         image:item.cover_image,
         author: item.author,
         headline: item.title,
@@ -61,7 +75,8 @@ const RecentNewsSection = () => {
 
   return (
     <View>
-      <SectionHeader label={"Recent News"} />
+      {/* <SectionHeader label={"Recent News"} /> */}
+      <SectionHeader label={"Trending"} />
       <View style={styles.recentCardContainer}>
         <Carousel
           loop