The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
improve short link input
Steven Teyebbda3d8d598
diff --git a/apps/web/ui/links/short-link-input.tsx b/apps/web/ui/links/short-link-input.tsxindex 883973cf88..2c0c60e0ea 100644--- a/apps/web/ui/links/short-link-input.tsx+++ b/apps/web/ui/links/short-link-input.tsx@@ -104,6 +104,18 @@ export const ShortLinkInput = forwardRef<HTMLInputElement, ShortLinkInputProps>(setGeneratingRandomKey(false);};+ const [isFocused, setIsFocused] = useState(false);++ useEffect(() => {+ // generate a random key if:+ // - there is a domain+ // - there is no key+ // - the input is not focused+ if (domain && !key && !isFocused) {+ generateRandomKey();+ }+ }, [domain, key, isFocused]);+const runKeyChecks = async (value: string) => {const res = await fetch(`/api/links/exists?domain=${domain}&key=${value}&workspaceId=${workspaceId}`,@@ -116,6 +128,14 @@ export const ShortLinkInput = forwardRef<HTMLInputElement, ShortLinkInputProps>(}};+ const [debouncedKey] = useDebounce(key, 500);++ useEffect(() => {+ if (debouncedKey) {+ runKeyChecks(debouncedKey);+ }+ }, [debouncedKey]);+const [generatedKeys, setGeneratedKeys] = useState<string[]>(existingLink && key ? [key] : [],);@@ -141,7 +161,6 @@ export const ShortLinkInput = forwardRef<HTMLInputElement, ShortLinkInputProps>(onFinish: (_, completion) => {setGeneratedKeys((prev) => [...prev, completion]);mutateWorkspace();- runKeyChecks(completion);posthog.capture("ai_key_generated", {key: completion,url: data.url,@@ -262,17 +281,8 @@ export const ShortLinkInput = forwardRef<HTMLInputElement, ShortLinkInputProps>("Only letters, numbers, '-', '_', '/', and emojis are allowed.",);}}- onBlur={(e) => {- // if the key is changed, check if key exists- if (e.target.value) {- // no need to check if the link key didn't change (for editing existing links)- if (existingLinkProps?.key === e.target.value) {- return;- } else {- runKeyChecks(e.target.value);- }- }- }}+ onFocus={() => setIsFocused(true)}+ onBlur={() => setIsFocused(false)}disabled={lockKey}autoComplete="off"autoCapitalize="none"diff --git a/apps/web/ui/modals/link-builder/link-preview.tsx b/apps/web/ui/modals/link-builder/link-preview.tsxindex ad6a67db7c..a1584edc21 100644--- a/apps/web/ui/modals/link-builder/link-preview.tsx+++ b/apps/web/ui/modals/link-builder/link-preview.tsx@@ -118,7 +118,9 @@ export function LinkPreview() {checked={proxy}fn={(checked) => setValue("proxy", checked, { shouldDirty: true })}disabledTooltip={- !plan || plan === "free" ? (+ !url ? (+ "Enter a URL to enable custom link previews."+ ) : !plan || plan === "free" ? (<TooltipContenttitle="Custom Link Previews are only available on the Pro plan and above."cta="Upgrade to Pro"diff --git a/apps/web/ui/modals/link-builder/qr-code-preview.tsx b/apps/web/ui/modals/link-builder/qr-code-preview.tsxindex e4416ea5c2..472df9ca49 100644--- a/apps/web/ui/modals/link-builder/qr-code-preview.tsx+++ b/apps/web/ui/modals/link-builder/qr-code-preview.tsx@@ -61,8 +61,8 @@ export function QRCodePreview() {const { LinkQRModal, setShowLinkQRModal } = useLinkQRModal({props: {- key: rawKey,domain: rawDomain,+ key: rawKey,},onSave: (data) => setData(data),});@@ -96,9 +96,6 @@ export function QRCodePreview() {icon={<Pen2 className="mx-px size-4" />}className="absolute right-2 top-2 z-10 h-8 w-fit bg-white px-1.5"onClick={() => setShowLinkQRModal(true)}- disabledTooltip={- key && domain ? undefined : "Enter a short link to customize"- }/>{!isMobile && (<ShimmerDots className="opacity-30 [mask-image:radial-gradient(40%_80%,transparent_50%,black)]" />