From 50872b40ba1dd61ce7d01f00b0115e1d062ecdfd Mon Sep 17 00:00:00 2001 From: Soni Dhruv Date: Wed, 3 Jul 2024 13:19:47 +0530 Subject: [PATCH 1/2] service change api --- app/Services/getAllNews.js | 20 ++++---------------- app/Services/getHeadlines.js | 2 -- app/config/config.js | 2 +- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/app/Services/getAllNews.js b/app/Services/getAllNews.js index f5fdda6..f4a0453 100644 --- a/app/Services/getAllNews.js +++ b/app/Services/getAllNews.js @@ -3,20 +3,8 @@ import { httpAxios } from "../httpAxios"; // specific news based on query string -> q export const getSpecificQueryNews = async (q) => { - const response = await httpAxios.get(`/article/getArticles`, { - params: { - action: "getArticles", - keyword: q, - articlesPage: 1, - articlesCount: 100, - articlesSortBy: "date", - articlesSortByAsc: false, - articlesArticleBodyLen: -1, - resultType: "articles", - dataType: ["news", "pr"], - apiKey: key, - forceMaxDataTimeWindow: 31, - }, - }); - return response.data; + const response = await httpAxios.get( + `/search/v2/articlesearch.json?q=${q}&api-key=${key}` + ); + return response.data.response; }; diff --git a/app/Services/getHeadlines.js b/app/Services/getHeadlines.js index 6a67a5b..c6aa0d4 100644 --- a/app/Services/getHeadlines.js +++ b/app/Services/getHeadlines.js @@ -9,8 +9,6 @@ export const getHeadlines = async () => { `/mostpopular/v2/emailed/7.json?api-key=${key}` ); - console.log("custom response",response) - // try to store in firestore -> so we can access it even we are offline if (response.data) { try { diff --git a/app/config/config.js b/app/config/config.js index d9d178e..d8a1891 100644 --- a/app/config/config.js +++ b/app/config/config.js @@ -21,7 +21,7 @@ export const categorys = [ ]; // key for api -export const key = "rANKrRljqAQrCZdtkkuyDz6n4aT3WHAG"; +export const key = "g0KmbShfkmkI0Jy22BG0OH7A1p0w0bxO"; // title export const title = "ENews" From f1a7b449569980cbb0f8b99cb9ac0a5846ecb06e Mon Sep 17 00:00:00 2001 From: Soni Dhruv Date: Wed, 3 Jul 2024 13:19:57 +0530 Subject: [PATCH 2/2] update news all cards --- app/components/BusinessCareer.jsx | 15 ++++++++++----- app/components/EducationComponent.jsx | 6 +++--- app/components/HorizontalCard.jsx | 10 +++++----- app/components/NewsSwiperSlide.jsx | 5 ++--- app/components/PopularCard.jsx | 13 +++++++++---- app/components/PopularNews.jsx | 6 +++--- app/components/SpecificCategoryPage.jsx | 2 +- app/components/Swiper.jsx | 1 - app/components/SwiperCard.jsx | 6 +++--- 9 files changed, 36 insertions(+), 28 deletions(-) diff --git a/app/components/BusinessCareer.jsx b/app/components/BusinessCareer.jsx index d95ed0b..5e47e4c 100644 --- a/app/components/BusinessCareer.jsx +++ b/app/components/BusinessCareer.jsx @@ -26,18 +26,23 @@ const BusinessCareer = () => { // if user is online then send request to api if (isOnlined) { try { + console.log("inside try") const response = await getSpecificQueryNews("career"); const business = await getSpecificQueryNews("business"); - setData(response.articles.results); + setData(response.docs); + console.log("response got",response) setLoading(false); - setBusiness(business.articles.results); + + console.log("business", business); + console.log("response", response); + setBusiness(business.docs); // response store in firestore so wher user is offline we got data from there - if (response.articles.results && business.articles.results) { + if (response.docs && business.docs) { try { - response.articles.results.forEach(async (article) => { + response.docs.forEach(async (article) => { await addDoc(collection(db, "career"), article); }); - business.articles.results.forEach(async (article) => { + business.docs.forEach(async (article) => { await addDoc(collection(db, "business"), article); }); console.log("Career & Business added to Firestore"); diff --git a/app/components/EducationComponent.jsx b/app/components/EducationComponent.jsx index d83288e..3449e38 100644 --- a/app/components/EducationComponent.jsx +++ b/app/components/EducationComponent.jsx @@ -22,9 +22,9 @@ const EducationComponent = () => { try { const education = await getSpecificQueryNews("education"); // store the data in firestore so we got it when user is offline - if (education.articles.results) { + if (education.docs) { try { - education.articles.forEach(async (article) => { + education.docs.forEach(async (article) => { await addDoc(collection(db, "edu"), article); }); console.log("Edu added to Firestore"); @@ -32,7 +32,7 @@ const EducationComponent = () => { console.log("error in store db", error); } } - setEducation(education.articles.results); + setEducation(education.docs); // disable skeleton setLoading(false); } catch (error) { diff --git a/app/components/HorizontalCard.jsx b/app/components/HorizontalCard.jsx index e540116..c56fa03 100644 --- a/app/components/HorizontalCard.jsx +++ b/app/components/HorizontalCard.jsx @@ -41,7 +41,7 @@ const HorizontalCard = ({ data, profilePage }) => { if (isAlreadyLiked) { toast.error("Article already in favorites"); } else { - const response = dispatch(addFavorite(data)); + dispatch(addFavorite(data)); toast.success("Article added to favorites"); } } catch (error) { @@ -58,7 +58,7 @@ const HorizontalCard = ({ data, profilePage }) => { // to display ... after certain characters const truncatedBody = article.body.length > 300 - ? `${article.body.substring(0, 300)}...` + ? `${article.lead_paragraph.substring(0, 300)}...` : article.body; return ( <> @@ -100,19 +100,19 @@ const HorizontalCard = ({ data, profilePage }) => {

- {article.title} + {article.abstract}

{truncatedBody}

- Date: {article.date} + Date: {article.pub_date}

{article.author ? (

Discovered By:{" "} - {article.author} + {article.news_desk}

) : ( diff --git a/app/components/NewsSwiperSlide.jsx b/app/components/NewsSwiperSlide.jsx index ab2b28f..6b383b1 100644 --- a/app/components/NewsSwiperSlide.jsx +++ b/app/components/NewsSwiperSlide.jsx @@ -9,11 +9,10 @@ const NewsSwiperSlide = ({ article }) => { localStorage.setItem("details", JSON.stringify(art)); }; - console.log("img", article.media[0]); return (
saveDetails(article)} > { alt="" />
-

{article.title}

+

{article.abstract}

diff --git a/app/components/PopularCard.jsx b/app/components/PopularCard.jsx index b59d312..3e5d928 100644 --- a/app/components/PopularCard.jsx +++ b/app/components/PopularCard.jsx @@ -43,6 +43,11 @@ const PopularCard = ({ article, edu }) => { } } + // Extracting the image URL from the multimedia array + const imageUrl = article.multimedia && article.multimedia.length > 0 + ? "https://www.nytimes.com/" + article.multimedia[0].url + : ""; + return (
@@ -63,18 +68,18 @@ const PopularCard = ({ article, edu }) => { {/* link for detailed page */} saveDetails(article)} > <>
-

{article.title}

+

{article.abstract}

diff --git a/app/components/PopularNews.jsx b/app/components/PopularNews.jsx index 978f251..8c9b0a3 100644 --- a/app/components/PopularNews.jsx +++ b/app/components/PopularNews.jsx @@ -21,10 +21,10 @@ const PopularNews = () => { if (isOnline) { try { const response = await getSpecificQueryNews("popular"); - if (response.articles.results) { + if (response) {1 // storing results in popular collection try { - response.articles.results.map(async (article) => { + response.docs.map(async (article) => { await addDoc(collection(db, "popular"), article); }); console.log("Popular added to Firestore"); @@ -32,7 +32,7 @@ const PopularNews = () => { console.log("error in store db", error); } } - setData(response.articles.results); + setData(response.docs); setLoading(false); } catch (error) { console.log(error); diff --git a/app/components/SpecificCategoryPage.jsx b/app/components/SpecificCategoryPage.jsx index d9378ff..bb452e6 100644 --- a/app/components/SpecificCategoryPage.jsx +++ b/app/components/SpecificCategoryPage.jsx @@ -20,7 +20,7 @@ const SpecificCategoryPage = ({ query }) => { try { // send request to particular query const response = await getSpecificQueryNews(query); - setData(response.articles.results); + setData(response.docs); setLoading(false); } catch (error) { console.log(error); diff --git a/app/components/Swiper.jsx b/app/components/Swiper.jsx index d4e2642..8405fa1 100644 --- a/app/components/Swiper.jsx +++ b/app/components/Swiper.jsx @@ -27,7 +27,6 @@ const SwiperSection = () => { if (isOnline) { try { const response = await getHeadlines(); - console.log("response", response); setData(response); setLoading(false); } catch (error) { diff --git a/app/components/SwiperCard.jsx b/app/components/SwiperCard.jsx index 0d09f46..127e3cd 100644 --- a/app/components/SwiperCard.jsx +++ b/app/components/SwiperCard.jsx @@ -80,17 +80,17 @@ const newsCard = (article) => { />
saveDetails(article)} >
-

{article.title}

+

{article.abstract}