2023-06-08 22:23:58 +02:00
|
|
|
import React, { useState, useEffect } from "react";
|
2023-06-08 12:06:43 +02:00
|
|
|
import { useAccountComment } from "@plebbit/plebbit-react-hooks";
|
2023-06-01 17:24:44 +02:00
|
|
|
import useStateString from "../hooks/useStateString";
|
2023-06-01 10:43:17 +02:00
|
|
|
|
2023-06-08 22:23:58 +02:00
|
|
|
const StateLabel = ({ commentIndex, className }) => {
|
|
|
|
|
const comment = useAccountComment({commentIndex: commentIndex});
|
2023-06-01 17:24:44 +02:00
|
|
|
const stateString = useStateString(comment);
|
2023-06-01 10:43:17 +02:00
|
|
|
|
2023-06-08 22:23:58 +02:00
|
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-06-08 22:27:34 +02:00
|
|
|
const timer = setTimeout(() => setIsLoading(false), 2000);
|
2023-06-08 22:23:58 +02:00
|
|
|
return () => clearTimeout(timer);
|
2023-08-11 17:22:06 +02:00
|
|
|
}, [commentIndex]);
|
2023-06-08 22:23:58 +02:00
|
|
|
|
2023-06-01 10:43:17 +02:00
|
|
|
return (
|
2023-08-11 17:22:06 +02:00
|
|
|
commentIndex !== undefined && stateString !== "Succeeded" ? (
|
2023-06-20 09:34:04 +02:00
|
|
|
(comment.state === "failed") ? (
|
|
|
|
|
null
|
2023-06-08 12:28:33 +02:00
|
|
|
) : (
|
2023-06-20 09:34:04 +02:00
|
|
|
stateString === undefined && !isLoading && comment.cid === undefined ? (
|
2023-06-22 21:59:17 +02:00
|
|
|
null
|
2023-06-20 09:34:04 +02:00
|
|
|
) : (
|
2023-06-08 22:23:58 +02:00
|
|
|
<span className="ttl">
|
|
|
|
|
<br />
|
|
|
|
|
(
|
|
|
|
|
<span className={className}>
|
|
|
|
|
{stateString}
|
|
|
|
|
</span>
|
|
|
|
|
)
|
|
|
|
|
</span>
|
2023-06-20 09:34:04 +02:00
|
|
|
))
|
2023-06-08 12:06:43 +02:00
|
|
|
) : null
|
|
|
|
|
);
|
2023-06-01 10:43:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default StateLabel;
|