From a5adfa7fb2b3772f7c1050e1b18d4a74dd7fb3b8 Mon Sep 17 00:00:00 2001
From: Ivan <45982459+ivntsng@users.noreply.github.com>
Date: Mon, 28 Oct 2024 19:35:33 +0800
Subject: [PATCH] Added description editing feature with markdown (#513)
* Added description editing feature with markdown
* Resolved issue and removed unnecessary console logs
---
.../components/listing/ListingDescription.tsx | 52 ++++----
.../src/components/products/ProductPage.tsx | 125 +++++++++++++++++-
frontend/src/hooks/useAuth.tsx | 2 -
3 files changed, 146 insertions(+), 33 deletions(-)
diff --git a/frontend/src/components/listing/ListingDescription.tsx b/frontend/src/components/listing/ListingDescription.tsx
index 3fb72ca7..572b5bb9 100644
--- a/frontend/src/components/listing/ListingDescription.tsx
+++ b/frontend/src/components/listing/ListingDescription.tsx
@@ -11,22 +11,29 @@ import remarkGfm from "remark-gfm";
interface RenderDescriptionProps {
description: string;
+ onImageClick?: (src: string, alt: string) => void;
}
-export const RenderDescription = ({ description }: RenderDescriptionProps) => {
- const [imageModal, setImageModal] = useState<[string, string] | null>(null);
-
+export const RenderDescription = ({
+ description,
+ onImageClick,
+}: RenderDescriptionProps) => {
return (
- <>
+
{children}
,
- ul: ({ children }) => ,
+ ul: ({ children }) => (
+
+ ),
ol: ({ children }) => (
{children}
),
- li: ({ children }) => {children},
+ li: ({ children }) => {children},
table: ({ children }) => (
),
@@ -51,7 +58,9 @@ export const RenderDescription = ({ description }: RenderDescriptionProps) => {
{children}
),
- h1: ({ children }) => {children}
,
+ h1: ({ children }) => (
+ {children}
+ ),
h2: ({ children }) => {children}
,
h3: ({ children }) => (
{children}
@@ -62,7 +71,7 @@ export const RenderDescription = ({ description }: RenderDescriptionProps) => {
img: ({ src, alt }) => (
src && setImageModal([src, alt ?? ""])}
+ onClick={() => src && onImageClick?.(src, alt ?? "")}
>
{alt && {alt}}
@@ -72,25 +81,7 @@ export const RenderDescription = ({ description }: RenderDescriptionProps) => {
>
{description}
-
- {imageModal !== null && (
-
setImageModal(null)}
- >
-
e.stopPropagation()}
- >
-
-
-
- )}
- >
+
);
};
@@ -115,6 +106,8 @@ const ListingDescription = (props: Props) => {
const [debouncedDescription, setDebouncedDescription] = useState(
initialDescription ?? "",
);
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ const [imageModal, setImageModal] = useState<[string, string] | null>(null);
useEffect(() => {
const handler = setTimeout(() => {
@@ -177,7 +170,10 @@ const ListingDescription = (props: Props) => {
autoFocus
/>
)}
-
+ setImageModal([src, alt])}
+ />
{edit && (