Update post embed fetching to use new methods (#1916)

* Update post embed fetching to use new methods

* Use session agent
This commit is contained in:
Eric Bailey 2023-11-15 19:09:13 -06:00 committed by GitHub
parent 9bcd00b831
commit f23e9978d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 22 deletions

View file

@ -17,6 +17,7 @@ import {
import {ComposerOpts} from 'state/shell/composer'
import {POST_IMG_MAX} from 'lib/constants'
import {logger} from '#/logger'
import {useGetPost} from '#/state/queries/post'
export function useExternalLinkFetch({
setQuote,
@ -27,6 +28,7 @@ export function useExternalLinkFetch({
const [extLink, setExtLink] = useState<apilib.ExternalEmbedDraft | undefined>(
undefined,
)
const getPost = useGetPost()
useEffect(() => {
let aborted = false
@ -38,7 +40,7 @@ export function useExternalLinkFetch({
}
if (!extLink.meta) {
if (isBskyPostUrl(extLink.uri)) {
getPostAsQuote(store, extLink.uri).then(
getPostAsQuote(getPost, extLink.uri).then(
newQuote => {
if (aborted) {
return
@ -48,7 +50,7 @@ export function useExternalLinkFetch({
},
err => {
logger.error('Failed to fetch post for quote embedding', {
error: err,
error: err.toString(),
})
setExtLink(undefined)
},
@ -132,7 +134,7 @@ export function useExternalLinkFetch({
})
}
return cleanup
}, [store, extLink, setQuote])
}, [store, extLink, setQuote, getPost])
return {extLink, setExtLink}
}