refactor toasts

This commit is contained in:
Tom
2023-06-07 18:24:02 +02:00
parent a6faed9ada
commit db2e273ea6
14 changed files with 121 additions and 87 deletions
+25 -14
View File
@@ -68,6 +68,9 @@ const Thread = () => {
const navigate = useNavigate();
const handleClickForm = useClickForm();
const setErrorMessage = useError();
const setSuccessMessage = useSuccess();
const nameRef = useRef();
const commentRef = useRef();
const linkRef = useRef();
@@ -82,8 +85,6 @@ const Thread = () => {
const [triggerPublishComment, setTriggerPublishComment] = useState(false);
const [triggerPublishCommentEdit, setTriggerPublishCommentEdit] = useState(false);
const [deletePost, setDeletePost] = useState(false);
const [errorMessage, setErrorMessage] = useState(null);
const [successMessage, setSuccessMessage] = useState(null);
const [isReplyOpen, setIsReplyOpen] = useState(false);
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
const [originalCommentContent, setOriginalCommentContent] = useState(null);
@@ -97,9 +98,6 @@ const Thread = () => {
const [outOfViewCid, setOutOfViewCid] = useState(null);
const [outOfViewPosition, setOutOfViewPosition] = useState({top: 0, left: 0});
const [postOnHoverHeight, setPostOnHoverHeight] = useState(0);
useError(errorMessage, [errorMessage]);
useSuccess(successMessage, [successMessage]);
const comment = useComment({commentCid: selectedThread});
const { subplebbitAddress, threadCid } = useParams();
@@ -175,7 +173,7 @@ const Thread = () => {
if (errorString) {
setErrorMessage(errorString);
}
}, [errorString]);
}, [errorString, setErrorMessage]);
const flattenedReplies = useMemo(() =>
@@ -327,12 +325,17 @@ const Thread = () => {
useEffect(() => {
if (publishCommentOptions && triggerPublishComment) {
(async () => {
await publishComment();
resetFields();
try {
await publishComment();
resetFields();
} catch (error) {
setErrorMessage(error);
} finally {
setTriggerPublishComment(false);
}
})();
setTriggerPublishComment(false);
}
}, [publishCommentOptions, triggerPublishComment, publishComment, resetFields]);
}, [publishCommentOptions, triggerPublishComment, publishComment, resetFields, setErrorMessage]);
const getChallengeAnswersFromUser = async (challenges) => {
@@ -388,7 +391,7 @@ const Thread = () => {
if (error) {
setErrorMessage(error);
}
}, [error]);
}, [error, setErrorMessage]);
const handleAuthorDeleteClick = (commentCid) => {
@@ -454,11 +457,19 @@ const Thread = () => {
useEffect(() => {
if (publishCommentEditOptions && triggerPublishCommentEdit) {
(async () => {
await publishCommentEdit();
setTriggerPublishCommentEdit(false);
try {
await publishCommentEdit();
setTriggerPublishCommentEdit(false);
} catch (error) {
setErrorMessage(error);
} finally {
setIsAuthorEdit(false);
setIsAuthorDelete(false);
setTriggerPublishCommentEdit(false);
}
})();
}
}, [publishCommentEditOptions, triggerPublishCommentEdit, publishCommentEdit]);
}, [publishCommentEditOptions, triggerPublishCommentEdit, publishCommentEdit, setIsAuthorEdit, setIsAuthorDelete, setTriggerPublishCommentEdit, setErrorMessage]);
// mobile navbar board select functionality