-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathPanelRight.tsx
More file actions
68 lines (60 loc) · 2.55 KB
/
PanelRight.tsx
File metadata and controls
68 lines (60 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import React, { useEffect, useState } from "react";
import PanelToolbar from "../../Hooks/usePanelHooks.tsx";
import DocumentViewer from '../../Components/DocumentViewer/DocumentViewer.tsx'
import { useDispatch, useSelector, shallowEqual } from 'react-redux';
import { AppDispatch, RootState } from '../../store';
import { fetchContentFileData } from '../../store/slices/rightPanelSlice'
import { bundleIcon, ChevronDoubleLeft20Filled, ChevronDoubleLeft20Regular } from "@fluentui/react-icons";
import { Button } from "@fluentui/react-components";
const ChevronDoubleLeft = bundleIcon(ChevronDoubleLeft20Regular, ChevronDoubleLeft20Filled);
interface PanelRightProps {
togglePanel: (panel: string) => void;
}
const PanelRight: React.FC<PanelRightProps> = ({ togglePanel }) => {
const dispatch = useDispatch<AppDispatch>();
const [fileData, setFileData] = useState({ 'urlWithSasToken': '', 'mimeType': '' })
const store = useSelector((state: RootState) => ({
processId: state.leftPanel.processId,
fileHeaders: state.rightPanel.fileHeaders,
blobURL: state.rightPanel.blobURL,
rLoader: state.rightPanel.rLoader,
fileResponse: state.rightPanel.fileResponse
}), shallowEqual);
const isBlobExists = () => {
const isfileExists = store.fileResponse.find(i => i.processId == store.processId)
return isfileExists;
}
useEffect(() => {
if (store.processId != null && store.processId != '' && !isBlobExists()) {
dispatch(fetchContentFileData({ processId: store.processId }))
}
}, [store.processId])
useEffect(() => {
const isExists = isBlobExists();
if (store.fileResponse.length > 0 && isExists && isExists.processId == store.processId) {
setFileData({ 'urlWithSasToken': isExists.blobURL, 'mimeType': isExists.headers['content-type'] })
} else {
setFileData({ 'urlWithSasToken': '', 'mimeType': '' })
}
}, [store.processId, store.fileResponse])
return (
<div className="pr panelRight">
<PanelToolbar icon={null} header="Source Document">
<Button icon={<ChevronDoubleLeft />} title="Collapse Panel" onClick={() => togglePanel('Right')} />
</PanelToolbar>
<div className="panelRightContent">
{
store.rLoader ? <div className={"right-loader"}><p>Loading...</p></div>
:
<DocumentViewer
className="fullHeight"
metadata={{ mimeType: fileData.mimeType }}
urlWithSasToken={fileData.urlWithSasToken}
iframeKey={1}
/>
}
</div>
</div>
);
};
export default PanelRight;