diff --git a/src/assets/spoiler-dots-black.png b/src/assets/spoiler-dots-black.png index bb2e62c6..9d5c06f3 100644 Binary files a/src/assets/spoiler-dots-black.png and b/src/assets/spoiler-dots-black.png differ diff --git a/src/assets/spoiler-dots-white.png b/src/assets/spoiler-dots-white.png index efce3710..366c0de7 100644 Binary files a/src/assets/spoiler-dots-white.png and b/src/assets/spoiler-dots-white.png differ diff --git a/src/components/common/spoiler/Spoiler.scss b/src/components/common/spoiler/Spoiler.scss index 68cc1981..65e68034 100644 --- a/src/components/common/spoiler/Spoiler.scss +++ b/src/components/common/spoiler/Spoiler.scss @@ -27,7 +27,7 @@ } &--concealed &__content { - visibility: hidden; + user-select: none; opacity: 0; } } diff --git a/src/components/common/spoiler/Spoiler.tsx b/src/components/common/spoiler/Spoiler.tsx index f732ac9c..118566d1 100644 --- a/src/components/common/spoiler/Spoiler.tsx +++ b/src/components/common/spoiler/Spoiler.tsx @@ -13,7 +13,12 @@ type OwnProps = { messageId?: number; }; -const spoilersByMessageId: Map = new Map(); +const AUTO_HIDE_TIMEOUT = 5000; // 5s + +const actionsByMessageId: Map = new Map(); const buildClassName = createClassNameBuilder('Spoiler'); @@ -21,30 +26,35 @@ const Spoiler: FC = ({ children, messageId, }) => { - const [isRevealed, reveal] = useFlag(); + const [isRevealed, reveal, conceal] = useFlag(); const handleClick = useCallback((e: ReactMouseEvent) => { e.preventDefault(); e.stopPropagation(); - spoilersByMessageId.get(messageId!)?.forEach((_reveal) => _reveal()); - }, [messageId]); + actionsByMessageId.get(messageId!)?.forEach((actions) => actions.reveal()); + + setTimeout(() => { + actionsByMessageId.get(messageId!)?.forEach((actions) => actions.conceal()); + conceal(); + }, AUTO_HIDE_TIMEOUT); + }, [conceal, messageId]); useEffect(() => { if (!messageId) { return undefined; } - if (spoilersByMessageId.has(messageId)) { - spoilersByMessageId.get(messageId)!.push(reveal); + if (actionsByMessageId.has(messageId)) { + actionsByMessageId.get(messageId)!.push({ reveal, conceal }); } else { - spoilersByMessageId.set(messageId, [reveal]); + actionsByMessageId.set(messageId, [{ reveal, conceal }]); } return () => { - spoilersByMessageId.delete(messageId); + actionsByMessageId.delete(messageId); }; - }, [handleClick, isRevealed, messageId, reveal]); + }, [conceal, handleClick, isRevealed, messageId, reveal]); return (