MCPcopy Create free account
hub / github.com/dailydotdev/apps / usePostImage

Function usePostImage

packages/shared/src/hooks/post/usePostImage.ts:5–31  ·  view source on GitHub ↗
(post: Post)

Source from the content-addressed store, hash-verified

3import type { Post } from '../../graphql/posts';
4
5export 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 ]);

Callers 6

CollectionList.tsxFile · 0.90
CollectionGrid.tsxFile · 0.90
FreeformList.tsxFile · 0.90
FreeformGrid.tsxFile · 0.90
BoostPostModalFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected