fix(BOOK-478): convert to image vault asset and remove useEffect max depth error

This commit is contained in:
Bianca Widstam
2025-11-27 10:56:32 +01:00
parent 1337e8293f
commit 4a0f8f4721
3 changed files with 34 additions and 30 deletions

View File

@@ -1,5 +1,5 @@
import { Icon, Tooltip, cbModal } from "@contentstack/venus-components"
import React, { PropsWithChildren, useCallback, useEffect } from "react"
import React, { PropsWithChildren, useCallback } from "react"
import EmbedBtn from "./EmbedBtn"
import ImageEditModal from "./ImageEditModal"
@@ -19,6 +19,7 @@ type ImageElementProps = PropsWithChildren & {
rte: IRteParam
}
export function ImageElement({ children, element, rte }: ImageElementProps) {
const isAssetInsertResponse = isInsertResponse(element.attrs)
const imageVaultAsset = getImageVaultAssetFromData(element.attrs)
const isSelected = rte.selection.isSelected()
const isFocused = rte.selection.isFocused()
@@ -62,14 +63,6 @@ export function ImageElement({ children, element, rte }: ImageElementProps) {
})
}, [element, handleMedia])
// The existing data might still be in InsertResponse format if the user has not edited it yet.
// We'll convert it to ImageVaultAsset when the user edits the RTE.
useEffect(() => {
if (isInsertResponse(element.attrs) && imageVaultAsset) {
handleMedia(imageVaultAsset)
}
}, [element.attrs, imageVaultAsset, handleMedia])
const ToolTipButtons = () => {
return (
<div contentEditable={false} className="embed--btn-group">
@@ -91,6 +84,11 @@ export function ImageElement({ children, element, rte }: ImageElementProps) {
if (!imageVaultAsset) {
return <>{children}</>
}
// The existing data might still be in InsertResponse format if the user has not edited it yet.
// We'll convert it to ImageVaultAsset when the user edits the RTE.
if (isAssetInsertResponse) {
handleMedia(imageVaultAsset)
}
return (
<Tooltip