diff options
| author | realtradam <[email protected]> | 2024-06-06 19:24:45 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2024-06-06 19:24:45 -0400 |
| commit | 34346b1fd4fffd2571374f86b16084066dc4aa2d (patch) | |
| tree | 1f147151e9b1eb9449394d5adb1827b04c4841c5 /src/components/Blogs.tsx | |
| parent | 7a38eef00de0bb35565dda3ddb1efa748c22ea47 (diff) | |
| download | malcz.com-34346b1fd4fffd2571374f86b16084066dc4aa2d.tar.gz malcz.com-34346b1fd4fffd2571374f86b16084066dc4aa2d.zip | |
add seperate uploading page and update match backend functionality
Diffstat (limited to 'src/components/Blogs.tsx')
| -rw-r--r-- | src/components/Blogs.tsx | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/components/Blogs.tsx b/src/components/Blogs.tsx new file mode 100644 index 0000000..863aa73 --- /dev/null +++ b/src/components/Blogs.tsx @@ -0,0 +1,68 @@ +//import React, { useState, useEffect } from "react"; +import { useState, useEffect } from "react"; +import { Link, useNavigate } from "react-router-dom"; + +const Blogs = () => { + const navigate = useNavigate(); + const [blogs, setBlogs] = useState<any[]>([]); // eslint-disable-line @typescript-eslint/no-explicit-any + + + useEffect(() => { + const url = `${import.meta.env.VITE_API_TITLE}/api/v1/blogs/index`; + fetch(url).then((response) => { + if (response.ok) { + return response.json(); + } + throw new Error("Network response was not ok."); + }).then((response) => setBlogs(response)).catch(() => navigate("/")); + }, [navigate]); + + const allBlogs = blogs.map((blog, index) => ( + <div key={index} className="col-md-6 col-lg-4"> + <div className="card mb-4"> + <img src={blog.image} className="card-img-top" alt={`${blog.name} image`}/> + <div className="card-body"> + <h5 className="card-title">{blog.name}</h5> + <Link to={`/blog/${blog.id}`} className="btn custom-button"> + View Post + </Link> + </div> + </div> + </div> + )); + const noBlog = ( + <div className="vw-100 vh-50 dflex align-items-center justify-content-center"> + <h4> Nothing Yet! </h4> + </div> + ); + + return ( + <> + <section className="jumbotron jumbotron-fluid text-center"> + <div className="container py-5"> + <h1 className="display-4">Welcome to my Blog</h1> + <p className="lead text-muted"> + Yup, this is my blog and stuff. Enjoy it :) + </p> + </div> + </section> + <div className="py-5"> + <main className="container"> + <div className="text-end mb-3"> + <Link to="/blog" className="btn custom-button"> + Write New Blog + </Link> + </div> + <div className="row"> + {blogs.length > 0 ? allBlogs : noBlog} + </div> + <Link to="/" className="btn btn-link"> + Home + </Link> + </main> + </div> + </> + ); +}; + +export default Blogs; |
