-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de0b457
commit a7f8d3a
Showing
10 changed files
with
283 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.CodeMirror { | ||
text-align: left !important; | ||
width: 100vh !important; | ||
height: 100% !important; | ||
max-height: 100vh !important; | ||
} | ||
.CodeMirror-wrap pre { | ||
word-break: break-word; | ||
} | ||
.cm-wrap { | ||
height: 100vh !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { faArrowLeft, faSave } from "@fortawesome/free-solid-svg-icons"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { Button, Col, Row } from "react-bootstrap"; | ||
import { useHistory } from "react-router-dom"; | ||
import { userFileDataUpdate } from "../../../redux/actionCreators/filefoldersActionCreators"; | ||
import { useDispatch } from "react-redux"; | ||
|
||
const Header = ({ data, prevData, currentFile }) => { | ||
const history = useHistory(); | ||
const [update, setUPdate] = useState(data.trim() !== prevData.trim()); | ||
|
||
useEffect(() => { | ||
setUPdate(data.trim() !== prevData.trim()); | ||
}, [prevData]); | ||
|
||
const dispatch = useDispatch(); | ||
const pushItBack = () => { | ||
if (data.trim() !== prevData.trim()) { | ||
if (window.confirm("are your sure to leave without saving data?")) { | ||
history.push( | ||
currentFile.data.parent === "" | ||
? "/dashboard" | ||
: `dashboard/folder/${currentFile.data.parent}` | ||
); | ||
} else { | ||
return; | ||
} | ||
} | ||
}; | ||
const saveFile = () => { | ||
dispatch(userFileDataUpdate(data.trim(), currentFile.docId)); | ||
}; | ||
|
||
return ( | ||
<Row className="px-5 d-flex align-items-center border-bottom mb-3 justify-content-between border-2 py-2 pt-3"> | ||
<Col md={5} className="d-flex align-items-center justify-content-between"> | ||
<h5 className="font-weight-bold"> | ||
{currentFile.data.name} | ||
{update && " [* . Modified]"} | ||
</h5> | ||
</Col> | ||
<Col md={5} className="d-flex align-items-center justify-content-end"> | ||
<Button variant="success" disabled={!update}> | ||
<FontAwesomeIcon icon={faSave} onClick={() => saveFile()} /> | ||
Save | ||
</Button> | ||
| ||
<Button variant="dark" onClick={() => pushItBack()}> | ||
<FontAwesomeIcon icon={faArrowLeft} /> | ||
Go Back | ||
</Button> | ||
</Col> | ||
</Row> | ||
); | ||
}; | ||
|
||
export default Header; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { Col, Row } from "react-bootstrap"; | ||
import { shallowEqual, useDispatch, useSelector } from "react-redux"; | ||
import { useParams } from "react-router-dom"; | ||
import { | ||
getAdminFiles, | ||
getAdminFolders, | ||
getUserFiles, | ||
getUserFolders, | ||
} from "../../../redux/actionCreators/filefoldersActionCreators"; | ||
import "codemirror/lib/codemirror.css"; | ||
import "codemirror/theme/eclipse.css"; | ||
import "codemirror/mode/xml/xml"; | ||
import "codemirror/mode/php/php"; | ||
import "codemirror/mode/javascript/javascript"; | ||
import "codemirror/mode/textile/textile"; | ||
import "codemirror/mode/jsx/jsx"; | ||
import "codemirror/mode/css/css"; | ||
import "codemirror/mode/python/python"; | ||
import "codemirror/mode/clike/clike"; | ||
import { Controlled as CodeMirror } from "react-codemirror2"; | ||
|
||
import "./FileComponent.css"; | ||
import Header from "./Header"; | ||
|
||
const FileComponent = () => { | ||
const { fileId } = useParams(); | ||
|
||
const { isLoading, userId, currentFile, folders } = useSelector( | ||
(state) => ({ | ||
userId: state.auth.userId, | ||
isLoading: state.filefolders.isLoading, | ||
folders: state.filefolders.UserFolders, | ||
currentFile: state.filefolders.userFiles?.find( | ||
(file) => file.docId === fileId | ||
), | ||
}), | ||
shallowEqual | ||
); | ||
const [prevData, setPrevData] = useState(""); | ||
const [data, setData] = useState(""); | ||
|
||
const codes = { | ||
html: "xml", | ||
php: "php", | ||
js: "javascript", | ||
jsx: "jsx", | ||
txt: "textile", | ||
xml: "xml", | ||
css: "css", | ||
c: "clike", | ||
cpp: "clike", | ||
java: "textile", | ||
cs: "clike", | ||
py: "python", | ||
json: "javascript", | ||
}; | ||
|
||
const dispatch = useDispatch(); | ||
|
||
const extension = | ||
currentFile && | ||
currentFile.data.name.split(".")[ | ||
currentFile.data.name.split(".").length - 1 | ||
]; | ||
useEffect(() => { | ||
if (isLoading && !folders && !currentFile) { | ||
dispatch(getAdminFolders()); | ||
dispatch(getAdminFiles()); | ||
dispatch(getUserFolders(userId)); | ||
dispatch(getUserFiles(userId)); | ||
} | ||
|
||
if ( | ||
currentFile && | ||
(currentFile.data.url === "" || | ||
!currentFile.data.name.includes(".jpg") || | ||
!currentFile.data.name.includes(".png") || | ||
!currentFile.data.name.includes(".jpeg") || | ||
!currentFile.data.name.includes(".doc") || | ||
!currentFile.data.name.includes(".ppt") || | ||
!currentFile.data.name.includes(".pptx") || | ||
!currentFile.data.name.includes(".xls") || | ||
!currentFile.data.name.includes(".rar")) | ||
) { | ||
setData(currentFile.data.data); | ||
setPrevData(currentFile.data.data); | ||
} | ||
}, [dispatch, isLoading, currentFile.data.data]); | ||
|
||
if (isLoading) { | ||
return ( | ||
<Row className="m-0 w-100 h-100"> | ||
<Col md={12} className="bg-white m-0"> | ||
<h1 className="text-center my-5">Fetching file...</h1> | ||
</Col> | ||
</Row> | ||
); | ||
} | ||
return ( | ||
<> | ||
{currentFile ? ( | ||
currentFile.data.url === "" || | ||
!currentFile.data.name.includes(".jpg") || | ||
!currentFile.data.name.includes(".png") || | ||
!currentFile.data.name.includes(".jpeg") || | ||
!currentFile.data.name.includes(".doc") || | ||
!currentFile.data.name.includes(".ppt") || | ||
!currentFile.data.name.includes(".pptx") || | ||
!currentFile.data.name.includes(".xls") || | ||
!currentFile.data.name.includes(".rar") ? ( | ||
<> | ||
<Header | ||
currentFile={currentFile} | ||
data={data} | ||
prevData={prevData} | ||
userId={userId} | ||
/> | ||
<Row | ||
className="m-0 w-100 " | ||
style={{ overflowX: "hidden", overflowY: "auto" }} | ||
> | ||
<Col md={12} className="bg-white"> | ||
<CodeMirror | ||
value={data} | ||
options={{ | ||
mode: { | ||
name: codes[extension], | ||
json: extension === "json", | ||
}, | ||
theme: "eclipse", | ||
lineNumbers: true, | ||
inputStyle: "textarea", | ||
autofocus: true, | ||
lineWrapping: true, | ||
}} | ||
onBeforeChange={(editor, data, value) => { | ||
setData(value); | ||
}} | ||
style={{ textAlign: "left !important" }} | ||
/> | ||
</Col> | ||
</Row> | ||
</> | ||
) : ( | ||
<Row className="position-fixed top-0 left-0 m-0 w-100 h-100"> | ||
<Col md={12}>Show File</Col> | ||
</Row> | ||
) | ||
) : ( | ||
<Row className="m-0 w-100 h-100"> | ||
<Col md={12}>File Not Present</Col> | ||
</Row> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default FileComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters