diff --git a/README.md b/README.md index a93b4f0..e447676 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,15 @@ ## Introduction +![GCI Badge](https://img.shields.io/badge/Google%20Code%20In-JBoss%20Community-red?style=flatr&labelColor=fdb900) +### React Online Editor to View,Edit Files stored on Local Storage -In this project, create a react app to support online editor to view and edit a file using intelisense +## Tech Stack +* Reactjs +* Ace editor +* file-saver +* css -for example: we can use npm `react-ace` - https://www.npmjs.com/package/react-ace +## How to Run +* Run ***npm start*** in the main directory( make sure you install the node modules first using ***npm install***) + +## Video Demo - [Youtube](https://youtu.be/u3PHpIwsZgk) diff --git a/online-editor/package.json b/online-editor/package.json index 0abcbbc..73c10f0 100644 --- a/online-editor/package.json +++ b/online-editor/package.json @@ -3,7 +3,11 @@ "version": "0.1.0", "private": true, "dependencies": { + "bootstrap": "^4.4.1", + "file-saver": "^2.0.2", "react": "^16.12.0", + "react-ace": "^8.0.0", + "react-bootstrap": "^1.0.0-beta.16", "react-dom": "^16.12.0", "react-scripts": "3.2.0" }, diff --git a/online-editor/public/index.html b/online-editor/public/index.html index c240d2c..d629a1d 100644 --- a/online-editor/public/index.html +++ b/online-editor/public/index.html @@ -7,7 +7,7 @@ + + + + + - React App + Online Text Editor diff --git a/online-editor/src/App.css b/online-editor/src/App.css index afc3885..4931613 100644 --- a/online-editor/src/App.css +++ b/online-editor/src/App.css @@ -1,22 +1,3 @@ .App { text-align: center; } - -.App-logo { - height: 40vmin; -} - -.App-header { - background-color: #282c34; - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); - color: white; -} - -.App-link { - color: #09d3ac; -} diff --git a/online-editor/src/App.js b/online-editor/src/App.js index ce9cbd2..f54192e 100644 --- a/online-editor/src/App.js +++ b/online-editor/src/App.js @@ -1,24 +1,13 @@ import React from 'react'; import logo from './logo.svg'; import './App.css'; +import Home from './components/Home.js'; +import 'bootstrap/dist/css/bootstrap.min.css'; function App() { return ( -
-
- logo -

- Edit src/App.js and save to reload. -

- - Learn React - -
+
+
); } diff --git a/online-editor/src/components/Home.js b/online-editor/src/components/Home.js new file mode 100644 index 0000000..e0f54aa --- /dev/null +++ b/online-editor/src/components/Home.js @@ -0,0 +1,160 @@ +// Imports +import React, { useState } from 'react'; +import './css/home.css'; +import AceEditor from "react-ace"; +import FileSaver from 'file-saver'; + +// Modes +import 'ace-builds/src-min-noconflict/ext-searchbox'; +import "ace-builds/src-noconflict/mode-java"; +import "ace-builds/src-noconflict/mode-html"; +import "ace-builds/src-noconflict/mode-python"; +import "ace-builds/src-noconflict/mode-json"; +import "ace-builds/src-noconflict/mode-xml"; +import "ace-builds/src-noconflict/mode-golang"; +import "ace-builds/src-noconflict/mode-css"; + +// Themes +import "ace-builds/src-noconflict/theme-github"; +import "ace-builds/src-noconflict/theme-monokai"; +import "ace-builds/src-noconflict/theme-terminal"; + +export default function Home() { + + // State + const [fileContent, setFileContent] = useState(""); + const [file,setFile] = useState(); + const [isChanged,set_isChange] = useState(false); + const [fileType,setType] = useState(""); + const [fontSize,setFontSize] = useState("18px"); + const [theme,setTheme] = useState("monokai"); + + // On Changing the value in the editor + const onValueChange = value =>{ + set_isChange(value ? true : false) + setFileContent(value); + } + + // Set File type + const setFileType = type =>{ + + // Remove the prefix + if(type == "text/html" || type == "text/plain"){ + setType(type.substring(5)); + } + // .py .java files have type written like this "text/-xjava" + else{ + setType(type.substring(7)); + } + } + + // On File Upload + const onFileUpload = event =>{ + + // Get the file + let read = event.target.files[0]; + setFile(read); + + // Initiate File Reader + const reader = new FileReader(); + + // On Load, set state fileContent to the content in the file + reader.onload = function(e){ + let content = reader.result; + setFileContent(content); + set_isChange(true); + setFileType(read.type); + } + + // Read content in the file as text + reader.readAsText(read); + } + + // On Clicking Download + const downloadFile = () => { + + // Encode the content into text + let blob = new Blob([ new TextEncoder().encode(fileContent) ],{type: "text/plain"}); + + // Different Downloads for File which is created from editor and file which is uploaded + file ? FileSaver.saveAs(blob,file.name) : FileSaver.saveAs(blob,"sample." + fileType); + } + + // Customizations for editor + const modeChange = e =>{ + setType(e.target.value); + } + const themeChange = e =>{ + setTheme(e.target.value); + } + const sizeChange = e =>{ + setFontSize(e.target.value); + } + + // Data for customizations + const modes = ['txt','java','javascript','python','html','markdown','xml','golang','css']; + const themes = ['monokai','github','terminal']; + const sizes = ['18px','24px','28px','32px','40px']; + + return ( +
+
+ +
+
+
+ + + +
+
+

