fix react-toastify with setTimeout

This commit is contained in:
Tom
2023-05-04 08:54:09 +02:00
parent 3b17609336
commit 0aec100ed6
4 changed files with 42 additions and 28 deletions
+1 -3
View File
@@ -2,7 +2,7 @@ import React, { Fragment, useCallback, useEffect, useRef, useState } from 'react
import { Helmet } from 'react-helmet-async'; import { Helmet } from 'react-helmet-async';
import InfiniteScroll from 'react-infinite-scroller'; import InfiniteScroll from 'react-infinite-scroller';
import { Link, useNavigate, useParams } from 'react-router-dom'; import { Link, useNavigate, useParams } from 'react-router-dom';
import { useAccount, useFeed, usePublishComment, useSubscribe } from '@plebbit/plebbit-react-hooks'; import { useFeed, usePublishComment, useSubscribe } from '@plebbit/plebbit-react-hooks';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import useGeneralStore from '../../hooks/stores/useGeneralStore'; import useGeneralStore from '../../hooks/stores/useGeneralStore';
import { Container, NavBar, Header, Break, PostForm, PostFormLink, PostFormTable } from '../styled/Board.styled'; import { Container, NavBar, Header, Break, PostForm, PostFormLink, PostFormTable } from '../styled/Board.styled';
@@ -38,8 +38,6 @@ const Catalog = () => {
showPostFormLink, showPostFormLink,
} = useGeneralStore(state => state); } = useGeneralStore(state => state);
const account = useAccount();
const nameRef = useRef(); const nameRef = useRef();
const subjectRef = useRef(); const subjectRef = useRef();
const commentRef = useRef(); const commentRef = useRef();
+1 -1
View File
@@ -30,7 +30,7 @@ const Subscriptions = () => {
const { const {
defaultSubplebbits, defaultSubplebbits,
isSettingsOpen, setIsSettingsOpen, isSettingsOpen, setIsSettingsOpen,
selectedAddress, setSelectedAddress, setSelectedAddress,
setSelectedParentCid, setSelectedParentCid,
setSelectedShortCid, setSelectedShortCid,
selectedStyle, selectedStyle,
+11 -3
View File
@@ -3,13 +3,14 @@ import { toast } from "react-toastify";
const useError = (message) => { const useError = (message) => {
useEffect(() => { useEffect(() => {
if (message) { if (message && message.length > 0) {
const showErrorToast = () => {
const toastId = toast.error(message.toString(), { const toastId = toast.error(message.toString(), {
position: "top-right", position: "top-right",
autoClose: false, autoClose: false,
hideProgressBar: false, hideProgressBar: true,
closeOnClick: false, closeOnClick: false,
pauseOnHover: true, pauseOnHover: false,
draggable: false, draggable: false,
progress: undefined, progress: undefined,
theme: "dark", theme: "dark",
@@ -18,6 +19,13 @@ const useError = (message) => {
return () => { return () => {
toast.dismiss(toastId); toast.dismiss(toastId);
}; };
};
const timeoutId = setTimeout(showErrorToast, 500);
return () => {
clearTimeout(timeoutId);
};
} }
}, [message]); }, [message]);
}; };
+9 -1
View File
@@ -3,7 +3,8 @@ import { toast } from "react-toastify";
const useSuccess = (message) => { const useSuccess = (message) => {
useEffect(() => { useEffect(() => {
if (message) { if (message && message.length > 0) {
const showSuccessToast = () => {
const toastId = toast.success(message.toString(), { const toastId = toast.success(message.toString(), {
position: "top-right", position: "top-right",
autoClose: 3000, autoClose: 3000,
@@ -18,6 +19,13 @@ const useSuccess = (message) => {
return () => { return () => {
toast.dismiss(toastId); toast.dismiss(toastId);
}; };
};
const timeoutId = setTimeout(showSuccessToast, 500);
return () => {
clearTimeout(timeoutId);
};
} }
}, [message]); }, [message]);
}; };