(post: Post)
| 3 | import type { Post } from '../../graphql/posts'; |
| 4 | |
| 5 | export const usePostImage = (post: Post): string | undefined => |
| 6 | useMemo(() => { |
| 7 | if (post?.type === PostType.SocialTwitter && post?.subType === 'thread') { |
| 8 | return undefined; |
| 9 | } |
| 10 | |
| 11 | const baseImage = post?.sharedPost?.image ?? post?.image; |
| 12 | |
| 13 | if (baseImage) { |
| 14 | return baseImage; |
| 15 | } |
| 16 | |
| 17 | const parser = new DOMParser(); |
| 18 | const doc = parser.parseFromString(post?.contentHtml ?? '', 'text/html'); |
| 19 | const imgTag = doc.querySelector('img'); |
| 20 | if (imgTag) { |
| 21 | return imgTag.getAttribute('src') ?? undefined; |
| 22 | } |
| 23 | |
| 24 | return undefined; |
| 25 | }, [ |
| 26 | post?.contentHtml, |
| 27 | post?.image, |
| 28 | post?.sharedPost?.image, |
| 29 | post?.subType, |
| 30 | post?.type, |
| 31 | ]); |
no outgoing calls
no test coverage detected