Online Text Editor

+
+
+ + + + + + +
+ +
+ +
+ +
+ +
+
+
+ ); +} diff --git a/online-editor/src/components/css/home.css b/online-editor/src/components/css/home.css new file mode 100644 index 0000000..fe2d343 --- /dev/null +++ b/online-editor/src/components/css/home.css @@ -0,0 +1,64 @@ +*{ + cursor: url('../icons/cursor.png'), auto; +} +.title{ + font-family: 'Comfortaa', cursive; + font-size: 55px; + font-weight: bold; + color: #00C8F9; + text-align: center; +} +.Main{ + padding: 100px; +} +.upload { + display: inline-block; + width: 20%; + padding-top:60px; + height: 50px; + overflow: hidden; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + background: url('../icons/icon.png') center center no-repeat; + border-radius: 20px; + background-size: 50px 50px; +} +.download{ + margin-left: 10px; + border: none; + display: inline-block; + width: 20%; + padding-top:60px; + height: 50px; + overflow: hidden; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + background: url('../icons/icon2.png') center center no-repeat; + border-radius: 20px; + background-size: 50px 30px; +} + +.editor{ + padding: 5px; + background-color: #00C8F9; +} +.tools{ + font-weight: bold; + font-family: 'Comfortaa', cursive; + color: #00C8F9; +} + +.mode{ + margin-left:10px; + font-weight:bold; + padding:10px; + border: 1px solid #00C8F9; + color: #00C8F9; + background-color: #232323; +} + +.mode-option{ + font-weight: bold; +} diff --git a/online-editor/src/components/icons/cursor-button.png b/online-editor/src/components/icons/cursor-button.png new file mode 100644 index 0000000..ac0f593 Binary files /dev/null and b/online-editor/src/components/icons/cursor-button.png differ diff --git a/online-editor/src/components/icons/cursor.png b/online-editor/src/components/icons/cursor.png new file mode 100644 index 0000000..f7bb2fb Binary files /dev/null and b/online-editor/src/components/icons/cursor.png differ diff --git a/online-editor/src/components/icons/icon.png b/online-editor/src/components/icons/icon.png new file mode 100644 index 0000000..9f82a49 Binary files /dev/null and b/online-editor/src/components/icons/icon.png differ diff --git a/online-editor/src/components/icons/icon2.png b/online-editor/src/components/icons/icon2.png new file mode 100644 index 0000000..c75ca5c Binary files /dev/null and b/online-editor/src/components/icons/icon2.png differ diff --git a/online-editor/src/icon.png b/online-editor/src/icon.png new file mode 100644 index 0000000..a731806 Binary files /dev/null and b/online-editor/src/icon.png differ