Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Fix link preview image

Tim Wilson0a16b2a42005
diff --git a/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/link/form.tsx b/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/link/form.tsx
index 8cc0914152..85c47fa233 100644
--- a/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/link/form.tsx
+++ b/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/link/form.tsx
@@ -62,24 +62,28 @@ export function Form() {
const [debouncedUrl] = useDebounce(getUrlWithoutUTMParams(url), 500);
+ // Update preview image when URL changes
useEffect(() => {
if (debouncedUrl) {
- try {
- // If url is valid, continue to generate metatags, else return null
- new URL(debouncedUrl);
- setLoadingPreviewImage(true);
- fetch(`/api/metatags?url=${debouncedUrl}`).then(async (res) => {
+ const fn = async () => {
+ try {
+ // If url is valid, continue to generate metatags, else return null
+ new URL(debouncedUrl);
+ setLoadingPreviewImage(true);
+ const res = await fetch(`/api/metatags?url=${debouncedUrl}`);
if (res.ok) {
const results = await res.json();
setPreviewImage(results.image);
- }
- });
- } catch (_) {
- setPreviewImage(null);
- } finally {
- // Timeout to prevent flickering
- setTimeout(() => setLoadingPreviewImage(false), 200);
- }
+ } else throw new Error(res.statusText);
+ } catch (_) {
+ setPreviewImage(null);
+ } finally {
+ // Timeout to prevent flickering
+ setTimeout(() => setLoadingPreviewImage(false), 200);
+ }
+ };
+
+ fn();
}
}, [debouncedUrl]);
@@ -158,20 +162,21 @@ export function Form() {
<img
src={previewImage}
alt="Preview"
- className="size-full rounded-[inherit] object-cover"
+ className="relative size-full rounded-[inherit] object-cover"
/>
- ) : loadingPreviewImage ? (
- <div className="absolute inset-0 z-[5] flex items-center justify-center rounded-[inherit] bg-white">
- <LoadingCircle />
- </div>
) : (
- <div className="flex size-full flex-col items-center justify-center space-y-4 bg-white">
+ <div className="relative flex size-full flex-col items-center justify-center space-y-4 bg-white">
<Photo className="h-8 w-8 text-gray-400" />
<p className="text-sm text-gray-400">
Enter a link to generate a preview.
</p>
</div>
)}
+ {loadingPreviewImage && (
+ <div className="absolute inset-0 z-[5] flex items-center justify-center rounded-[inherit] bg-white">
+ <LoadingCircle />
+ </div>
+ )}
</div>
</div>
<Button