import { NodeViewWrapper } from '@tiptap/react' import React, { useEffect } from 'react' import styled from 'styled-components' import { Resizable } from 're-resizable' import { AlertTriangle, Image, Loader } from 'lucide-react' import { uploadNewImageFile } from '../../../../../services/blocks/Image/images' import { UploadIcon } from '@radix-ui/react-icons' import { getActivityBlockMediaDirectory } from '@services/media/media' import { useOrg } from '@components/Contexts/OrgContext' import { useCourse } from '@components/Contexts/CourseContext' import { useEditorProvider } from '@components/Contexts/Editor/EditorContext' function ImageBlockComponent(props: any) { const org = useOrg() as any const course = useCourse() as any const editorState = useEditorProvider() as any const isEditable = editorState.isEditable const [image, setImage] = React.useState(null) const [isLoading, setIsLoading] = React.useState(false) const [blockObject, setblockObject] = React.useState( props.node.attrs.blockObject ) const [imageSize, setImageSize] = React.useState({ width: props.node.attrs.size ? props.node.attrs.size.width : 300, }) const fileId = blockObject ? `${blockObject.content.file_id}.${blockObject.content.file_format}` : null const handleImageChange = (event: React.ChangeEvent) => { setImage(event.target.files[0]) } const handleSubmit = async (e: any) => { e.preventDefault() setIsLoading(true) let object = await uploadNewImageFile( image, props.extension.options.activity.activity_uuid ) setIsLoading(false) setblockObject(object) props.updateAttributes({ blockObject: object, size: imageSize, }) } useEffect(() => {}, [course, org]) return ( {!blockObject && isEditable && ( {isLoading ? ( ) : ( <>
)}
)} {blockObject && ( { props.updateAttributes({ size: { width: imageSize.width + d.width, }, }) setImageSize({ width: imageSize.width + d.width, }) }} > )} {isLoading && (
)}
) } export default ImageBlockComponent const BlockImageWrapper = styled.div` align-items: center; justify-content: center; text-align: center; font-size: 14px; ` const BlockImage = styled.div` display: flex; // center align-items: center; justify-content: center; text-align: center; font-size: 14px; `