The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Added Android section and a bunch of small UI optimizations
Steven Tey3b9e41fe0311
diff --git a/components/app/modals/add-edit-link-modal/android-section.tsx b/components/app/modals/add-edit-link-modal/android-section.tsxnew file mode 100644index 0000000000..99b12bd262--- /dev/null+++ b/components/app/modals/add-edit-link-modal/android-section.tsx@@ -0,0 +1,58 @@+import { Dispatch, SetStateAction, useEffect, useState } from "react";+import { LinkProps } from "@/lib/types";+import Switch from "@/components/shared/switch";+import { motion } from "framer-motion";+import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";++export default function AndroidSection({+ props,+ data,+ setData,+}: {+ props: LinkProps;+ data: LinkProps;+ setData: Dispatch<SetStateAction<LinkProps>>;+}) {+ const { android } = data;+ const [enabled, setEnabled] = useState(!!android);+ useEffect(() => {+ if (enabled) {+ // if enabling, add previous android link if exists+ setData({+ ...data,+ android: props?.android || android,+ });+ } else {+ // if disabling, remove android link+ setData({ ...data, android: null });+ }+ }, [enabled]);++ return (+ <div className="border-b border-gray-200 pb-5">+ <div className="flex items-center justify-between">+ <h2 className="text-sm font-medium text-gray-900">Android Targeting</h2>+ <Switch fn={() => setEnabled(!enabled)} checked={enabled} />+ </div>+ {enabled && (+ <motion.div+ className="mt-3 flex rounded-md shadow-sm"+ {...FADE_IN_ANIMATION_SETTINGS}+ >+ <input+ name="android-url"+ id="android-url"+ type="url"+ placeholder="https://play.google.com/store/apps/details?id=com.disney.disneyplus"+ value={android}+ onChange={(e) => {+ setData({ ...data, android: e.target.value });+ }}+ className="block w-full rounded-md border-gray-300 text-sm text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500"+ aria-invalid="true"+ />+ </motion.div>+ )}+ </div>+ );+}diff --git a/components/app/modals/add-edit-link-modal/index.tsx b/components/app/modals/add-edit-link-modal/index.tsxindex 26ecbc7ed8..834ed0a442 100644--- a/components/app/modals/add-edit-link-modal/index.tsx+++ b/components/app/modals/add-edit-link-modal/index.tsx@@ -35,6 +35,7 @@ import PasswordSection from "./password-section";import UTMSection from "./utm-section";import IOSSection from "./ios-section";import Preview from "./preview";+import AndroidSection from "./android-section";function AddEditLinkModal({showAddEditLinkModal,@@ -163,11 +164,12 @@ function AddEditLinkModal({new URL(debouncedUrl);setGeneratingMetatags(true);fetch(`/api/edge/metatags?url=${debouncedUrl}`).then(async (res) => {- setGeneratingMetatags(false);if (res.status === 200) {const results = await res.json();setData((prev) => ({ ...prev, ...results }));}+ // set timeout to prevent flickering+ setTimeout(() => setGeneratingMetatags(false), 200);});} catch (e) {console.log("not a valid url");@@ -205,14 +207,15 @@ function AddEditLinkModal({}}, [props]);- const [scrolled, setScrolled] = useState(false);- const handleScroll = (event: UIEvent<HTMLElement>) => {- if (event.currentTarget.scrollTop > 144) {- setScrolled(true);+ const [atBottom, setAtBottom] = useState(false);+ const handleScroll = useCallback((event: UIEvent<HTMLDivElement>) => {+ const { scrollTop, scrollHeight, clientHeight } = event.currentTarget;+ if (Math.abs(scrollHeight - scrollTop - clientHeight) < 5) {+ setAtBottom(true);} else {- setScrolled(false);+ setAtBottom(false);}- };+ }, []);const saveDisabled = useMemo(() => {/*@@ -244,7 +247,7 @@ function AddEditLinkModal({setShowModal={setShowAddEditLinkModal}closeWithX={true}>- <div className="grid max-h-[80vh] w-full divide-x divide-gray-100 overflow-scroll bg-white shadow-xl transition-all scrollbar-hide sm:max-w-screen-lg sm:grid-cols-2 sm:rounded-2xl sm:border sm:border-gray-200">+ <div className="grid max-h-[min(918px,_90vh)] w-full divide-x divide-gray-100 overflow-scroll bg-white shadow-xl transition-all scrollbar-hide sm:max-w-screen-lg sm:grid-cols-2 sm:rounded-2xl sm:border sm:border-gray-200">{!hideXButton && (<buttononClick={() => setShowAddEditLinkModal(false)}@@ -255,14 +258,10 @@ function AddEditLinkModal({)}<div- className="max-h-[80vh] overflow-scroll rounded-l-2xl"+ className="max-h-[min(918px,_90vh)] overflow-scroll rounded-l-2xl"onScroll={handleScroll}>- <div- className={`${- scrolled ? "py-5" : "pt-10 pb-8"- } sticky top-0 z-10 flex flex-col items-center justify-center space-y-3 border-b border-gray-200 bg-white px-4 transition-all sm:px-16`}- >+ <div className="sticky top-0 z-10 flex flex-col items-center justify-center space-y-3 border-b border-gray-200 bg-white px-4 pt-8 pb-8 transition-all sm:px-16"><BlurImagesrc={logo}alt="Logo"@@ -270,17 +269,15 @@ function AddEditLinkModal({width={20}height={20}/>- {!scrolled && (- <h3 className="text-lg font-medium">- {props- ? `Edit ${linkConstructor({- key: props.key,- domain,- pretty: true,- })}`- : "Add a new link"}- </h3>- )}+ <h3 className="text-lg font-medium">+ {props+ ? `Edit ${linkConstructor({+ key: props.key,+ domain,+ pretty: true,+ })}`+ : "Add a new link"}+ </h3></div><form@@ -452,9 +449,14 @@ function AddEditLinkModal({<PasswordSection {...{ props, data, setData }} /><ExpirationSection {...{ props, data, setData }} /><IOSSection {...{ props, data, setData }} />+ <AndroidSection {...{ props, data, setData }} /></div>- <div className="sticky bottom-0 bg-gray-50 px-4 py-8 sm:px-16">+ <div+ className={`${+ atBottom ? "" : "shadow-[0_-20px_30px_-10px_rgba(0,0,0,0.1)]"+ } sticky bottom-0 bg-gray-50 px-4 py-8 transition-all sm:px-16`}+ ><buttondisabled={saveDisabled}className={`${@@ -474,7 +476,7 @@ function AddEditLinkModal({</div></form></div>- <div className="max-h-[80vh] overflow-scroll rounded-r-2xl">+ <div className="max-h-[min(918px,_90vh)] overflow-scroll rounded-r-2xl"><Preview data={data} generatingMetatags={generatingMetatags} /></div></div>diff --git a/components/app/modals/add-edit-link-modal/og-section.tsx b/components/app/modals/add-edit-link-modal/og-section.tsxindex 35928dda8e..411771468c 100644--- a/components/app/modals/add-edit-link-modal/og-section.tsx+++ b/components/app/modals/add-edit-link-modal/og-section.tsx@@ -57,7 +57,7 @@ export default function OGSection({image: props.image || image,}));}- }, [proxy, props]);+ }, [proxy]);const randomIdx = Math.floor(Math.random() * 100);@@ -93,35 +93,39 @@ export default function OGSection({className="group relative mt-1 flex h-[14rem] cursor-pointer flex-col items-center justify-center rounded-md border border-gray-300 bg-white shadow-sm transition-all hover:bg-gray-50">{generatingMetatags && (- <div className="absolute flex h-full w-full items-center justify-center rounded-md bg-white">+ <div className="absolute z-[5] flex h-full w-full items-center justify-center rounded-md bg-white"><LoadingCircle /></div>)}- {image ? (- image.startsWith("https://res.cloudinary.com") ? (+ <div+ className={`absolute z-[3] flex h-full w-full flex-col items-center justify-center rounded-md transition-all ${+ image+ ? "bg-white/80 opacity-0 hover:opacity-100 hover:backdrop-blur-md"+ : "bg-white opacity-100 hover:bg-gray-50"+ }`}+ >+ <UploadCloud className="h-7 w-7 text-gray-500 transition-all duration-75 group-hover:scale-110 group-active:scale-95" />+ <p className="mt-2 text-sm text-gray-500">+ Recommended: 1200 x 627 pixels+ </p>+ <span className="sr-only">OG Image upload</span>+ </div>+ {image &&+ (image.startsWith("https://res.cloudinary.com") ? (<BlurImagesrc={image}alt="Preview"width={1200}height={627}- className="h-full w-full rounded-md object-cover transition-all hover:brightness-95"+ className="h-full w-full rounded-md object-cover"/>) : (<imgsrc={image}alt="Preview"- className="h-full w-full rounded-md object-cover transition-all hover:brightness-95"+ className="h-full w-full rounded-md object-cover"/>- )- ) : (- <>- <UploadCloud className="h-7 w-7 text-gray-500 transition-all duration-75 group-hover:scale-110 group-active:scale-95" />- <p className="mt-2 text-sm text-gray-500">- Recommended: 1200 x 627 pixels- </p>- <span className="sr-only">OG Image upload</span>- </>- )}+ ))}</label><div className="mt-1 flex rounded-md shadow-sm"><inputdiff --git a/pages/api/edge/metatags.ts b/pages/api/edge/metatags.tsindex 23bfd47adb..5fdf9129b7 100644--- a/pages/api/edge/metatags.ts+++ b/pages/api/edge/metatags.ts@@ -82,7 +82,7 @@ const getMetadataFromUrl = async (url: string) => {}return {- title: obj["title"] || obj["og:title"] || obj["twitter:title"],+ title: obj["og:title"] || obj["twitter:title"] || obj["title"],description:obj["description"] ||obj["og:description"] ||diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex ac431525e3..087f3f52df 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -135,7 +135,7 @@ model Link {password String? // password to access the link – also stored on Redisproxy Boolean @default(false) // Proxy to use custom OG tags – if false, will use OG tags from target url- title String? @db.VarChar(120) // OG title for the link (e.g. Dub - Open-Source Bitly Alternative)+ title String? // OG title for the link (e.g. Dub - Open-Source Bitly Alternative)description String? @db.VarChar(240) // OG description for the link (e.g. An open-source link management tool for modern marketing teams to create, share, and track short links.)image String? // OG image for the link (e.g. https://dub.sh/og-image.png)