Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor changes #2

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions app/Services/getAllNews.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
2 changes: 0 additions & 2 deletions app/Services/getHeadlines.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 10 additions & 5 deletions app/components/BusinessCareer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions app/components/EducationComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ 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");
} catch (error) {
console.log("error in store db", error);
}
}
setEducation(education.articles.results);
setEducation(education.docs);
// disable skeleton
setLoading(false);
} catch (error) {
Expand Down
10 changes: 5 additions & 5 deletions app/components/HorizontalCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 (
<>
Expand Down Expand Up @@ -100,19 +100,19 @@ const HorizontalCard = ({ data, profilePage }) => {
<CardContent className="w-full">
<div className="text-start ml-3">
<h1 className="hover:text-red-500 font-semibold">
{article.title}
{article.abstract}
</h1>
<h1 className="hover:text-red-300 text-sm">
{truncatedBody}
</h1>
<h1 className="hover:text-red-400 text-sm">
Date: {article.date}
Date: {article.pub_date}
</h1>
{article.author ? (
<h1 className="text-sm mt-1 ">
Discovered By:{" "}
<span className="bg-red-500 w-max p-1 hover:text-white rounded">
{article.author}
{article.news_desk}
</span>
</h1>
) : (
Expand Down
5 changes: 2 additions & 3 deletions app/components/NewsSwiperSlide.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ const NewsSwiperSlide = ({ article }) => {
localStorage.setItem("details", JSON.stringify(art));
};

console.log("img", article.media[0]);
return (
<div className="h-full">
<Link
href={"/categorys/" + slugify(article.title).toLowerCase()}
href={"/categorys/" + slugify(article.abstract).toLowerCase()}
onClick={() => saveDetails(article)}
>
<img
Expand All @@ -22,7 +21,7 @@ const NewsSwiperSlide = ({ article }) => {
alt=""
/>
<div className="absolute bottom-0 left-0 right-0 bg-black bg-opacity-50 p-4">
<h1 className="text-3xl text-white">{article.title}</h1>
<h1 className="text-3xl text-white">{article.abstract}</h1>
</div>
</Link>
</div>
Expand Down
13 changes: 9 additions & 4 deletions app/components/PopularCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div>
<div className="px-3 py-1">
Expand All @@ -63,18 +68,18 @@ const PopularCard = ({ article, edu }) => {

{/* link for detailed page */}
<Link
href={"/categorys/" + slugify(article.title).toLowerCase()}
href={"/categorys/" + slugify(article.abstract).toLowerCase()}
onClick={() => saveDetails(article)}
>
<>
<div className="h-[400px] rounded overflow-hidden">
<img
className="object-cover h-full w-full hover:h-[420px]"
src={article.image}
alt=""
src={imageUrl}
alt={article.lead_paragraph}
/>
<div className="bottom-0 -mt-20 left-0 right-0 p-4">
<p className="text-sm text-white">{article.title}</p>
<p className="text-sm font-semibold text-white">{article.abstract}</p>
</div>
</div>
</>
Expand Down
6 changes: 3 additions & 3 deletions app/components/PopularNews.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ 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");
} catch (error) {
console.log("error in store db", error);
}
}
setData(response.articles.results);
setData(response.docs);
setLoading(false);
} catch (error) {
console.log(error);
Expand Down
2 changes: 1 addition & 1 deletion app/components/SpecificCategoryPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion app/components/Swiper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const SwiperSection = () => {
if (isOnline) {
try {
const response = await getHeadlines();
console.log("response", response);
setData(response);
setLoading(false);
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions app/components/SwiperCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ const newsCard = (article) => {
/>
</div>
<Link
href={"/categorys/" + slugify(article.title).toLowerCase()}
href={"/categorys/" + slugify(article.abstract).toLowerCase()}
onClick={() => saveDetails(article)}
>
<div className="h-[200px] rounded overflow-hidden">
<img
className="object-cover h-full w-full hover:h-[220px]"
src={article.image}
src={article.media[0] ? article.media[0]["media-metadata"][2].url: ""}
alt=""
/>
<div className="bottom-0 -mt-20 left-0 right-0 p-4">
<p className="text-sm text-white">{article.title}</p>
<p className="text-sm text-white">{article.abstract}</p>
</div>
</div>
</Link>
Expand Down
2 changes: 1 addition & 1 deletion app/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const categorys = [
];

// key for api
export const key = "rANKrRljqAQrCZdtkkuyDz6n4aT3WHAG";
export const key = "g0KmbShfkmkI0Jy22BG0OH7A1p0w0bxO";

// title
export const title = "ENews"