Skip to content

Commit

Permalink
update api
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruv8433 committed Jul 3, 2024
1 parent 538b3ac commit d33ab47
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
30 changes: 10 additions & 20 deletions app/Services/getHeadlines.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,23 @@ import { httpAxios, topHeadlines } from "../httpAxios";

// top healines of US
export const getHeadlines = async () => {
const response = await httpAxios.get(`/article/getArticles`, {
params: {
action: "getArticles",
keyword: "Top Headlines",
articlesPage: 1,
articlesCount: 100,
articlesSortBy: "date",
articlesSortByAsc: false,
articlesArticleBodyLen: -1,
resultType: "articles",
dataType: ["news", "pr"],
apiKey: key,
forceMaxDataTimeWindow: 31,
},
});
const response = await httpAxios.get(
`/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.articles.results) {
if (response.data) {
try {
response.data.articles.results.forEach(async (article) => {
await addDoc(collection(db, "headlines"), article);
});
// response.data.forEach(async (article) => {
// await addDoc(collection(db, "headlines"), article);
// });
console.log("Article added to Firestore");
} catch (error) {
console.log("error in store db", error);
}
}

return response.data;
return response.data.results;
};
4 changes: 3 additions & 1 deletion app/components/NewsSwiperSlide.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const NewsSwiperSlide = ({ article }) => {
const saveDetails = (art) => {
localStorage.setItem("details", JSON.stringify(art));
};

console.log("img", article.media[0]);
return (
<div className="h-full">
<Link
Expand All @@ -16,7 +18,7 @@ const NewsSwiperSlide = ({ article }) => {
>
<img
className="object-cover h-full w-full"
src={article.image}
src={article.media[0] ? article.media[0]["media-metadata"][2].url: ""}
alt=""
/>
<div className="absolute bottom-0 left-0 right-0 bg-black bg-opacity-50 p-4">
Expand Down
3 changes: 2 additions & 1 deletion app/components/Swiper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const SwiperSection = () => {
if (isOnline) {
try {
const response = await getHeadlines();
setData(response.articles.results);
console.log("response", response);
setData(response);
setLoading(false);
} catch (error) {
console.log(error);
Expand Down
4 changes: 2 additions & 2 deletions app/config/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// api end-point
export const api_endpoint = `https://newsapi.ai/api/v1`;
export const api_endpoint = `https://api.nytimes.com/svc`;

// our top category
export const categorys = [
Expand All @@ -21,7 +21,7 @@ export const categorys = [
];

// key for api
export const key = "7f5fd96a-2f8e-4ac6-9187-cb0e6efc6109";
export const key = "rANKrRljqAQrCZdtkkuyDz6n4aT3WHAG";

// title
export const title = "ENews"

0 comments on commit d33ab47

Please sign in to comment.