mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix react-toastify with setTimeout
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const Subscriptions = () => {
|
|||||||
const {
|
const {
|
||||||
defaultSubplebbits,
|
defaultSubplebbits,
|
||||||
isSettingsOpen, setIsSettingsOpen,
|
isSettingsOpen, setIsSettingsOpen,
|
||||||
selectedAddress, setSelectedAddress,
|
setSelectedAddress,
|
||||||
setSelectedParentCid,
|
setSelectedParentCid,
|
||||||
setSelectedShortCid,
|
setSelectedShortCid,
|
||||||
selectedStyle,
|
selectedStyle,
|
||||||
|
|||||||
+20
-12
@@ -3,20 +3,28 @@ import { toast } from "react-toastify";
|
|||||||
|
|
||||||
const useError = (message) => {
|
const useError = (message) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (message) {
|
if (message && message.length > 0) {
|
||||||
const toastId = toast.error(message.toString(), {
|
const showErrorToast = () => {
|
||||||
position: "top-right",
|
const toastId = toast.error(message.toString(), {
|
||||||
autoClose: false,
|
position: "top-right",
|
||||||
hideProgressBar: false,
|
autoClose: false,
|
||||||
closeOnClick: false,
|
hideProgressBar: true,
|
||||||
pauseOnHover: true,
|
closeOnClick: false,
|
||||||
draggable: false,
|
pauseOnHover: false,
|
||||||
progress: undefined,
|
draggable: false,
|
||||||
theme: "dark",
|
progress: undefined,
|
||||||
});
|
theme: "dark",
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
toast.dismiss(toastId);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const timeoutId = setTimeout(showErrorToast, 500);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
toast.dismiss(toastId);
|
clearTimeout(timeoutId);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}, [message]);
|
}, [message]);
|
||||||
|
|||||||
+20
-12
@@ -3,20 +3,28 @@ import { toast } from "react-toastify";
|
|||||||
|
|
||||||
const useSuccess = (message) => {
|
const useSuccess = (message) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (message) {
|
if (message && message.length > 0) {
|
||||||
const toastId = toast.success(message.toString(), {
|
const showSuccessToast = () => {
|
||||||
position: "top-right",
|
const toastId = toast.success(message.toString(), {
|
||||||
autoClose: 3000,
|
position: "top-right",
|
||||||
hideProgressBar: false,
|
autoClose: 3000,
|
||||||
closeOnClick: false,
|
hideProgressBar: false,
|
||||||
pauseOnHover: false,
|
closeOnClick: false,
|
||||||
draggable: false,
|
pauseOnHover: false,
|
||||||
progress: undefined,
|
draggable: false,
|
||||||
theme: "dark",
|
progress: undefined,
|
||||||
});
|
theme: "dark",
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
toast.dismiss(toastId);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const timeoutId = setTimeout(showSuccessToast, 500);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
toast.dismiss(toastId);
|
clearTimeout(timeoutId);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}, [message]);
|
}, [message]);
|
||||||
|
|||||||
Reference in New Issue
Block a user