diff options
author | Paul Frazee <pfrazee@gmail.com> | 2024-03-19 17:54:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-19 17:54:40 -0700 |
commit | 54f424d0476f7da221b890c9096886b3ca3ac472 (patch) | |
tree | c45d1ee2ef89978b8bf064cec0d94f9e37b53185 /src/view/com/composer/useExternalLinkFetch.e2e.ts | |
parent | a90566d86439a96509967f522069a4be729dfc1b (diff) | |
download | voidsky-54f424d0476f7da221b890c9096886b3ca3ac472.tar.zst |
Various e2e test fixes (#3284)
* Just use the first picture every time * Add missing testIDs * Various test fixes * Use simplified link fetcher for e2e * Disable tests for now-n * Update test-env creation
Diffstat (limited to 'src/view/com/composer/useExternalLinkFetch.e2e.ts')
-rw-r--r-- | src/view/com/composer/useExternalLinkFetch.e2e.ts | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/view/com/composer/useExternalLinkFetch.e2e.ts b/src/view/com/composer/useExternalLinkFetch.e2e.ts new file mode 100644 index 000000000..ccf619db3 --- /dev/null +++ b/src/view/com/composer/useExternalLinkFetch.e2e.ts @@ -0,0 +1,45 @@ +import {useState, useEffect} from 'react' +import * as apilib from 'lib/api/index' +import {getLinkMeta} from 'lib/link-meta/link-meta' +import {ComposerOpts} from 'state/shell/composer' +import {getAgent} from '#/state/session' + +export function useExternalLinkFetch({}: { + setQuote: (opts: ComposerOpts['quote']) => void +}) { + const [extLink, setExtLink] = useState<apilib.ExternalEmbedDraft | undefined>( + undefined, + ) + + useEffect(() => { + let aborted = false + const cleanup = () => { + aborted = true + } + if (!extLink) { + return cleanup + } + if (!extLink.meta) { + getLinkMeta(getAgent(), extLink.uri).then(meta => { + if (aborted) { + return + } + setExtLink({ + uri: extLink.uri, + isLoading: !!meta.image, + meta, + }) + }) + return cleanup + } + if (extLink.isLoading) { + setExtLink({ + ...extLink, + isLoading: false, // done + }) + } + return cleanup + }, [extLink]) + + return {extLink, setExtLink} +} |