import { NodeViewWrapper } from '@tiptap/react' import React, { useEffect } from 'react' import { Resizable } from 're-resizable' import { AlertTriangle, Image } from 'lucide-react' import { uploadNewImageFile } from '../../../../../services/blocks/Image/images' 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' import { useLHSession } from '@components/Contexts/LHSessionContext' import { FileUploadBlock, FileUploadBlockButton, FileUploadBlockInput } from '../../FileUploadBlock' import { constructAcceptValue } from '@/lib/constants'; const SUPPORTED_FILES = constructAcceptValue(['image']) function ImageBlockComponent(props: any) { const org = useOrg() as any const course = useCourse() as any const editorState = useEditorProvider() as any const session = useLHSession() as any const access_token = session?.data?.tokens?.access_token; 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,access_token ) setIsLoading(false) setblockObject(object) props.updateAttributes({ blockObject: object, size: imageSize, }) } useEffect(() => {}, [course, org]) return ( {blockObject && ( { props.updateAttributes({ size: { width: imageSize.width + d.width, }, }) setImageSize({ width: imageSize.width + d.width, }) }} > )} {isLoading && (
)}
) } export default ImageBlockComponent