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

detailed page created #3

Merged
merged 9 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
16 changes: 10 additions & 6 deletions app/categorys/[category]/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ const page = () => {
setArticle(jsonData);
}, []);

const imageUrl = article.multimedia && article.multimedia.length > 0
? "https://www.nytimes.com/" + article.multimedia[0].url
: "";

return (
<div className="my-4">
<Container>
<div className="h-[500px]">
<img
className="object-cover h-full w-full rounded"
src={article.image}
src={imageUrl}
alt=""
/>
</div>
<div className="my-3">
<p className="text-3xl font-bold text-red-500">{article.title}</p>
<p className="text-3xl font-bold text-red-500">{article.abstract}</p>
{/* <p className="text-xl">
Author:
{article.authors.map((auth) => (
Expand All @@ -38,14 +42,14 @@ const page = () => {
))}
</p> */}
<p className="text-xl mt-2">
Published At : <span className="font-bold rounded p-1 text-white bg-red-500">{article.date}</span>{" "}
Published At : <span className="font-bold rounded p-1 text-white bg-red-500">{article.pub_date}</span>{" "}
</p>
<p className="text-sm italic mt-4">{article.body} </p>
<p className="text-sm italic mt-4">{article.lead_paragraph} </p>

<p className="mt-3">
For more information visit :{" "}
<a href={article.url} className="text-blue-500 underline">
{article.url}
<a href={article.uri} className="text-blue-500 underline">
{article.uri}
</a>
</p>
</div>
Expand Down
28 changes: 18 additions & 10 deletions app/components/BusinessCareer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ const BusinessCareer = () => {
console.log("inside try")
const response = await getSpecificQueryNews("career");
const business = await getSpecificQueryNews("business");
setData(response.docs);
console.log("response got",response)
setLoading(false);


console.log("response got", response.docs)
console.log("business", business);
console.log("response", response);

setData(response.docs);
setBusiness(business.docs);
// response store in firestore so wher user is offline we got data from there

// response store in firestore so when user is offline we got data from there
if (response.docs && business.docs) {
try {
response.docs.forEach(async (article) => {
Expand All @@ -50,23 +51,30 @@ const BusinessCareer = () => {
console.log("error in store db", error);
}
}

setLoading(false);
setBusinessLoading(false);
} catch (error) {
console.log(error);
}
}
// else getting data from cache(firestore)
else {
} else {
// else getting data from cache(firestore)
const careerData = await getDocs(collection(db, "career"));
const careerDocs = [];
careerData.forEach((doc) => {
console.log(doc.id, " => ", doc.data());
data.push(doc.data());
careerDocs.push(doc.data());
});
setData(careerDocs);

const businessData = await getDocs(collection(db, "business"));
const businessDocs = [];
businessData.forEach((doc) => {
console.log(doc.id, " => ", doc.data());
business.push(doc.data());
businessDocs.push(doc.data());
});
setBusiness(businessDocs);

setLoading(false);
setBusinessLoading(false);
}
Expand Down
29 changes: 13 additions & 16 deletions app/components/HorizontalCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const HorizontalCard = ({ data, profilePage }) => {
const isAlreadyLiked = favItems.some(
(item) => item.title === data.title
);
// check whether artiley is already in fav or not
// check whether article is already in fav or not
if (isAlreadyLiked) {
toast.error("Article already in favorites");
} else {
Expand All @@ -56,17 +56,15 @@ const HorizontalCard = ({ data, profilePage }) => {
<div>
{data.slice(0, 5).map((article) => {
// to display ... after certain characters
const truncatedBody =
article.body.length > 300
? `${article.lead_paragraph.substring(0, 300)}...`
: article.body;
const imageUrl = article.multimedia && article.multimedia.length > 0
? "https://www.nytimes.com/" + article.multimedia[0].url
: "";

return (
<>
<div key={article.title}>
{/* if it doesn't a profile page than only this add fav btn visible */}
{!profilePage ? (
<div
className={`like absolute ml-2 mt-2 border bg-white rounded-full`}
>
<div className="like absolute ml-2 mt-2 border bg-white rounded-full">
<IconButton onClick={() => addToLike(article)}>
<FavoriteBorder />
</IconButton>
Expand All @@ -75,8 +73,7 @@ const HorizontalCard = ({ data, profilePage }) => {
""
)}
<Link
key={article.title}
href={"/categorys/" + slugify(article.title).toLowerCase()}
href={"/categorys/" + slugify(article.abstract).toLowerCase()}
onClick={() => saveDetails(article)}
>
<Card
Expand All @@ -89,7 +86,7 @@ const HorizontalCard = ({ data, profilePage }) => {
className="h-full"
>
<img
src={article.image}
src={imageUrl}
alt=""
className="object-cover h-full"
height={"100%"}
Expand All @@ -103,13 +100,13 @@ const HorizontalCard = ({ data, profilePage }) => {
{article.abstract}
</h1>
<h1 className="hover:text-red-300 text-sm">
{truncatedBody}
{article.lead_paragraph}
</h1>
<h1 className="hover:text-red-400 text-sm">
Date: {article.pub_date}
</h1>
{article.author ? (
<h1 className="text-sm mt-1 ">
<h1 className="text-sm mt-1">
Discovered By:{" "}
<span className="bg-red-500 w-max p-1 hover:text-white rounded">
{article.news_desk}
Expand All @@ -122,7 +119,7 @@ const HorizontalCard = ({ data, profilePage }) => {
</CardContent>
</Card>
</Link>
{/* inside profile page we give remove fav btn that remove any article from favoritesF */}
{/* inside profile page we give remove fav btn that remove any article from favorites */}
{profilePage ? (
<div className="flex justify-end mr-2 -mt-14">
<button
Expand All @@ -135,7 +132,7 @@ const HorizontalCard = ({ data, profilePage }) => {
) : (
""
)}
</>
</div>
);
})}
</div>
Expand Down
6 changes: 5 additions & 1 deletion app/components/NewsSwiperSlide.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const NewsSwiperSlide = ({ article }) => {
localStorage.setItem("details", JSON.stringify(art));
};

const imageUrl = article.multimedia && article.multimedia.length > 0
? "https://www.nytimes.com/" + article.multimedia[0].url
: "";

return (
<div className="h-full">
<Link
Expand All @@ -17,7 +21,7 @@ const NewsSwiperSlide = ({ article }) => {
>
<img
className="object-cover h-full w-full"
src={article.media[0] ? article.media[0]["media-metadata"][2].url: ""}
src={imageUrl}
alt=""
/>
<div className="absolute bottom-0 left-0 right-0 bg-black bg-opacity-50 p-4">
Expand Down
5 changes: 3 additions & 2 deletions app/components/Swiper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import NewsSwiperSlide from "./NewsSwiperSlide";
import { SwiperSkeleton } from "./Skeleton";
import { db } from "../firebaseConfig";
import { collection, getDocs } from "firebase/firestore";
import { getSpecificQueryNews } from "../Services/getAllNews";

const SwiperSection = () => {
const [data, setData] = useState([]);
Expand All @@ -26,8 +27,8 @@ const SwiperSection = () => {
// if user is online then send req to api
if (isOnline) {
try {
const response = await getHeadlines();
setData(response);
const response = await getSpecificQueryNews("trending");
setData(response.docs);
setLoading(false);
} catch (error) {
console.log(error);
Expand Down
6 changes: 5 additions & 1 deletion app/components/SwiperCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ const newsCard = (article) => {
}
}

const imageUrl = article.multimedia && article.multimedia.length > 0
? "https://www.nytimes.com/" + article.multimedia[0].url
: "";

return (
<div className="px-3 py-1" key={article.url}>
<div className={`like absolute ml-2 mt-2 border bg-white rounded-full`}>
Expand All @@ -86,7 +90,7 @@ const newsCard = (article) => {
<div className="h-[200px] rounded overflow-hidden">
<img
className="object-cover h-full w-full hover:h-[220px]"
src={article.media[0] ? article.media[0]["media-metadata"][2].url: ""}
src={imageUrl}
alt=""
/>
<div className="bottom-0 -mt-20 left-0 right-0 p-4">
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 = "g0KmbShfkmkI0Jy22BG0OH7A1p0w0bxO";
export const key = "x1GDJ2YLEA54gjCw0NVcG0hmNWUKmxJ0";

// title
export const title = "ENews"