mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: refactor pdfBlock
This commit is contained in:
parent
3715157722
commit
619688676b
9 changed files with 86 additions and 137 deletions
|
|
@ -11,7 +11,7 @@ export default Node.create({
|
|||
|
||||
addAttributes() {
|
||||
return {
|
||||
fileObject: {
|
||||
blockObject: {
|
||||
default: null,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ import { NodeViewWrapper } from "@tiptap/react";
|
|||
import React from "react";
|
||||
import styled from "styled-components";
|
||||
import { AlertCircle, AlertTriangle, FileText, Image, ImagePlus, Info } from "lucide-react";
|
||||
import { getPDFFile, uploadNewPDFFile } from "../../../../services/files/documents";
|
||||
import { getPDFFile, uploadNewPDFFile } from "../../../../services/blocks/Pdf/pdf";
|
||||
import { getBackendUrl } from "../../../../services/config";
|
||||
|
||||
function PDFBlockComponent(props: any) {
|
||||
const [pdf, setPDF] = React.useState(null);
|
||||
const [isLoading, setIsLoading] = React.useState(false);
|
||||
const [fileObject, setfileObject] = React.useState(props.node.attrs.fileObject);
|
||||
const [blockObject, setblockObject] = React.useState(props.node.attrs.blockObject);
|
||||
|
||||
const handlePDFChange = (event: React.ChangeEvent<any>) => {
|
||||
setPDF(event.target.files[0]);
|
||||
|
|
@ -19,15 +19,15 @@ function PDFBlockComponent(props: any) {
|
|||
setIsLoading(true);
|
||||
let object = await uploadNewPDFFile(pdf, props.extension.options.lecture.lecture_id);
|
||||
setIsLoading(false);
|
||||
setfileObject(object);
|
||||
setblockObject(object);
|
||||
props.updateAttributes({
|
||||
fileObject: object,
|
||||
blockObject: object,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<NodeViewWrapper className="block-pdf">
|
||||
{!fileObject && (
|
||||
{!blockObject && (
|
||||
<BlockPDFWrapper contentEditable={props.extension.options.editable}>
|
||||
<div>
|
||||
<FileText color="#e1e0e0" size={50} />
|
||||
|
|
@ -38,11 +38,11 @@ function PDFBlockComponent(props: any) {
|
|||
<button onClick={handleSubmit}>Submit</button>
|
||||
</BlockPDFWrapper>
|
||||
)}
|
||||
{fileObject && (
|
||||
{blockObject && (
|
||||
<BlockPDF>
|
||||
<iframe
|
||||
src={`${getBackendUrl()}content/uploads/files/documents/${props.extension.options.lecture.lecture_id}/${fileObject.file_id}.${
|
||||
fileObject.file_format
|
||||
src={`${getBackendUrl()}content/uploads/files/lectures/${props.extension.options.lecture.lecture_id}/blocks/pdfBlock/${blockObject.block_id}/${blockObject.block_data.file_id}.${
|
||||
blockObject.block_data.file_format
|
||||
}`}
|
||||
/>
|
||||
</BlockPDF>
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ import { AlertTriangle, Image, Video } from "lucide-react";
|
|||
import React from "react";
|
||||
import styled from "styled-components";
|
||||
import { getBackendUrl } from "../../../../services/config";
|
||||
import { uploadNewVideoFile } from "../../../../services/files/video";
|
||||
import { uploadNewVideoFile } from "../../../../services/blocks/Video/video";
|
||||
|
||||
function VideoBlockComponents(props: any) {
|
||||
const [video, setVideo] = React.useState(null);
|
||||
const [isLoading, setIsLoading] = React.useState(false);
|
||||
const [blockObject, setblockObject] = React.useState(props.node.attrs.fileObject);
|
||||
const [blockObject, setblockObject] = React.useState(props.node.attrs.blockObject);
|
||||
|
||||
const handleVideoChange = (event: React.ChangeEvent<any>) => {
|
||||
setVideo(event.target.files[0]);
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ export async function uploadNewPDFFile(file: any, lecture_id: string) {
|
|||
formData.append("file_object", file);
|
||||
formData.append("lecture_id", lecture_id);
|
||||
|
||||
return fetch(`${getAPIUrl()}blocks/document`, RequestBodyForm("POST", formData))
|
||||
return fetch(`${getAPIUrl()}blocks/pdf`, RequestBodyForm("POST", formData))
|
||||
.then((result) => result.json())
|
||||
.catch((error) => console.log("error", error));
|
||||
}
|
||||
|
||||
export async function getPDFFile(file_id: string) {
|
||||
// todo : add course id to url
|
||||
return fetch(`${getAPIUrl()}blocks/document?file_id=${file_id}`, RequestBody("GET", null))
|
||||
return fetch(`${getAPIUrl()}blocks/pdf?file_id=${file_id}`, RequestBody("GET", null))
|
||||
.then((result) => result.json())
|
||||
.catch((error) => console.log("error", error));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue