Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

BlogSection.jsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import PropTypes from 'prop-types';
  2. import { useState, useEffect } from 'react';
  3. import axios from 'axios';
  4. import { Link } from 'react-router-dom';
  5. import { motion } from 'framer-motion';
  6. import Animation_Diligent from './../assets/animation_diligent.webm';
  7. const api_url = process.env.REACT_APP_API_URL;
  8. export default function BlogSection(props) {
  9. const [cntBlog, setCntBlog] = useState('');
  10. const [isLoaded, setIsLoaded] = useState('');
  11. useEffect(async () => {
  12. var vid = document.getElementById('animation');
  13. vid.playbackRate = 2;
  14. axios
  15. .get(`${api_url}/api/blogpage?populate[0]=post.image`)
  16. .then(res => {
  17. setCntBlog(res.data.data.attributes);
  18. setIsLoaded(true);
  19. })
  20. .catch(err => {
  21. console.log(err);
  22. setIsLoaded(false);
  23. });
  24. }, []);
  25. if (!isLoaded) {
  26. return (
  27. <div className="z-50 w-full h-screen bg-white dark:bg-dg-primary-1700 dark:text-white flex items-center justify-center text-3xl font-semibold">
  28. <video id="animation" width="540" height="540" autoPlay muted loop>
  29. <source src={Animation_Diligent} type="video/webm" />
  30. Loading...
  31. </video>
  32. </div>
  33. );
  34. }
  35. return (
  36. <section id="blog_section" className={props.bgColor + ' ' + props.padding}>
  37. <motion.div
  38. className="max-w-custom m-auto"
  39. initial={{ y:60, opacity: 0 }}
  40. whileInView={{ y:0, opacity: 1}}
  41. transition={{ duration: 0.5, ease: 'easeOut' }}
  42. >
  43. <section id="heading" className="flex flex-col justify-center px-4">
  44. <div className="my-8 flex justify-start items-center w-4/5">
  45. <div className="w-4/5 lg:w-3/5">
  46. <h6 className="subheading">
  47. {cntBlog.subheading}
  48. </h6>
  49. <h1 className="heading mt-2">
  50. {cntBlog.heading}
  51. </h1>
  52. </div>
  53. </div>
  54. </section>
  55. {/* Blog Posts Section */}
  56. <section
  57. id="posts"
  58. className="flex flex-col items-center justify-center px-4 mb-8"
  59. >
  60. <div className="grid grid-cols-1 lg:grid-cols-3 gap-8 w-full">
  61. {cntBlog.post.map(post => (
  62. <div
  63. className="card w-full lg:w-fit text-left flex flex-col justify-between lg:first:col-span-2"
  64. key={post.id}
  65. >
  66. <div className="mb-12">
  67. <div className="w-full">
  68. <img
  69. src={api_url + post.image.data.attributes.formats.thumbnail.url}
  70. alt="Post's image"
  71. className="max-w-fit max-h-fit"
  72. />
  73. </div>
  74. <h3 className="font-semibold text-2xl mb-2">{post.heading}</h3>
  75. <p className="text-sm">{post.paragraph}</p>
  76. </div>
  77. <div className="flex flex-row items-center justify-between">
  78. <h6 className="text-gray-500 text-xs">{post.date}</h6>
  79. <Link
  80. to="/post"
  81. state={{
  82. date: post.date,
  83. heading: post.heading,
  84. subheading: cntBlog.subheading,
  85. content: post.content,
  86. }}
  87. className="font-semibold text-dg-secondary underline transition-all hover:text-dg-primary-900 hover:transition-all"
  88. >
  89. Read More
  90. </Link>
  91. </div>
  92. </div>
  93. ))}
  94. </div>
  95. </section>
  96. </motion.div>
  97. </section>
  98. );
  99. }
  100. BlogSection.propTypes = {
  101. bgColor: PropTypes.string,
  102. padding: PropTypes.string,
  103. };