fix: removed unused stuff

This commit is contained in:
Palanikannan M
2024-09-12 15:09:22 +05:30
parent 8eaf6ed0de
commit d5a1d4e26a
3 changed files with 21 additions and 10 deletions

View File

@@ -1,8 +1,9 @@
import { UploadImage, DeleteImage, RestoreImage } from "@/types";
import { mergeAttributes, Range } from "@tiptap/core";
import { Image } from "@tiptap/extension-image";
import { ReactNodeViewRenderer } from "@tiptap/react";
import { v4 as uuidv4 } from "uuid";
import { UploadImage, DeleteImage, RestoreImage } from "@/types";
import { UploadImageExtensionStorage } from "../image-upload";
import { ImageUpload } from "../image-upload/view";
@@ -108,9 +109,16 @@ export const ImageBlock = ({
event: props.event,
});
}
return commands.insertContent(
`<image-block data-type="${this.name}" id="${fileId}" ${props?.file ? `data-file="${props.file}"` : ""} />`
);
const attributes = {
"data-type": this.name,
id: fileId,
"data-file": props?.file ? `data-file="${props.file}"` : "",
};
return commands.insertContent({
type: this.name,
attrs: attributes,
});
},
uploadImage: (file: File) => async () => {
const fileUrl = await uploadFile(file);

View File

@@ -21,7 +21,6 @@ export const ImageUpload: React.FC<ImageUploadProps> = ({ getPos, editor, node,
const fileInputRef = useRef<HTMLInputElement>(null);
const hasTriggeredFilePickerRef = useRef(false);
const [isUploaded, setIsUploaded] = useState(!!node.attrs.src);
const [uploadedImageUrl, setUploadedImageUrl] = useState("");
const id = node.attrs.id as string;
const editorStorage = editor.storage.imageBlock as UploadImageExtensionStorage | undefined;
@@ -34,9 +33,8 @@ export const ImageUpload: React.FC<ImageUploadProps> = ({ getPos, editor, node,
const onUpload = useCallback(
(url: string) => {
if (url) {
setUploadedImageUrl(url);
setIsUploaded(true);
// Update the node attributes with the new image URL
// Update the node view's src attribute
updateAttributes({ src: url });
editorStorage?.fileMap.delete(id);
}
@@ -99,7 +97,13 @@ export const ImageUpload: React.FC<ImageUploadProps> = ({ getPos, editor, node,
updateAttributes={updateAttributes}
/>
) : (
<ImageUploader onUpload={onUpload} editor={editor} fileInputRef={fileInputRef} existingFile={existingFile} />
<ImageUploader
onUpload={onUpload}
editor={editor}
fileInputRef={fileInputRef}
existingFile={existingFile}
id={id}
/>
)}
</div>
</NodeViewWrapper>

View File

@@ -34,10 +34,9 @@ import {
toggleHeadingFour,
toggleHeadingFive,
toggleHeadingSix,
insertImageCommand,
} from "@/helpers/editor-commands";
// types
import { CommandProps, ISlashCommandItem, UploadImage } from "@/types";
import { CommandProps, ISlashCommandItem } from "@/types";
interface CommandItemProps {
key: string;