fix StateLabel flickering

This commit is contained in:
plebeius.eth
2023-08-18 20:46:32 +02:00
parent afb5991b47
commit e524ba4a67
+11 -15
View File
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from "react"; import React from "react";
import { useAccountComment } from "@plebbit/plebbit-react-hooks"; import { useAccountComment } from "@plebbit/plebbit-react-hooks";
import useStateString from "../hooks/useStateString"; import useStateString from "../hooks/useStateString";
@@ -6,21 +6,19 @@ const StateLabel = ({ commentIndex, className }) => {
const comment = useAccountComment({commentIndex: commentIndex}); const comment = useAccountComment({commentIndex: commentIndex});
const stateString = useStateString(comment); const stateString = useStateString(comment);
const [isLoading, setIsLoading] = useState(true); if (comment.updatedAt !== undefined) {
return null;
}
useEffect(() => { if (comment.state === "failed") {
const timer = setTimeout(() => setIsLoading(false), 2000); return null;
return () => clearTimeout(timer); }
}, [commentIndex]);
if (!stateString) {
return null;
}
return ( return (
commentIndex !== undefined && stateString !== "Succeeded" ? (
(comment.state === "failed") ? (
null
) : (
stateString === undefined && !isLoading && comment.cid === undefined ? (
null
) : (
<span className="ttl"> <span className="ttl">
<br /> <br />
( (
@@ -29,8 +27,6 @@ const StateLabel = ({ commentIndex, className }) => {
</span> </span>
) )
</span> </span>
))
) : null
); );
}; };