From 0729e5c052dceca39e227b14536f2a26580a1bf9 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 8 Apr 2019 17:36:56 +0300 Subject: embeds in Thread --- vnext/src/components/Thread.js | 99 +++++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 41 deletions(-) (limited to 'vnext/src/components') diff --git a/vnext/src/components/Thread.js b/vnext/src/components/Thread.js index c1dc915b..3fa0ce10 100644 --- a/vnext/src/components/Thread.js +++ b/vnext/src/components/Thread.js @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState, useRef } from 'react'; import ReactRouterPropTypes from 'react-router-prop-types'; import { UserType } from './Types'; @@ -12,10 +12,65 @@ import Spinner from './Spinner'; import Avatar from './Avatar'; import Button from './Button'; -import { format } from '../utils/embed'; +import { format, embedUrls } from '../utils/embed'; import { getMessages, comment, markReadTracker } from '../api'; +function Comment({ msg, visitor, active, setActive }) { + const embedRef = useRef(); + const msgRef = useRef(); + useEffect(() => { + if (msgRef.current) { + embedUrls(msgRef.current.querySelectorAll('a'), embedRef.current); + if (!embedRef.current.hasChildNodes()) { + embedRef.current.style.display = 'none'; + } + } + }, []); + return ( +
+
+ +
+ {msg.replyto > 0 && + ( + {msg.to.uname}  + )} +
+
+
+ { + msg.html ?
+ : +
+

= 0) }} /> +

+ } + { + msg.photo && +

+ +

+ } +
+
+ { + visitor.uid > 0 ? ( + <> + {active === msg.rid || setActive(msg.rid)}>Reply} + {active === msg.rid && Write a comment...} + + ) : ( + <> +  · {active === msg.rid || } + + ) + } +
+
+ ); +} + export default function Thread(props) { const [message, setMessage] = useState(props.location.state || {}); const [replies, setReplies] = useState([]); @@ -87,45 +142,7 @@ export default function Thread(props) { { !loading ? replies.map((msg) => (
  • -
    -
    - -
    - {msg.replyto > 0 && - ( - {msg.to.uname}  - )} -
    -
    -
    - { - msg.html ?
    - : -
    -

    = 0) }} /> -

    - } - { - msg.photo && -

    - -

    - } -
    - { - props.visitor.uid > 0 ? ( - <> - {active === msg.rid || setActive(msg.rid)}>Reply} - {active === msg.rid && Write a comment...} - - ) : ( - <> -  · {active === msg.rid || } - - ) - } -
    -
    +
  • )) : ( <> -- cgit v1.2.3