Skip to content

Commit

Permalink
update swiper
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruv8433 committed Jul 3, 2024
1 parent 6476b2e commit 2fde8ab
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
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"

0 comments on commit 2fde8ab

Please sign in to comment.