├── public ├── favicon.png ├── robots.txt └── index.html ├── src ├── assets │ ├── file.png │ ├── close.png │ ├── folder.png │ ├── arrow_up.png │ └── add_new_button.png ├── setupTests.js ├── index.css ├── reportWebVitals.js ├── index.js ├── components │ ├── BreadCrumbs.js │ ├── FileFolder.js │ ├── RenameFile.js │ ├── AddFile.js │ └── App.js └── styles │ ├── App.css │ ├── FileFolder.css │ └── AddFile.css ├── .gitignore ├── .github └── workflows │ └── node.js.yml ├── package.json └── README.md /public/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/slmnsh/cloud-drive/main/public/favicon.png -------------------------------------------------------------------------------- /src/assets/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/slmnsh/cloud-drive/main/src/assets/file.png -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/assets/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/slmnsh/cloud-drive/main/src/assets/close.png -------------------------------------------------------------------------------- /src/assets/folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/slmnsh/cloud-drive/main/src/assets/folder.png -------------------------------------------------------------------------------- /src/assets/arrow_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/slmnsh/cloud-drive/main/src/assets/arrow_up.png -------------------------------------------------------------------------------- /src/assets/add_new_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/slmnsh/cloud-drive/main/src/assets/add_new_button.png -------------------------------------------------------------------------------- /src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", 4 | "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", 5 | "Helvetica Neue", sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = (onPerfEntry) => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import("web-vitals").then( 4 | ({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 5 | getCLS(onPerfEntry); 6 | getFID(onPerfEntry); 7 | getFCP(onPerfEntry); 8 | getLCP(onPerfEntry); 9 | getTTFB(onPerfEntry); 10 | } 11 | ); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import "./index.css"; 4 | import App from "./components/App"; 5 | import reportWebVitals from "./reportWebVitals"; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById("root") 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /src/components/BreadCrumbs.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import "react-dom"; 3 | 4 | export default function BreadCrumbs({ currPath, setCurrPath }) { 5 | return ( 6 |
7 | setCurrPath("/")}>root 8 | {currPath 9 | .split("/") 10 | .filter((x) => x) 11 | .map((path) => ( 12 | 16 | setCurrPath( 17 | currPath.substr( 18 | 0, 19 | currPath.indexOf( 20 | "/", 21 | currPath.indexOf(path) 22 | ) 23 | ) + "/" 24 | ) 25 | } 26 | > 27 | {path} 28 | 29 | ))} 30 |
31 | ); 32 | } 33 | -------------------------------------------------------------------------------- /src/styles/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | display: flex; 3 | flex-direction: column; 4 | } 5 | 6 | header { 7 | display: flex; 8 | align-items: center; 9 | padding: 10px; 10 | margin: 0 20px 20px; 11 | font-size: x-large; 12 | border-bottom: 1px solid lightgray; 13 | } 14 | 15 | header img { 16 | padding: 5px; 17 | margin: 10px; 18 | rotate: 270deg; 19 | opacity: 0.7; 20 | scale: 2; 21 | cursor: pointer; 22 | } 23 | 24 | header img:hover { 25 | filter: brightness(0.5); 26 | } 27 | 28 | header .bread { 29 | display: flex; 30 | align-items: center; 31 | vertical-align: middle; 32 | } 33 | 34 | .file-list { 35 | display: flex; 36 | flex-wrap: wrap; 37 | } 38 | 39 | span { 40 | cursor: pointer; 41 | user-select: none; 42 | border-radius: 10px; 43 | padding: 10px 5px; 44 | margin: 5px; 45 | } 46 | 47 | span:hover { 48 | background-color: lightgray; 49 | } 50 | 51 | .crumb::before { 52 | content: ">"; 53 | margin: 10px 15px 10px 0; 54 | } 55 | -------------------------------------------------------------------------------- /src/styles/FileFolder.css: -------------------------------------------------------------------------------- 1 | .file-folder { 2 | width: 125px; 3 | display: flex; 4 | flex-direction: column; 5 | align-items: center; 6 | justify-content: center; 7 | border-radius: 10px; 8 | } 9 | 10 | .file-folder img { 11 | align-self: auto; 12 | } 13 | 14 | .file-folder div { 15 | text-align: center; 16 | } 17 | 18 | .file-folder:hover { 19 | background-color: lightgray; 20 | } 21 | 22 | .new-file { 23 | align-self: center; 24 | height: min-content; 25 | } 26 | 27 | .new-file:hover { 28 | filter: invert(0.1); 29 | } 30 | 31 | .menu { 32 | background-color: white; 33 | border: 1px solid lightgray; 34 | border-radius: 5px; 35 | padding: 0; 36 | } 37 | 38 | .danger { 39 | color: red; 40 | } 41 | 42 | .menu-item { 43 | text-align: center; 44 | margin: 0; 45 | padding: 15px 20px; 46 | cursor: pointer; 47 | user-select: none; 48 | } 49 | 50 | .menu-item:hover { 51 | background-color: lightgray; 52 | } 53 | 54 | .menu-divider { 55 | background-color: lightgray; 56 | height: 1px; 57 | margin: 0; 58 | } 59 | -------------------------------------------------------------------------------- /.github/workflows/node.js.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Deployment CI 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | strategy: 18 | matrix: 19 | node-version: [16.x] 20 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ 21 | 22 | steps: 23 | - uses: actions/checkout@v2 24 | - name: Use Node.js ${{ matrix.node-version }} 25 | uses: actions/setup-node@v2 26 | with: 27 | node-version: ${{ matrix.node-version }} 28 | cache: 'npm' 29 | - run: npm ci 30 | - run: npm run build --if-present 31 | - name: GitHub Pages action 32 | uses: peaceiris/actions-gh-pages@v3.7.3 33 | with: 34 | github_token: ${{ secrets.GITHUB_TOKEN }} 35 | publish_dir: ./build 36 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "drive", 3 | "version": "0.1.0", 4 | "private": true, 5 | "homepage": ".", 6 | "dependencies": { 7 | "@testing-library/jest-dom": "^5.14.1", 8 | "@testing-library/react": "^11.2.7", 9 | "@testing-library/user-event": "^12.8.3", 10 | "react": "^17.0.2", 11 | "react-contextmenu": "^2.14.0", 12 | "react-dom": "^17.0.2", 13 | "react-modal": "^3.14.3", 14 | "react-scripts": "4.0.3", 15 | "uuid": "^8.3.2", 16 | "web-vitals": "^1.1.2" 17 | }, 18 | "scripts": { 19 | "start": "react-scripts start", 20 | "build": "react-scripts build", 21 | "test": "react-scripts test", 22 | "eject": "react-scripts eject" 23 | }, 24 | "eslintConfig": { 25 | "extends": [ 26 | "react-app", 27 | "react-app/jest" 28 | ] 29 | }, 30 | "browserslist": { 31 | "production": [ 32 | ">0.2%", 33 | "not dead", 34 | "not op_mini all" 35 | ], 36 | "development": [ 37 | "last 1 chrome version", 38 | "last 1 firefox version", 39 | "last 1 safari version" 40 | ] 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/styles/AddFile.css: -------------------------------------------------------------------------------- 1 | form { 2 | display: flex; 3 | flex-direction: column; 4 | width: 300px; 5 | border: 1px solid lightgray; 6 | border-radius: 10px; 7 | box-shadow: 5px 5px 10px lightgrey; 8 | position: absolute; 9 | top: 50%; 10 | left: 50%; 11 | transform: translate(-50%, -50%); 12 | } 13 | 14 | .head { 15 | display: flex; 16 | align-items: center; 17 | justify-content: space-between; 18 | } 19 | 20 | .file-type-selector { 21 | display: flex; 22 | border: 1px solid lightgray; 23 | border-radius: 10px; 24 | cursor: pointer; 25 | user-select: none; 26 | align-self: center; 27 | width: 50%; 28 | margin: 20px; 29 | } 30 | 31 | .file-type { 32 | padding: 10px; 33 | border-radius: 10px; 34 | flex: 1; 35 | text-align: center; 36 | margin: 0; 37 | } 38 | 39 | .selected { 40 | background-color: lightskyblue; 41 | color: white; 42 | } 43 | 44 | input { 45 | padding: 10px; 46 | margin: 10px; 47 | border-radius: 10px; 48 | border: 1px solid transparent; 49 | outline: none; 50 | } 51 | 52 | input[type="submit"] { 53 | background-color: lightskyblue; 54 | color: white; 55 | cursor: pointer; 56 | } 57 | 58 | div { 59 | margin: 10px; 60 | } 61 | 62 | img { 63 | height: 15px; 64 | width: 15px; 65 | align-self: flex-end; 66 | padding: 15px; 67 | } 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cloud Drive Frontend 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm run build` 18 | 19 | Builds the app for production to the `build` folder.\ 20 | It correctly bundles React in production mode and optimizes the build for the best performance. 21 | 22 | The build is minified and the filenames include the hashes.\ 23 | Your app is ready to be deployed! 24 | 25 | ### `npm run eject` 26 | 27 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 28 | 29 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 30 | 31 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 32 | 33 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 34 | -------------------------------------------------------------------------------- /src/components/FileFolder.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { ContextMenu, ContextMenuTrigger, MenuItem } from "react-contextmenu"; 3 | import fileIcon from "../assets/file.png"; 4 | import folderIcon from "../assets/folder.png"; 5 | import addNewButton from "../assets/add_new_button.png"; 6 | import "../styles/FileFolder.css"; 7 | 8 | export default function FileFolder(props) { 9 | if (!props.name) { 10 | return ( 11 |
12 | Create file 17 |
18 | ); 19 | } 20 | return ( 21 | 22 |
25 | props.openFolder(props.currPath + props.name + "/") 26 | } 27 | > 28 | {props.name} 33 |
{props.name}
34 |
35 | 36 | 37 | 39 | props.handleContextMenu({ 40 | action: "rename", 41 | id: props.id, 42 | }) 43 | } 44 | className="menu-item" 45 | > 46 | Rename 47 | 48 | 49 | 51 | props.handleContextMenu({ 52 | action: "delete", 53 | id: props.id, 54 | name: props.name, 55 | }) 56 | } 57 | className="menu-item danger" 58 | > 59 | Delete 60 | 61 | 62 |
63 | ); 64 | } 65 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 13 | 22 | Cloud Drive 23 | 24 | 25 | 26 |
27 | 37 | 38 | -------------------------------------------------------------------------------- /src/components/RenameFile.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from "react"; 2 | import close from "../assets/close.png"; 3 | import "react-dom"; 4 | 5 | export default function RenameFile(props) { 6 | const [error, setError] = useState(""); 7 | const [fileName, setFileName] = useState(""); 8 | 9 | useEffect(() => { 10 | props.fileList.forEach((file) => { 11 | if (file.id === props.fileId) { 12 | setFileName(file.name); 13 | } 14 | }); 15 | // eslint-disable-next-line react-hooks/exhaustive-deps 16 | }, []); 17 | 18 | const renameFile = (e) => { 19 | e.preventDefault(); 20 | if (fileName.trim() === "") { 21 | setError("Invalid File / Folder name"); 22 | return; 23 | } 24 | if (props.fileList.every((file) => file.name !== fileName)) { 25 | props.setFileList( 26 | props.fileList.map((file) => { 27 | if (file.id === props.fileId) { 28 | return { ...file, name: fileName.trim() }; 29 | } else { 30 | return file; 31 | } 32 | }) 33 | ); 34 | props.setRenameModal(false); 35 | setFileName(""); 36 | } else { 37 | setError("File / Folder name already exists"); 38 | } 39 | }; 40 | 41 | return ( 42 |
43 |
44 |
Rename File
45 | close props.setRenameModal(false)} 49 | /> 50 |
51 | setFileName(e.target.value)} 58 | /> 59 | {error ?
{error}
: null} 60 | 61 |
62 | ); 63 | } 64 | -------------------------------------------------------------------------------- /src/components/AddFile.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import "react-dom"; 3 | import "../styles/AddFile.css"; 4 | import close from "../assets/close.png"; 5 | import { v4 as uuid } from "uuid"; 6 | 7 | export default function AddFile(props) { 8 | const [error, setError] = useState(""); 9 | const [fileName, setFileName] = useState(""); 10 | const [fileType, setFileType] = useState("file"); 11 | const addFile = (e) => { 12 | e.preventDefault(); 13 | if ( 14 | fileName.trim() === "" || 15 | fileName.indexOf("/") !== -1 || 16 | /^\.*$/.test(fileName) 17 | ) { 18 | setError(`Invalid ${fileType} name`); 19 | } else if ( 20 | props.fileList.every( 21 | (file) => file.path !== props.currPath || file.name !== fileName 22 | ) 23 | ) { 24 | props.setFileList([ 25 | ...props.fileList, 26 | { 27 | id: uuid(), 28 | name: fileName.trim(), 29 | path: props.currPath, 30 | type: fileType, 31 | }, 32 | ]); 33 | props.setShowNewModal(false); 34 | } else { 35 | setError("File / Folder name already exists"); 36 | } 37 | }; 38 | 39 | return ( 40 |
41 |
42 |
Create new
43 | close props.setShowNewModal(false)} 47 | /> 48 |
49 |
50 |
{ 55 | setFileType("file"); 56 | e.target.parentElement.nextSibling.focus(); 57 | }} 58 | > 59 | File 60 |
61 |
{ 66 | setFileType("folder"); 67 | e.target.parentElement.nextSibling.focus(); 68 | }} 69 | > 70 | Folder 71 |
72 |
73 | setFileName(e.target.value)} 80 | /> 81 | {error ?
{error}
: null} 82 | 83 |
84 | ); 85 | } 86 | -------------------------------------------------------------------------------- /src/components/App.js: -------------------------------------------------------------------------------- 1 | import "../styles/App.css"; 2 | import { useState } from "react"; 3 | import FileFolder from "./FileFolder"; 4 | import ReactModal from "react-modal"; 5 | import arrow from "../assets/arrow_up.png"; 6 | import AddFile from "./AddFile"; 7 | import RenameFile from "./RenameFile"; 8 | import BreadCrumbs from "./BreadCrumbs"; 9 | 10 | ReactModal.setAppElement("#root"); 11 | 12 | function App() { 13 | const [fileList, setFileList] = useState([]); 14 | const [fileId, setFileId] = useState(""); 15 | const [showNewModal, setShowNewModal] = useState(false); 16 | const [showRenameModal, setRenameModal] = useState(false); 17 | const [currPath, setCurrPath] = useState("/"); 18 | 19 | const handleContextMenu = (data) => { 20 | switch (data.action) { 21 | case "rename": 22 | setFileId(data.id); 23 | setRenameModal(true); 24 | break; 25 | case "delete": 26 | setFileList( 27 | fileList.filter( 28 | (file) => 29 | file.id !== data.id && 30 | !file.path.startsWith(`${currPath}${data.name}/`) 31 | ) 32 | ); 33 | break; 34 | default: 35 | console.log("Invalid action"); 36 | } 37 | }; 38 | 39 | return ( 40 |
41 |
42 | { 45 | const arr = currPath.split("/").filter((x) => x); 46 | if (arr.length > 0) 47 | setCurrPath( 48 | currPath.substr( 49 | 0, 50 | currPath.indexOf(arr[arr.length - 1]) 51 | ) 52 | ); 53 | }} 54 | alt="back" 55 | /> 56 | 57 |
58 | ( 61 |
62 | setFileList(e)} 66 | setShowNewModal={(e) => setShowNewModal(e)} 67 | /> 68 |
69 | )} 70 | /> 71 | ( 74 |
75 | setFileList(e)} 79 | setRenameModal={(e) => setRenameModal(e)} 80 | /> 81 |
82 | )} 83 | /> 84 |
85 | {fileList 86 | .filter((file) => file.path === currPath) 87 | .map((file) => ( 88 | {} 93 | } 94 | id={file.id} 95 | name={file.name} 96 | type={file.type} 97 | handleContextMenu={(data) => 98 | handleContextMenu(data) 99 | } 100 | /> 101 | ))} 102 | { 104 | setShowNewModal(true); 105 | }} 106 | /> 107 |
108 |
109 | ); 110 | } 111 | 112 | export default App; 113 | --------------------------------------------------------------------------------