MailNew.jsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {useEffect, useState} from "react";
  2. import Spring from "@components/Spring";
  3. import Lottie from "lottie-react";
  4. import mailnew from "@assets/newmail.json";
  5. const objInfo={
  6. timerIds:[]
  7. }
  8. const MailNew = ({...props}) => {
  9. const [isShow, setIsShow] = useState(false);
  10. const show=()=>{
  11. setIsShow(true);
  12. }
  13. const hide=()=>{
  14. setIsShow(false);
  15. }
  16. const resetTimer=()=>{
  17. if (objInfo.timerIds){
  18. for (let i = 0; i < objInfo.timerIds; i++) {
  19. clearTimeout(objInfo.timerIds[i]);
  20. }
  21. objInfo.timerIds=[];
  22. }
  23. }
  24. useEffect(()=>{
  25. const mailNew={
  26. show,
  27. hide
  28. };
  29. global.mailNew=mailNew;
  30. },[])
  31. useEffect(() => {
  32. resetTimer();
  33. if (isShow){
  34. let timer=setTimeout(()=>{
  35. setIsShow(false);
  36. },4000);
  37. objInfo.timerIds.push(timer);
  38. }
  39. },[isShow])
  40. return (
  41. <>
  42. {
  43. isShow?(
  44. <Spring {...props} className="d-flex align-items-center justify-content-center flex-1 w-100 h-100 top_view">
  45. <Lottie loop={false} autoplay={true} className="top_view" animationData={mailnew} />
  46. </Spring>
  47. ):(<></>)
  48. }
  49. </>
  50. )
  51. }
  52. export default MailNew;