From 7b83d10013a32976434ed7d7600219308d6c877f Mon Sep 17 00:00:00 2001 From: Duc Ho Date: Thu, 3 Oct 2024 19:10:20 -0600 Subject: [PATCH] Finished mockup editting mode for Media Card --- package.json | 1 + src/components/MediaCard.tsx | 128 +++++++++++++++++++++++-- src/index.css | 4 + src/main.tsx | 10 +- src/routes/test/MediaCardTestRoute.tsx | 31 ++++-- tailwind.config.cjs | 3 + 6 files changed, 157 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index c356599..fe341a8 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@types/node": "^20.11.27", "@types/react": "^18.2.51", "@types/react-dom": "^18.0.10", + "@types/react-grid-layout": "^1.3.5", "@types/react-test-renderer": "^18.0.0", "@vitejs/plugin-react": "^3.1.0", "autoprefixer": "^10.4.13", diff --git a/src/components/MediaCard.tsx b/src/components/MediaCard.tsx index 44f6787..3eee06c 100644 --- a/src/components/MediaCard.tsx +++ b/src/components/MediaCard.tsx @@ -1,11 +1,15 @@ import { displayToast } from "@/utils"; -import { Copy } from "@phosphor-icons/react"; +import { Copy, Check, WarningCircle } from "@phosphor-icons/react"; +import { useLayoutEffect, useRef, useState } from "react"; +import Button from "./Button"; +import clsx from "clsx"; interface MediaCardProps { src: string; - title: string; + caption?: string | null; date: Date; id: number; + selectable?: boolean; } const options: Intl.DateTimeFormatOptions = { @@ -14,22 +18,132 @@ const options: Intl.DateTimeFormatOptions = { day: "numeric", }; -function MediaCard({ src, title, date, id }: MediaCardProps) { +function MediaCard({ + src, + caption, + date, + id, + selectable = false, +}: MediaCardProps) { + const [isEditingCaption, setIsEditingCaption] = useState(false); + const [newCaption, setNewCaption] = useState( + caption, + ); + const [isSelected, setIsSelected] = useState(false); + const [isHovered, setIsHovered] = useState(false); + const [temporaryCaption, setTemporaryCaption] = useState(caption); + const [error, setError] = useState(null); + const captionTextAreaRef = useRef(null); + const copyHandler = () => { navigator.clipboard.writeText(id.toString()); displayToast("ID Copied!", "success"); }; + + useLayoutEffect(() => { + if (captionTextAreaRef.current) { + captionTextAreaRef.current.style.height = "auto"; + const scrollHeight = captionTextAreaRef.current.scrollHeight; + captionTextAreaRef.current.style.height = `${scrollHeight + 16}px`; + } + }, [temporaryCaption, newCaption, caption, isEditingCaption]); + return ( -
-
+
setIsHovered(true)} + onMouseLeave={() => setIsHovered(false)} + > + {selectable && ( + setIsSelected(!isSelected)} + > + {isSelected && ( + + )} + + )} +
Image
-

{title}

+ {!isEditingCaption ? ( +
setIsEditingCaption(true)} + > + {newCaption} +
+ ) : ( +
+