Files
5chan/src/components/StateLabel.jsx
T

45 lines
1.2 KiB
React
Raw Normal View History

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
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
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
2023-06-08 22:27:34 +02:00
const timer = setTimeout(() => setIsLoading(false), 2000);
return () => clearTimeout(timer);
}, []);
if (commentIndex === undefined) return null;
2023-06-01 10:43:17 +02:00
return (
commentIndex && 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 ? (
<span className="ttl">
<br />
(
<span className={className}>
</span>
)
</span>
) : (
<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;