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.

Make previews section editable

Steven Teya9e913642055
diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsx
index c376d7e6c5..a737b9c0d7 100644
--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx
@@ -254,7 +254,7 @@ function AddEditLinkModal({
} else {
setGeneratingMetatags(false);
}
- }, [debouncedUrl, password, showAddEditLinkModal, proxy]);
+ }, [debouncedUrl, password, showAddEditLinkModal]);
const endpoint = useMemo(() => {
if (props?.key) {
@@ -292,18 +292,13 @@ function AddEditLinkModal({
*/
if (
!showAddEditLinkModal ||
+ generatingMetatags ||
saving ||
keyError ||
urlError ||
(props &&
Object.entries(props).every(([key, value]) => {
- // If the key is "title" or "description" and proxy is not enabled, return true (skip the check)
- if (
- (key === "title" || key === "description" || key === "image") &&
- !proxy
- ) {
- return true;
- } else if (key === "geo") {
+ if (key === "geo") {
const equalGeo = deepEqual(props.geo as object, data.geo as object);
return equalGeo;
}
@@ -315,7 +310,15 @@ function AddEditLinkModal({
} else {
return false;
}
- }, [showAddEditLinkModal, saving, keyError, urlError, props, data]);
+ }, [
+ showAddEditLinkModal,
+ generatingMetatags,
+ saving,
+ keyError,
+ urlError,
+ props,
+ data,
+ ]);
const randomIdx = Math.floor(Math.random() * 100);
diff --git a/apps/web/ui/modals/add-edit-link-modal/og-section.tsx b/apps/web/ui/modals/add-edit-link-modal/og-section.tsx
index ca4605f9c9..3a4f51418d 100644
--- a/apps/web/ui/modals/add-edit-link-modal/og-section.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/og-section.tsx
@@ -24,12 +24,10 @@ import { usePromptModal } from "../prompt-modal";
import UnsplashSearch from "./unsplash-search";
export default function OGSection({
- props,
data,
setData,
generatingMetatags,
}: {
- props?: LinkProps;
data: LinkProps;
setData: Dispatch<SetStateAction<LinkProps>>;
generatingMetatags: boolean;
@@ -142,18 +140,6 @@ export default function OGSection({
}
}, [completionDescription]);
- useEffect(() => {
- if (proxy && props) {
- // if custom OG is enabled
- setData((prev) => ({
- ...prev,
- title: props.title || title,
- description: props.description || description,
- image: props.image || image,
- }));
- }
- }, [proxy]);
-
const [resizingImage, setResizingImage] = useState(false);
const [cooldown, setCooldown] = useState(false);
diff --git a/apps/web/ui/modals/add-edit-link-modal/preview.tsx b/apps/web/ui/modals/add-edit-link-modal/preview.tsx
index 69e652711e..76f4c19ef2 100644
--- a/apps/web/ui/modals/add-edit-link-modal/preview.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/preview.tsx
@@ -24,6 +24,7 @@ import {
useRef,
useState,
} from "react";
+import ReactTextareaAutosize from "react-textarea-autosize";
import { toast } from "sonner";
import { useDebounce } from "use-debounce";
import { usePromptModal } from "../prompt-modal";
@@ -76,7 +77,7 @@ export default function Preview({
onImageChange={onImageChange}
generatingMetatags={generatingMetatags}
/>
- {title && (
+ {(title || title === "") && (
<div className="absolute bottom-2 left-2 rounded-md bg-[#414142] px-1.5 py-px">
<h3 className="max-w-sm truncate text-sm text-white">
{title}
@@ -119,17 +120,34 @@ export default function Preview({
) : (
<div className="mb-1 h-4 w-24 rounded-md bg-gray-200" />
)}
- {title ? (
- <h3 className="truncate font-semibold text-[#1d2129]">
- {title}
- </h3>
+ {title || title === "" ? (
+ <input
+ className="truncate border-none bg-transparent p-0 font-semibold text-[#1d2129] outline-none focus:ring-0"
+ value={title}
+ onChange={(e) => {
+ setData((prev) => ({
+ ...prev,
+ title: e.currentTarget.value,
+ proxy: true,
+ }));
+ }}
+ />
) : (
<div className="mb-1 h-5 w-full rounded-md bg-gray-200" />
)}
- {description ? (
- <p className="line-clamp-2 text-sm text-[#606770]">
- {description}
- </p>
+ {description || description === "" ? (
+ <ReactTextareaAutosize
+ className="mb-1 line-clamp-2 w-full resize-none rounded-md border-none bg-gray-200 bg-transparent p-0 text-sm text-[#606770] outline-none focus:ring-0"
+ value={description}
+ maxRows={2}
+ onChange={(e) => {
+ setData((prev) => ({
+ ...prev,
+ description: e.currentTarget.value,
+ proxy: true,
+ }));
+ }}
+ />
) : (
<div className="grid gap-2">
<div className="h-4 w-full rounded-md bg-gray-200" />
@@ -163,10 +181,18 @@ export default function Preview({
generatingMetatags={generatingMetatags}
/>
<div className="grid gap-1 border-t border-gray-300 bg-white p-3">
- {title ? (
- <h3 className="truncate font-semibold text-[#000000E6]">
- {title}
- </h3>
+ {title || title === "" ? (
+ <input
+ className="truncate border-none bg-transparent p-0 font-semibold text-[#000000E6] outline-none focus:ring-0"
+ value={title}
+ onChange={(e) => {
+ setData((prev) => ({
+ ...prev,
+ title: e.currentTarget.value,
+ proxy: true,
+ }));
+ }}
+ />
) : (
<div className="mb-1 h-5 w-full rounded-md bg-gray-200" />
)}