({
squad,
className,
onPostSuccess,
post,
moderated,
isPostingOnMySource = false,
initialUrl,
initialCommentary,
}: ShareLinkProps)
| 39 | }; |
| 40 | |
| 41 | export function ShareLink({ |
| 42 | squad, |
| 43 | className, |
| 44 | onPostSuccess, |
| 45 | post, |
| 46 | moderated, |
| 47 | isPostingOnMySource = false, |
| 48 | initialUrl, |
| 49 | initialCommentary, |
| 50 | }: ShareLinkProps): ReactElement { |
| 51 | const fetchedPost = post || moderated; |
| 52 | const isCreatingPost = !fetchedPost; |
| 53 | |
| 54 | const { showPrompt } = usePrompt(); |
| 55 | const { push } = useRouter(); |
| 56 | const { displayToast } = useToastNotification(); |
| 57 | const { onSubmitForm, isPosting: isPendingCreation } = useWritePostContext(); |
| 58 | |
| 59 | const [commentary, setCommentary] = useState(() => { |
| 60 | if (fetchedPost?.sharedPost) { |
| 61 | return fetchedPost.title; |
| 62 | } |
| 63 | |
| 64 | if (fetchedPost) { |
| 65 | return fetchedPost.content; |
| 66 | } |
| 67 | |
| 68 | return initialCommentary ?? ''; |
| 69 | }); |
| 70 | |
| 71 | useEffect(() => { |
| 72 | if (!fetchedPost?.sharedPost) { |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | if (fetchedPost.title !== fetchedPost.sharedPost.title) { |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | if (commentary !== fetchedPost.sharedPost.title) { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | setCommentary(''); |
| 85 | }, [commentary, fetchedPost]); |
| 86 | const { |
| 87 | getLinkPreview, |
| 88 | isLoadingPreview, |
| 89 | preview, |
| 90 | isPosting, |
| 91 | onUpdateSharePost, |
| 92 | onUpdatePreview, |
| 93 | } = usePostToSquad({ |
| 94 | onPostSuccess, |
| 95 | initialPreview: |
| 96 | fetchedPost?.sharedPost || |
| 97 | (moderated && { |
| 98 | url: moderated.externalLink, |
nothing calls this directly
no test coverage detected