|
1 |
| -import { createElement, Fragment, useCallback, useEffect, useState } from "react"; |
2 |
| -import mammoth from "mammoth"; |
3 |
| -import { DocumentViewerContainerProps } from "typings/DocumentViewerProps"; |
| 1 | +import { createElement, Fragment } from "react"; |
| 2 | +import { DocumentViewerContainerProps } from "../typings/DocumentViewerProps"; |
4 | 3 | import { DocRendererElement } from "./documentRenderer";
|
5 | 4 |
|
6 |
| -const DocxViewer: DocRendererElement = (props: DocumentViewerContainerProps) => { |
7 |
| - const { file } = props; |
8 |
| - const [docxHtml, setDocxHtml] = useState<string | null>(null); |
9 |
| - |
10 |
| - const loadContent = useCallback(async (arrayBuffer: any) => { |
11 |
| - try { |
12 |
| - mammoth |
13 |
| - .convertToHtml( |
14 |
| - { arrayBuffer: arrayBuffer }, |
15 |
| - { |
16 |
| - includeDefaultStyleMap: true |
17 |
| - } |
18 |
| - ) |
19 |
| - .then(result => { |
20 |
| - if (result) { |
21 |
| - setDocxHtml(result.value); |
22 |
| - } |
23 |
| - }); |
24 |
| - } catch (error) {} |
25 |
| - }, []); |
26 |
| - |
27 |
| - useEffect(() => { |
28 |
| - const controller = new AbortController(); |
29 |
| - const { signal } = controller; |
30 |
| - if (file.status === "available" && file.value.uri) { |
31 |
| - fetch(file.value.uri, { method: "GET", signal }) |
32 |
| - .then(res => res.arrayBuffer()) |
33 |
| - .then(response => { |
34 |
| - loadContent(response); |
35 |
| - }); |
36 |
| - } |
37 |
| - |
38 |
| - return () => { |
39 |
| - controller.abort(); |
40 |
| - }; |
41 |
| - }, [file, file?.status, file?.value?.uri]); |
42 |
| - |
43 |
| - return ( |
44 |
| - <Fragment> |
45 |
| - {docxHtml && ( |
46 |
| - <div className="widget-document-viewer-content" dangerouslySetInnerHTML={{ __html: docxHtml }}> |
47 |
| - {/* {docHtmlStr} */} |
48 |
| - </div> |
49 |
| - )} |
50 |
| - </Fragment> |
51 |
| - ); |
| 5 | +const DocxViewer: DocRendererElement = (_props: DocumentViewerContainerProps) => { |
| 6 | + return <Fragment>DOCX</Fragment>; |
52 | 7 | };
|
53 | 8 |
|
54 | 9 | DocxViewer.contentTypes = [
|
|
0 commit comments