From effd056d124cdd4649ff2a3f66cdb28f1a7dc246 Mon Sep 17 00:00:00 2001 From: Ayush Date: Fri, 8 Nov 2024 21:25:59 +0530 Subject: [PATCH] added aniamtion loading in the read more blogs page --- .../src/Components/BlogDetailsPage.jsx | 148 +++++++++++------- 1 file changed, 95 insertions(+), 53 deletions(-) diff --git a/hiring-portal/src/Components/BlogDetailsPage.jsx b/hiring-portal/src/Components/BlogDetailsPage.jsx index e22cc1c..e4c341f 100644 --- a/hiring-portal/src/Components/BlogDetailsPage.jsx +++ b/hiring-portal/src/Components/BlogDetailsPage.jsx @@ -3,73 +3,115 @@ import Navbar from "./Navbar"; import Footer from "./Footer"; import axios from "axios"; import { useParams } from "react-router-dom"; +import Lottie from "react-lottie"; +import loading from "../assests/loading.json"; const formatDate = (dateString) => { - const date = new Date(dateString); - if (isNaN(date.getTime())) { - throw new Error("Invalid date format"); - } + const date = new Date(dateString); + if (isNaN(date.getTime())) { + throw new Error("Invalid date format"); + } - const day = String(date.getDate()).padStart(2, '0'); - const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are 0-based - const year = date.getFullYear(); + const day = String(date.getDate()).padStart(2, "0"); + const month = String(date.getMonth() + 1).padStart(2, "0"); // Months are 0-based + const year = date.getFullYear(); - return `${day}-${month}-${year}`; + return `${day}-${month}-${year}`; +}; +const defaultOptions2 = { + loop: true, + autoplay: true, + animationData: loading, + rendererSettings: { + preserveAspectRatio: "xMidYMid slice", + }, }; - const BlogDetailPage = () => { - const [blog, setBlog] = useState(null); - const { id } = useParams(); // Get the blog ID from the URL + const [blog, setBlog] = useState(null); + const { id } = useParams(); // Get the blog ID from the URL - const fetchBlogData = async () => { - try { - const response = await axios.get(`http://localhost:5000/api/get-by-id/${id}`); - setBlog(response.data.blog); // Assuming response.data contains the blog object - } catch (error) { - console.error("Error fetching blog data:", error); - } - }; + const fetchBlogData = async () => { + try { + const response = await axios.get( + `http://localhost:5000/api/get-by-id/${id}` + ); + setBlog(response.data.blog); // Assuming response.data contains the blog object + } catch (error) { + console.error("Error fetching blog data:", error); + } + }; - useEffect(() => { - fetchBlogData(); - }, [id]); + useEffect(() => { + fetchBlogData(); + }, [id]); - if (!blog) { - return

Loading...

; // Show a loading message while fetching - } + if (!blog) { + return ( +
+ +

Loading page...

+
+ ); // Show a loading message while fetching + } - // Convert HTML content to plain text - const getPlainTextContent = (htmlContent) => { - const tempDiv = document.createElement('div'); - tempDiv.innerHTML = htmlContent; - return tempDiv.innerText; - }; + // Convert HTML content to plain text + const getPlainTextContent = (htmlContent) => { + const tempDiv = document.createElement("div"); + tempDiv.innerHTML = htmlContent; + return tempDiv.innerText; + }; - const placeholderImage = "https://images.unsplash.com/photo-1493723843671-1d655e66ac1c"; - const imageUrl = blog.imageUrl || placeholderImage; // Use placeholder if no image URL is provided + const placeholderImage = + "https://images.unsplash.com/photo-1493723843671-1d655e66ac1c"; + const imageUrl = blog.imageUrl || placeholderImage; // Use placeholder if no image URL is provided - return ( - <> - -
-
-

{blog.title}

-

- Published on By {blog.author} -

-
+ return ( + <> + +
+
+

+ {blog.title} +

+

+ Published on{" "} + By{" "} + {blog.author} +

+
- {blog.title} + {blog.title} -
-

- {getPlainTextContent(blog.content)} -

-
-
-
- - ); +
+

{getPlainTextContent(blog.content)}

+
+
+