├── .babelrc ├── .editorconfig ├── .gitignore ├── LICENSE ├── Osiris.code-workspace ├── README.md ├── code-of-conduct.md ├── customComponents ├── Div.jpg ├── footer.jpg ├── h1.jpg ├── h2.jpg ├── h3.jpg ├── img.jpg ├── navbar.jpg └── ptag.jpg ├── main.js ├── package-lock.json ├── package.json ├── postcss.config.js ├── src ├── NeilArmstrong │ └── components │ │ ├── AllenBean.jsx │ │ └── CharlesErwin.jsx ├── Osiris.code-workspace ├── assets │ ├── css │ │ ├── App.css │ │ ├── BuildPage.css │ │ ├── DetailPage.css │ │ ├── Generator.css │ │ ├── UiItem.css │ │ └── UiLibrary.css │ └── images │ │ ├── Free-Copper-textures.jpg │ │ ├── blue_bg_please.jpg │ │ ├── copper_test1.jpg │ │ ├── d2052-swatch.jpg │ │ ├── grey-wp.jpg │ │ └── scratched-copper-surface_84485-170.jpg ├── components │ ├── App.js │ └── BuildItem.jsx ├── containers │ ├── BottomContainer.jsx │ ├── BuildPage.jsx │ ├── CodeDisplayContainer.jsx │ ├── DetailPage.jsx │ ├── Generator.jsx │ ├── HierarchyContainer.jsx │ ├── LeftContainer.jsx │ ├── StyleContainer.jsx │ ├── UiItem.jsx │ └── UiLibrary.jsx ├── context │ └── MyProvider.js ├── index.js └── utils │ ├── componentRender.js │ ├── createFiles.js │ ├── createfile.js │ └── vueComponentRender.js ├── webpack.build.config.js ├── webpack.dev.config.js └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-react" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = crlf 8 | indent_size = 2 9 | indent_style = space 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build folder and files # 2 | ########################## 3 | builds/ 4 | 5 | # Development folders and files # 6 | ################################# 7 | .tmp/ 8 | dist/ 9 | node_modules/ 10 | *.compiled.* 11 | 12 | # Folder config file # 13 | ###################### 14 | Desktop.ini 15 | 16 | # Folder notes # 17 | ################ 18 | _ignore/ 19 | 20 | # Log files & folders # 21 | ####################### 22 | logs/ 23 | *.log 24 | npm-debug.log* 25 | .npm 26 | 27 | # Packages # 28 | ############ 29 | # it's better to unpack these files and commit the raw source 30 | # git has its own built in compression methods 31 | *.7z 32 | *.dmg 33 | *.gz 34 | *.iso 35 | *.jar 36 | *.rar 37 | *.tar 38 | *.zip 39 | 40 | # Photoshop & Illustrator files # 41 | ################################# 42 | *.ai 43 | *.eps 44 | *.psd 45 | 46 | # Windows & Mac file caches # 47 | ############################# 48 | .DS_Store 49 | Thumbs.db 50 | ehthumbs.db 51 | 52 | # Windows shortcuts # 53 | ##################### 54 | *.lnk 55 | 56 | # PG KEYS# 57 | ##################### 58 | /src/pgKeys.js 59 | 60 | #amplify 61 | amplify/ 62 | build/ 63 | dist/ 64 | node_modules/ 65 | aws-exports.js 66 | awsconfiguration.json 67 | amplifyconfiguration.json 68 | amplify-build-config.json 69 | amplify-gradle-config.json 70 | amplifytools.xcconfig 71 | 72 | #vue-todo 73 | ####################### 74 | vue-todo/ 75 | # -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Alex Devero (alexdevero.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Osiris.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | }, 6 | { 7 | "path": "../../../Downloads/amplify" 8 | } 9 | ], 10 | "settings": { 11 | "git.ignoreLimitWarning": true 12 | } 13 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 |
11 |

12 | 13 | Logo 14 | 15 | 16 | ## Osiris 17 | An Electron based desktop application for generating components and storing them in a UI library. 18 | 19 | __________ 20 | 21 | 22 | 23 | ## Table of Contents 24 | 25 | * [About the Project](#about-the-project) 26 | * [Built With](#built-with) 27 | * [Usage](#usage) 28 | * [Getting Started](#getting-started) 29 | * [Prerequisites](#prerequisites) 30 | * [Installation](#installation) 31 | * [Contributing](#contributing) 32 | * [Contact](#contact) 33 | * [Authors](#authors) 34 | * [License](#license) 35 | 36 | 37 | 38 | 39 | ## About The Project 40 | 41 | Osiris is an all-in-one UI Component Library + Generator + Page Builder for developers and designers. Create and store custom, reusable components in React or Vue. Then, dynamically inject the components and manipulate their hierarchy. Finally, download the code for further development. 42 | 43 | ### Built With 44 | * [Electron](https://www.electronjs.org/) 45 | * [React](https://reactjs.org/) 46 | * [PostgreSQL](https://www.postgresql.org/) 47 | * [Node](https://nodejs.org/en/) 48 | * [Webpack](https://webpack.js.org/) 49 | * [AWS](https://aws.amazon.com/) 50 | 51 | 52 | ## Usage 53 | 54 | _______ 55 | 56 | 57 | **UI Generator and Library Features**: Create custom components in React or Vue. Store your custom components securely in our UI Library powered by AWS S3 58 | 59 | 60 | 61 | _______ 62 | 63 | 64 | **Build Page: Style and Add to Build**: Easily build a React or Vue page by controlling the hierarchy of your custom components stored in your library. Customize your components by adding CSS and text 65 | 66 | 67 | 68 | ________ 69 | 70 | 71 | **Build Page: Hierarchy & Download Code to Vue or React**: Edit the hierarchy with simple arrow buttons. Choose to build your React page with/without State or Hooks. You can also build a Vue page with or without State. Lastly, download your custom page directly to your computer! 72 | 73 | buildpage2 74 | 75 | _______ 76 | 77 | 78 | 79 | ## Getting Started 80 | 81 | To get a local copy up and running follow these steps. 82 | 83 | ### Prerequisite Accounts 84 | 85 | * ElephantSQL: 86 | https://www.elephantsql.com/ 87 | 88 | * AWS S3 Bucket with Amplify: 89 | https://docs.amplify.aws/lib/storage/getting-started/q/platform/js 90 | 91 | ### Installation 92 | 93 | 1. Clone the repo 94 | ```sh 95 | git clone https://github.com/oslabs-beta/Osiris.git 96 | ``` 97 | 2. Install NPM packages 98 | ```sh 99 | npm install 100 | ``` 101 | ### Connect Osiris Electron App to SQL Database with ElephantSQL 102 | 103 | 1. SQL Script 104 | ```sh 105 | CREATE TABLE individual_ui (id SERIAL PRIMARY KEY, organization_id VARCHAR, image VARCHAR, tags VARCHAR, react_code VARCHAR, file_name VARCHAR, type VARCHAR, description VARCHAR); 106 | ``` 107 | 108 | 2. Add pgkeys.js to /src and include the following: 109 | ```sh 110 | export const PG_URI = '' 111 | ``` 112 | ### Initialize AWS-Amplify to your project 113 | 114 | 1. Navigate to Osiris Root folder 115 | 116 | 2. Install Amplify folder following these steps: 117 | 118 | https://docs.amplify.aws/start/getting-started/installation/q/integration/react 119 | https://docs.amplify.aws/lib/storage/getting-started/q/platform/android#initialize-amplify-storage 120 | 121 | ### Run 122 | 123 | 1. Run the electron app 124 | ```sh 125 | npm start 126 | ``` 127 | 128 | 129 | 130 | ### Contributing 131 | 132 | Contributions are what make the open source community such an amazing place to be, learn, inspire, and create. Any contributions you make are **greatly appreciated**. 133 | 134 | 1. Fork the Project 135 | 2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`) 136 | 3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`) 137 | 4. Push to the Branch (`git push origin feature/AmazingFeature`) 138 | 5. Open a Pull Request 139 | 140 | 141 | 142 | ## Contact 143 | 144 | Website: [https://osirisdev.io](https://osirisdev.io/) 145 | 146 | Github Link: [https://github.com/oslabs-beta/Osiris/](https://github.com/oslabs-beta/Osiris/) 147 | 148 | Twitter: [@osiris_io](https://twitter.com/osiris_io) 149 | 150 | 151 | ## Authors 152 | 153 | * [@Wayne Wilcox](https://github.com/LovelaceDink) 154 | * [@Eelan Tung](https://github.com/cupofjoy) 155 | * [@Cameron Fitz](https://github.com/cameronleefitz) 156 | * [@Jehovany Cruz](https://github.com/howaboutjeho) 157 | * [@Garrett Lee](https://github.com/geewailee) 158 | 159 | 160 | ## License 161 | 162 | Distributed under the MIT License. See `LICENSE` for more information. 163 | -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at deveroalex@gmail.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]. 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /customComponents/Div.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oslabs-beta/Osiris/16f256b58030939739889775ef07240e8b137704/customComponents/Div.jpg -------------------------------------------------------------------------------- /customComponents/footer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oslabs-beta/Osiris/16f256b58030939739889775ef07240e8b137704/customComponents/footer.jpg -------------------------------------------------------------------------------- /customComponents/h1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oslabs-beta/Osiris/16f256b58030939739889775ef07240e8b137704/customComponents/h1.jpg -------------------------------------------------------------------------------- /customComponents/h2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oslabs-beta/Osiris/16f256b58030939739889775ef07240e8b137704/customComponents/h2.jpg -------------------------------------------------------------------------------- /customComponents/h3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oslabs-beta/Osiris/16f256b58030939739889775ef07240e8b137704/customComponents/h3.jpg -------------------------------------------------------------------------------- /customComponents/img.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oslabs-beta/Osiris/16f256b58030939739889775ef07240e8b137704/customComponents/img.jpg -------------------------------------------------------------------------------- /customComponents/navbar.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oslabs-beta/Osiris/16f256b58030939739889775ef07240e8b137704/customComponents/navbar.jpg -------------------------------------------------------------------------------- /customComponents/ptag.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oslabs-beta/Osiris/16f256b58030939739889775ef07240e8b137704/customComponents/ptag.jpg -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Import parts of electron to use 4 | const { 5 | app, 6 | BrowserWindow, 7 | ipcMain, 8 | dialog 9 | } = require("electron"); 10 | const path = require("path"); 11 | const url = require("url"); 12 | 13 | // Keep a global reference of the window object, if you don't, the window will 14 | // be closed automatically when the JavaScript object is garbage collected. 15 | let mainWindow; 16 | 17 | // Keep a reference for dev mode 18 | let dev = false; 19 | 20 | // Broken: 21 | // if (process.defaultApp || /[\\/]electron-prebuilt[\\/]/.test(process.execPath) || /[\\/]electron[\\/]/.test(process.execPath)) { 22 | // dev = true 23 | // } 24 | 25 | if ( 26 | process.env.NODE_ENV !== undefined && 27 | process.env.NODE_ENV === "development" 28 | ) { 29 | dev = true; 30 | } 31 | 32 | // Temporary fix broken high-dpi scale factor on Windows (125% scaling) 33 | // info: https://github.com/electron/electron/issues/9691 34 | if (process.platform === "win32") { 35 | app.commandLine.appendSwitch("high-dpi-support", "true"); 36 | app.commandLine.appendSwitch("force-device-scale-factor", "1"); 37 | } 38 | 39 | // Choose directory 40 | ipcMain.on("choose_app_dir", async (event) => { 41 | const directory = await dialog.showOpenDialog(mainWindow, { 42 | properties: ["openDirectory"], 43 | }); 44 | console.log(directory); 45 | if (!directory) return; 46 | event.sender.send("app_dir_selected", directory.filePaths[0]); 47 | }); 48 | 49 | function createWindow() { 50 | // Create the browser window. 51 | mainWindow = new BrowserWindow({ 52 | width: 1024, 53 | height: 768, 54 | show: false, 55 | webPreferences: { 56 | nodeIntegration: true, 57 | }, 58 | }); 59 | 60 | // and load the index.html of the app. 61 | let indexPath; 62 | 63 | if (dev && process.argv.indexOf("--noDevServer") === -1) { 64 | indexPath = url.format({ 65 | protocol: "http:", 66 | host: "localhost:8080", 67 | pathname: "index.html", 68 | slashes: true, 69 | }); 70 | } else { 71 | indexPath = url.format({ 72 | protocol: "file:", 73 | pathname: path.join(__dirname, "dist", "index.html"), 74 | slashes: true, 75 | }); 76 | // indexPath = url.format({ 77 | // protocol: "http:", 78 | // host: "localhost:8080", 79 | // pathname: "index.html", 80 | // slashes: true, 81 | // }); 82 | } 83 | console.log('here', indexPath) 84 | 85 | mainWindow.loadURL(indexPath); 86 | 87 | // and load the index.html of the app. 88 | // mainWindow.loadURL(`file://${__dirname}/build/index.html`); 89 | 90 | // Don't show until we are ready and loaded 91 | mainWindow.once("ready-to-show", () => { 92 | mainWindow.show(); 93 | 94 | // Open the DevTools automatically if developing 95 | // if (dev) { 96 | // const { default: installExtension, REACT_DEVELOPER_TOOLS } = require('electron-devtools-installer') 97 | 98 | // installExtension(REACT_DEVELOPER_TOOLS) 99 | // .catch(err => console.log('Error loading React DevTools: ', err)) 100 | // mainWindow.webContents.openDevTools() 101 | // } 102 | }); 103 | 104 | // Emitted when the window is closed. 105 | mainWindow.on("closed", function () { 106 | // Dereference the window object, usually you would store windows 107 | // in an array if your app supports multi windows, this is the time 108 | // when you should delete the corresponding element. 109 | mainWindow = null; 110 | }); 111 | } 112 | 113 | // This method will be called when Electron has finished 114 | // initialization and is ready to create browser windows. 115 | // Some APIs can only be used after this event occurs. 116 | app.on("ready", createWindow); 117 | 118 | // Quit when all windows are closed. 119 | app.on("window-all-closed", () => { 120 | // On macOS it is common for applications and their menu bar 121 | // to stay active until the user quits explicitly with Cmd + Q 122 | if (process.platform !== "darwin") { 123 | app.quit(); 124 | } 125 | }); 126 | 127 | app.on("activate", () => { 128 | // On macOS it's common to re-create a window in the app when the 129 | // dock icon is clicked and there are no other windows open. 130 | if (mainWindow === null) { 131 | createWindow(); 132 | } 133 | }); 134 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Osiris", 3 | "version": "1.0.0", 4 | "description": "An Electron based desktop application for generating components and storing them in a UI library. ", 5 | "license": "MIT", 6 | "private": false, 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/oslabs-beta/Osiris" 10 | }, 11 | "homepage": "/generator", 12 | "keywords": [ 13 | "app", 14 | "boilerplate", 15 | "electron", 16 | "open", 17 | "open-source", 18 | "postcss", 19 | "react", 20 | "reactjs", 21 | "source", 22 | "webpack" 23 | ], 24 | "engines": { 25 | "node": ">=9.0.0", 26 | "npm": ">=5.0.0", 27 | "yarn": ">=1.0.0" 28 | }, 29 | "browserslist": [ 30 | "last 4 versions" 31 | ], 32 | "main": "main.js", 33 | "scripts": { 34 | "prod": "cross-env NODE_ENV=production webpack --mode production --config webpack.build.config.js && electron --noDevServer .", 35 | "start": "cross-env NODE_ENV=development webpack-dev-server --hot --host 0.0.0.0 --config=./webpack.dev.config.js --mode development", 36 | "build": "cross-env NODE_ENV=production webpack --config webpack.build.config.js --mode production", 37 | "package": "npm run build", 38 | "postpackage": "electron-packager ./ --out=./builds", 39 | "lint": "eslint" 40 | }, 41 | "dependencies": { 42 | "@aws-amplify/ui-react": "^0.2.11", 43 | "aws-amplify": "^3.0.20", 44 | "aws-sdk": "^2.714.0", 45 | "lodash.clonedeep": "^4.5.0", 46 | "pg": "^8.3.0", 47 | "prettier": "^2.0.5", 48 | "react": "^16.13.1", 49 | "react-dom": "^16.13.1", 50 | "react-router": "^5.2.0", 51 | "react-router-dom": "^5.2.0" 52 | }, 53 | "devDependencies": { 54 | "@babel/core": "^7.9.6", 55 | "@babel/preset-react": "^7.9.4", 56 | "babel-loader": "^8.1.0", 57 | "babel-minify-webpack-plugin": "^0.3.1", 58 | "cross-env": "^7.0.2", 59 | "css-loader": "^3.5.3", 60 | "electron": "^9.0.0", 61 | "electron-devtools-installer": "^3.0.0", 62 | "electron-packager": "^14.2.1", 63 | "file-loader": "^6.0.0", 64 | "html-webpack-plugin": "^4.3.0", 65 | "mini-css-extract-plugin": "^0.9.0", 66 | "postcss-import": "^12.0.1", 67 | "postcss-loader": "^3.0.0", 68 | "postcss-nested": "^4.2.1", 69 | "postcss-preset-env": "^6.7.0", 70 | "postcss-pxtorem": "^5.1.1", 71 | "style-loader": "^1.2.0", 72 | "webpack": "^4.43.0", 73 | "webpack-cli": "^3.3.11", 74 | "webpack-dev-server": "^3.11.0" 75 | }, 76 | "lint-staged": { 77 | "*.js": [ 78 | "prettier --write", 79 | "git add" 80 | ] 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | 'postcss-import': {}, 4 | 'postcss-nested': {}, 5 | 'postcss-preset-env': {}, 6 | 'postcss-pxtorem': { 7 | rootValue: 16, 8 | unitPrecision: 5, 9 | propList: ['*'], 10 | selectorBlackList: ['html', 'body'], 11 | replace: true, 12 | mediaQuery: false, 13 | minPixelValue: 0 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/NeilArmstrong/components/AllenBean.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | class AllenBean extends Component { 4 | constructor(props) { 5 | super(props); 6 | this.state = {}; 7 | } 8 | render() { 9 | return ( 10 |

11 |
12 |
    19 | HOME 20 |
21 |

27 | LETS GO 28 |

29 |

35 | WE DID FOR SURE NOWWW? LETS GOO 36 |

37 | 52 |
53 |
54 | ); 55 | } 56 | } 57 | export default AllenBean; 58 | -------------------------------------------------------------------------------- /src/NeilArmstrong/components/CharlesErwin.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | class CharlesErwin extends Component { 4 | constructor(props) { 5 | super(props); 6 | this.state = {}; 7 | } 8 | render() { 9 | return ( 10 |
11 |
12 |
    19 |

    25 | lets go!!!!? 26 |

    27 |

    33 | WE DID IT!? LAST EDGE CASE? 34 |

    35 | 48 |
    49 |
    50 | ); 51 | } 52 | } 53 | export default CharlesErwin; 54 | -------------------------------------------------------------------------------- /src/Osiris.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": ".." 5 | }, 6 | { 7 | "path": "../../../../Downloads/amplify" 8 | } 9 | ], 10 | "settings": {} 11 | } -------------------------------------------------------------------------------- /src/assets/css/App.css: -------------------------------------------------------------------------------- 1 | #root { 2 | display: grid; 3 | grid-template-columns: 1fr 80%; 4 | width: 100%; 5 | height: 100%; 6 | margin: 0 auto; 7 | background-image: url('../images/d2052-swatch.jpg'); 8 | } 9 | 10 | body { 11 | display: block; 12 | margin: 0px; 13 | font-family: Helvetica, sans-serif; 14 | } 15 | 16 | .navbar { 17 | min-height: 768px; 18 | grid-column: 1; 19 | display: flex; 20 | /* background-image: url('../images/grey-wp.jpg'); */ 21 | background-color: #d28e4f; 22 | /* background-color: teal; */ 23 | height: 100%; 24 | flex-direction: column; 25 | justify-content: flex-start; 26 | font-size: 22px; 27 | opacity: .7; 28 | } 29 | 30 | .navbar ul { 31 | list-style-type: none; 32 | margin-right: 10px; 33 | } 34 | 35 | .navbar li { 36 | font-weight: bold; 37 | padding: 10px; 38 | border-radius: 1px; 39 | border-top: 1px solid white; 40 | border-bottom: 1px solid white; 41 | margin: 10px; 42 | text-decoration: none; 43 | display: flex; 44 | justify-content: center; 45 | width: fit-content; 46 | /* background-color: #1a3643; */ 47 | } 48 | 49 | .navbar img { 50 | /* position: ; */ 51 | top: 0; 52 | } 53 | /* 54 | position: absolute; 55 | bottom: 0; 56 | */ 57 | a { 58 | color: white; 59 | font-size: large; 60 | text-decoration: none; 61 | } 62 | 63 | .main-style { 64 | grid-column: 1; 65 | color: white; 66 | display: flex; 67 | height: 100%; 68 | background-color: #1a3643; 69 | opacity: .6; 70 | display: flex; 71 | flex-direction: row; 72 | flex-wrap: wrap; 73 | align-items: center; 74 | justify-content: center; 75 | padding: 10px; 76 | } -------------------------------------------------------------------------------- /src/assets/css/BuildPage.css: -------------------------------------------------------------------------------- 1 | .buildPage { 2 | background-image: url("../images/grey-wp.jpg"); 3 | } 4 | 5 | .buildPageTop { 6 | display: grid; 7 | grid-template-columns: 75% 1fr; 8 | width: 100%; 9 | height: 100%; 10 | margin: 0 auto; 11 | background-color: black; 12 | background-repeat: repeat; 13 | border-bottom: 1px solid #d28e4f; 14 | border-top: 1px solid #d28e4f; 15 | padding-bottom: 10px; 16 | } 17 | 18 | .codeDisplay { 19 | grid-column: 1; 20 | display: flex; 21 | height: 100%; 22 | flex-direction: column; 23 | justify-content: center; 24 | background-color: black; 25 | color: #d28e4f; 26 | padding-left: 25px; 27 | /* padding-bottom: 10px; */ 28 | } 29 | 30 | .codeDisplayContainer { 31 | padding-bottom: 25px; 32 | } 33 | 34 | .hierarchy-container { 35 | display: flex; 36 | flex-direction: column; 37 | height: 100%; 38 | grid-column: 2; 39 | padding-left: 15px; 40 | padding-right: 10px; 41 | background-color: black; 42 | color: #d28e4f; 43 | border-left: 1px solid #d28e4f; 44 | /* border-width: medium; 45 | border:solid; */ 46 | } 47 | 48 | pre { 49 | white-space: pre-wrap; 50 | white-space: -moz-pre-wrap; 51 | white-space: -o-pre-wrap; 52 | word-wrap: break-word; 53 | } 54 | 55 | code { 56 | font-family: Courier, "New Courier", monospace; 57 | font-size: 12px; 58 | } 59 | 60 | .codeDisplayContainer { 61 | border-radius: 5px; 62 | -moz-border-radius: 5px; 63 | -webkit-border-radius: 5px; 64 | /* margin: 1em 0; */ 65 | /*padding-left: 25px; */ 66 | } 67 | 68 | h1 { 69 | font-size: 24px; 70 | } 71 | .buildPageHeader { 72 | border-bottom: 2px solid #d28e4f; 73 | border-top: 1px solid #d28e4f; 74 | background-color: #1a3643; 75 | opacity: 0.6; 76 | color: white; 77 | } 78 | 79 | button { 80 | margin-left: 5px; 81 | } 82 | 83 | .bottom-container { 84 | /* position: fixed; */ 85 | overflow-y: scroll; 86 | max-height: 1000px; 87 | } -------------------------------------------------------------------------------- /src/assets/css/DetailPage.css: -------------------------------------------------------------------------------- 1 | .detailpage { 2 | display: flex; 3 | flex-direction: column; 4 | height: 100%; 5 | grid-column: 2; 6 | padding-left: 2px; 7 | background-image: url("../images/grey-wp.jpg"); 8 | background-repeat: repeat; 9 | color: white; 10 | min-height: 1000px; 11 | } 12 | 13 | .detailHead { 14 | border-bottom: 2px solid white; 15 | border-top: 1px solid white; 16 | background-color: #1a3643; 17 | opacity: 0.6; 18 | } 19 | 20 | .detail-img { 21 | height: 100px; 22 | } 23 | 24 | h1 { 25 | display: flex; 26 | justify-content: center; 27 | opacity: 1; 28 | } 29 | 30 | button { 31 | padding: 10px; 32 | border-radius: 5px; 33 | border: 1px solid grey; 34 | background-color: white; 35 | } 36 | 37 | /* .oneDetail { 38 | margin: 10px; 39 | max-width: 300px; 40 | max-height: 450px; 41 | background-color: white; 42 | border-radius: 10px; 43 | box-shadow: 0px 0px 20px rgba(0,0,0, .5); 44 | display: flex; 45 | flex-direction: column; 46 | box-sizing: border-box; 47 | min-width: 150px; 48 | min-height: 150px; 49 | order: 4; 50 | flex: 1 ; 51 | flex-grow: 0; 52 | flex-shrink: 1; 53 | flex-basis: auto; 54 | justify-content: center; 55 | align-items: center; 56 | padding: 2em 0em; 57 | } 58 | 59 | img { 60 | margin-top: .5em; 61 | justify-self: center ; 62 | align-self: center; 63 | border-radius: inherit; 64 | /* width: 300px; 65 | height: 300px }*/ 66 | 67 | .oneUIBox { 68 | margin: 10px; 69 | max-width: 228px; 70 | max-height: 600px; 71 | background-color: white; /* #c3d3d0; */ 72 | border-radius: 10px; 73 | 74 | box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.5); 75 | display: flex; 76 | flex-direction: column; 77 | box-sizing: border-box; 78 | min-width: 150px; 79 | 80 | min-height: 200px; 81 | order: 4; 82 | flex: 1; 83 | flex-grow: 0; 84 | flex-shrink: 1; 85 | flex-basis: auto; 86 | justify-content: center; 87 | align-items: center; 88 | padding: 2em 0em; 89 | } 90 | h2 { 91 | overflow: hidden; 92 | white-space: nowrarp; 93 | text-overflow: ellipsis; 94 | max-width: 250px; 95 | min-width: 200px; 96 | border-radius: inherit; 97 | text-decoration: none; 98 | background: #cfd8dc; 99 | font: 14px/1 sans-serif; 100 | color: black; 101 | padding: 1.2em 1em; 102 | /*padding: 0.5rem 1rem; */ 103 | border-radius: 4px; 104 | } 105 | 106 | img { 107 | margin-top: 2em; 108 | justify-self: center; 109 | align-self: center; 110 | border-radius: inherit; 111 | } 112 | 113 | .detailList { 114 | overflow: hidden; 115 | white-space: nowrarp; 116 | text-overflow: ellipsis; 117 | max-width: 250px; 118 | min-width: 100px; 119 | border-radius: inherit; 120 | text-decoration: none; 121 | background: #cfd8dc; 122 | font: 14px/1 sans-serif; 123 | color: black; 124 | padding: 20px; 125 | /*padding: 0.5rem 1rem; */ 126 | border-radius: 4px; 127 | } 128 | 129 | button { 130 | max-width: 200px; 131 | max-height: 100px; 132 | margin-bottom: 5px; 133 | border-radius: 10px; 134 | background-color: white; 135 | font-family: "Courier New", Courier, monospace; 136 | text-decoration-color: blue; 137 | } 138 | -------------------------------------------------------------------------------- /src/assets/css/Generator.css: -------------------------------------------------------------------------------- 1 | .generator-container { 2 | display: flex; 3 | flex-direction: column; 4 | height: 100%; 5 | grid-column: 2; 6 | padding-left: 2px; 7 | background-image: url('../images/grey-wp.jpg'); 8 | background-repeat: repeat; 9 | color: white; 10 | min-height: 1200px; 11 | } 12 | 13 | .genHead { 14 | border-bottom: 2px solid white; 15 | border-top: 1px solid white; 16 | background-color: #1a3643; 17 | opacity: .6; 18 | } 19 | 20 | .generator-container button { 21 | padding: 10px; 22 | border-radius: 5px; 23 | border: 1px solid grey; 24 | margin: 5px; 25 | width: 10em; 26 | background-color: white; 27 | height: 50px; 28 | } 29 | 30 | .submitButton { 31 | padding: 10px; 32 | border-radius: 5px; 33 | border: 1px solid grey; 34 | margin: 5px; 35 | width: 10em; 36 | background-color: white; 37 | height: 50px; 38 | } 39 | 40 | .top-container, 41 | .bottom-container { 42 | height: 50%; 43 | display: flex; 44 | flex-direction: column; 45 | } 46 | 47 | .bottom-container input, 48 | .bottom-container select { 49 | padding: 10px; 50 | border-radius: 5px; 51 | border: 1px solid grey; 52 | margin: 5px; 53 | } 54 | 55 | #imageupload { 56 | max-width: 500px; 57 | max-height: 250px; 58 | } -------------------------------------------------------------------------------- /src/assets/css/UiItem.css: -------------------------------------------------------------------------------- 1 | .oneUIBox { 2 | margin: 10px; 3 | max-width: 300px; 4 | max-height: 450px; 5 | background-color: white;/* #c3d3d0; */ 6 | border-radius: 10px; 7 | 8 | box-shadow: 0px 0px 20px rgba(0,0,0, .5); 9 | display: flex; 10 | flex-direction: column; 11 | box-sizing: border-box; 12 | min-width: 150px; 13 | min-height: 150px; 14 | order: 4; 15 | flex: 1 ; 16 | flex-grow: 0; 17 | flex-shrink: 1; 18 | flex-basis: auto; 19 | justify-content: center; 20 | align-items: center; 21 | padding: 2em 0em; 22 | } 23 | img { 24 | margin-top: 2em; 25 | justify-self: center ; 26 | align-self: center; 27 | border-radius: inherit; 28 | } 29 | 30 | h2 { 31 | overflow: hidden; 32 | white-space: nowrarp; 33 | text-overflow: ellipsis; 34 | max-width: 250px; 35 | min-width: 200px; 36 | border-radius: inherit; 37 | text-decoration: none; 38 | background: #CFD8DC; 39 | font: 14px/1 sans-serif; 40 | color: black; 41 | padding: 1.2em 1em; 42 | /*padding: 0.5rem 1rem; */ 43 | border-radius: 4px; 44 | 45 | /* 46 | margin-top: 0; 47 | padding: 0; 48 | max-width: 400px; 49 | max-height: 75px; 50 | background-color: white; 51 | border-radius: inherit; 52 | font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif; 53 | font-size: 20px; 54 | white-space: nowrap; 55 | font-weight: 400; 56 | */ 57 | } 58 | 59 | button { 60 | max-width: 200px; 61 | max-height: 100px; 62 | margin-bottom: 5px; 63 | 64 | background-color: #d28e4f; 65 | border-radius: inherit; 66 | font-family: 'Courier New', Courier, monospace; 67 | text-decoration-color: blue; 68 | 69 | } -------------------------------------------------------------------------------- /src/assets/css/UiLibrary.css: -------------------------------------------------------------------------------- 1 | .libraryContainer { 2 | grid-column: 2; 3 | /* display:flex; */ 4 | overflow-y: scroll; 5 | min-height: 1000px; 6 | 7 | /* justify-content: center; */ 8 | background-image: url("../images/grey-wp.jpg"); 9 | background-repeat: repeat; 10 | border-bottom: 1px solid #d28e4f; 11 | border-top: 1px solid #d28e4f; 12 | /* margin-top: 10px;*/ 13 | } 14 | 15 | .ui-library { 16 | color: #1a3643; 17 | display: flex; 18 | flex-direction: row; 19 | flex-wrap: wrap; 20 | align-items: center; 21 | justify-content: center; 22 | padding: 10px; 23 | margin-top: 65px; 24 | } 25 | 26 | h1 { 27 | display: flex; 28 | justify-content: center; 29 | opacity: 1; 30 | } 31 | 32 | .libraryHeader { 33 | color: white; 34 | border-bottom: 2px solid white; 35 | border-top: 1px solid white; 36 | background-color: #1a3643; 37 | /*display: flex; */ 38 | /* justify-content: center; */ 39 | opacity: 0.6; 40 | /* height: 50px; */ 41 | width: 100%; 42 | display: flex; 43 | justify-content: center; 44 | /* position: fixed; */ 45 | /* margin-bottom: 100px; */ 46 | /* box-shadow: 0px 10px 14px -7px #276873; 47 | background-color:black; 48 | border-radius:8px; 49 | /* display:inline-block; */ 50 | /* cursor:pointer; */ 51 | /* color:#ffffff; 52 | font-family:Arial; 53 | font-size:20px; 54 | font-weight:bold; 55 | padding:13px 32px; 56 | text-shadow:0px 1px 0px #3d768a; */ 57 | } 58 | -------------------------------------------------------------------------------- /src/assets/images/Free-Copper-textures.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oslabs-beta/Osiris/16f256b58030939739889775ef07240e8b137704/src/assets/images/Free-Copper-textures.jpg -------------------------------------------------------------------------------- /src/assets/images/blue_bg_please.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oslabs-beta/Osiris/16f256b58030939739889775ef07240e8b137704/src/assets/images/blue_bg_please.jpg -------------------------------------------------------------------------------- /src/assets/images/copper_test1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oslabs-beta/Osiris/16f256b58030939739889775ef07240e8b137704/src/assets/images/copper_test1.jpg -------------------------------------------------------------------------------- /src/assets/images/d2052-swatch.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oslabs-beta/Osiris/16f256b58030939739889775ef07240e8b137704/src/assets/images/d2052-swatch.jpg -------------------------------------------------------------------------------- /src/assets/images/grey-wp.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oslabs-beta/Osiris/16f256b58030939739889775ef07240e8b137704/src/assets/images/grey-wp.jpg -------------------------------------------------------------------------------- /src/assets/images/scratched-copper-surface_84485-170.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oslabs-beta/Osiris/16f256b58030939739889775ef07240e8b137704/src/assets/images/scratched-copper-surface_84485-170.jpg -------------------------------------------------------------------------------- /src/components/App.js: -------------------------------------------------------------------------------- 1 | import "../assets/css/App.css"; 2 | import React, { useEffect, useReducer } from "react"; 3 | import { 4 | BrowserRouter as Router, 5 | Switch, 6 | Route, 7 | Link, 8 | Redirect, 9 | } from "react-router-dom"; 10 | import ReactDom from "react-dom"; 11 | import { Pool } from "pg"; 12 | import { PG_URI } from "../pgKeys"; 13 | import Generator from "../containers/Generator.jsx"; 14 | import UiLibrary from "../containers/UiLibrary.jsx"; 15 | import DetailPage from "../containers/DetailPage.jsx"; 16 | import BuildPage from "../containers/BuildPage.jsx"; 17 | import { Context } from "../context/MyProvider.js"; 18 | import { Storage } from "aws-amplify"; 19 | 20 | const pool = new Pool({ connectionString: PG_URI}); 21 | function App() { 22 | const { globalState, dispatch } = React.useContext(Context); 23 | 24 | const handlePromises = (itemsFromDB) => { 25 | const uiItemsPromises = itemsFromDB.map((obj) => { 26 | return Storage.get(`${obj.file_name}.jpg`); 27 | }); 28 | Promise.all(uiItemsPromises).then((results) => { 29 | // combining itemsFromDB with their appropriate urls 30 | const updateUiItems = itemsFromDB.map((item, index) => { 31 | item.url = results[index]; 32 | return item; 33 | }); 34 | 35 | dispatch({ type: "add_uis", payload: updateUiItems }); 36 | }); 37 | }; 38 | 39 | useEffect(() => { 40 | pool.query("SELECT * FROM individual_ui").then((data) => { 41 | handlePromises(data.rows); 42 | }); 43 | }, []); 44 | 45 | return ( 46 | 47 | {({ globalState }) => ( 48 | 49 |
    50 | osiris 57 |
      58 |
    • 59 | UI Library 60 |
    • 61 |
    • 62 | UI Generator 63 |
    • 64 |
    • 65 | Build Page 66 |
    • 67 |
    68 |
    69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | } /> 83 | 84 |
    85 | )} 86 |
    87 | ); 88 | } 89 | export default App; 90 | -------------------------------------------------------------------------------- /src/components/BuildItem.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Context } from '../context/MyProvider.js'; 3 | 4 | const BuildItem = (props) => { 5 | const { globalState, dispatch } = React.useContext(Context); 6 | 7 | const upArrowClick = (e) => { 8 | dispatch({ type: 'upClick', payload: props.item}) 9 | } 10 | const downArrowClick = (e) => { 11 | dispatch({ type: 'downClick', payload: props.item}) 12 | } 13 | const leftArrowClick = (e) => { 14 | dispatch({ type: 'leftClick', payload: props.item}) 15 | } 16 | const rightArrowClick = (e) => { 17 | dispatch({ type: 'rightClick', payload: props.item}) 18 | } 19 | return ( 20 |
    21 |
  • {props.item.file_name}
  • 22 | 23 | 24 | 25 | 26 |
    27 | ) 28 | } 29 | 30 | export default BuildItem; -------------------------------------------------------------------------------- /src/containers/BottomContainer.jsx: -------------------------------------------------------------------------------- 1 | import "../assets/css/bottomContainer.css"; 2 | import React from "react"; 3 | import { Context } from "../context/MyProvider.js"; 4 | import UiLibrary from "./UiLibrary.js"; 5 | 6 | const BottomContainer = (props) => { 7 | const { globalState } = React.useContext(Context); 8 | 9 | return
    ; 10 | }; 11 | 12 | export default BottomContainer; 13 | -------------------------------------------------------------------------------- /src/containers/BuildPage.jsx: -------------------------------------------------------------------------------- 1 | import "../assets/css/BuildPage.css"; 2 | import React, { useState } from "react"; 3 | import { Context } from "../context/MyProvider.js"; 4 | import UiLibrary from "./UiLibrary.jsx"; 5 | import HierarchyContainer from "./HierarchyContainer.jsx"; 6 | import CodeDisplayContainer from "./CodeDisplayContainer.jsx"; 7 | import StyleContainer from "./StyleContainer.jsx"; 8 | 9 | const BuildPage = (props) => { 10 | const { globalState, dispatch } = React.useContext(Context); 11 | 12 | const onClick = (e) => { 13 | dispatch({ 14 | type: "updateBuildUiItems", 15 | payload: e.target.id, 16 | }); 17 | }; 18 | 19 | 20 | return ( 21 |
    22 |
    23 |

    Page Builder

    24 |
    25 |
    26 |
    27 | 28 |
    29 |
    30 | 31 |
    32 |
    33 |
    34 | {globalState.showPopup === true && ( 35 | 36 | )} 37 |
    38 |
    39 | 40 |
    41 |
    42 | ); 43 | }; 44 | 45 | export default BuildPage; 46 | -------------------------------------------------------------------------------- /src/containers/CodeDisplayContainer.jsx: -------------------------------------------------------------------------------- 1 | // import '../assets/css/TopContainer.css'; 2 | import React, { useState, useEffect } from "react"; 3 | import BuildItem from "../components/BuildItem.jsx"; 4 | import createFiles from "../utils/createFiles.js"; 5 | import componentRender from "../utils/componentRender.js"; 6 | import vueComponentRender from "../utils/vueComponentRender.js"; 7 | import { Context } from "../context/MyProvider.js"; 8 | const IPC = require("electron").ipcRenderer; 9 | 10 | const CodeDisplayContainer = (props) => { 11 | const [DLFileName, setDLFileName] = useState(""); 12 | const [selectedState, setSelectedState] = useState("noState"); 13 | const [path, setPath] = useState(""); 14 | const [codeStr, setCodeStr] = useState(""); 15 | 16 | const { globalState, dispatch } = React.useContext(Context); 17 | let { items } = props; 18 | 19 | useEffect(() => { 20 | if (props.items !== undefined) { 21 | renderCode(props.items); 22 | } 23 | }, [props.items]); 24 | 25 | function clear() { 26 | dispatch({ 27 | type: "clearCode", 28 | }); 29 | setDLFileName(""); 30 | setSelectedState("noState"); 31 | setPath(""); 32 | setCodeStr(""); 33 | } 34 | 35 | function handleDownload() { 36 | let codeStr = renderCode(items); 37 | createFiles(codeStr, path, DLFileName, selectedState, globalState.language); 38 | alert("File Downloaded! Osiris is pieced together again, thank you!"); 39 | clear(); 40 | } 41 | 42 | function onChangeDL(e) { 43 | setDLFileName(e.target.value); 44 | } 45 | 46 | function languageDropDown(e) { 47 | dispatch({type: 'change_language', payload: e.target.value}); 48 | renderCode(items, selectedState, e.target.value); 49 | } 50 | function handleDropDown(e) { 51 | setSelectedState(e.target.value); 52 | renderCode(items, e.target.value); 53 | } 54 | 55 | function pickDirectory(e) { 56 | IPC.on("app_dir_selected", (event, path) => { 57 | setPath(path); 58 | }); 59 | IPC.send("choose_app_dir"); 60 | } 61 | 62 | function renderCode( 63 | items, 64 | stateSelection = selectedState, 65 | language = globalState.language 66 | ) { 67 | let code = ""; 68 | 69 | items.forEach((item) => { 70 | //base case, not nested 71 | if (Array.isArray(item)) { 72 | code += handleNested(item, code); 73 | } else { 74 | //close type tag 75 | code += `\n\t\t${item.react_code}`; 76 | } 77 | }); 78 | 79 | if (language === "react") { 80 | const reactCode = componentRender(code, stateSelection, DLFileName); 81 | setCodeStr(reactCode); 82 | return reactCode; 83 | } 84 | if (language === "vue") { 85 | const vueCode = vueComponentRender(code, stateSelection, DLFileName); 86 | setCodeStr(vueCode); 87 | return vueCode; 88 | } 89 | } 90 | 91 | function handleNested(items) { 92 | let openingHalf = "\n\t\t
    "; 93 | let closingHalf = "\n\t\t
    "; 94 | let counter = 0; 95 | // loop through each item 96 | for (let i = 1; i < items.length; i += 1) { 97 | if (items[i].type === "div") { 98 | openingHalf += "\n\t\t\t
    "; 99 | closingHalf = "\n\t\t\t
    " + closingHalf; 100 | counter++; 101 | } else { 102 | if (counter === 0) { 103 | openingHalf += `\n\t\t\t${items[i].react_code}`; 104 | } else { 105 | openingHalf += `\n\t\t\t\t${items[i].react_code}`; 106 | } 107 | } 108 | } 109 | 110 | return openingHalf + closingHalf; 111 | } 112 | 113 | return ( 114 |
    115 |
    116 |

    CODE DISPLAY

    117 |
    118 |           {codeStr}
    119 |         
    120 |
    121 |
    122 | 130 | {globalState.language === "react" && ( 131 | 141 | )} 142 | {globalState.language === "vue" && ( 143 | 152 | )} 153 | 159 | 160 | 161 | 162 |
    163 |
    164 | ); 165 | }; 166 | 167 | export default CodeDisplayContainer; 168 | -------------------------------------------------------------------------------- /src/containers/DetailPage.jsx: -------------------------------------------------------------------------------- 1 | import "../assets/css/DetailPage.css"; 2 | import React from "react"; 3 | import { Context } from "../context/MyProvider.js"; 4 | const detailPage = (props) => { 5 | const { globalState } = React.useContext(Context); 6 | // destructured global state for latest component from generator 7 | 8 | const { 9 | tags, 10 | react_code, 11 | vue_code, 12 | file_name, 13 | type, 14 | description, 15 | url, 16 | } = globalState.details; 17 | return ( 18 |
    19 |
    20 |

    DETAIL PAGE

    21 |
    22 |
    23 | {file_name} 29 |

    Type: {type}

    30 |

    Tags: {tags}

    31 |

    Description: {description}

    32 |

    React Code: {react_code}

    33 |
    34 |
    35 | ); 36 | }; 37 | 38 | export default detailPage; 39 | -------------------------------------------------------------------------------- /src/containers/Generator.jsx: -------------------------------------------------------------------------------- 1 | import '../assets/css/Generator.css'; 2 | import React, { useState } from 'react'; 3 | import { withRouter } from 'react-router-dom'; 4 | import { Storage } from 'aws-amplify'; 5 | import { Context } from '../context/MyProvider.js'; 6 | import { Pool } from 'pg'; 7 | import { PG_URI } from '../pgKeys'; 8 | const pool = new Pool({ connectionString: PG_URI }); 9 | 10 | function Generator(props) { 11 | const { dispatch } = React.useContext(Context); 12 | // initial state for generator: 13 | // htmlTags, buttonText, placeholder - compiled into react code 14 | // file only for handleFileChange 15 | const [ userData, setUserData ] = useState({ 16 | htmlTags: 'div', 17 | searchTags: '', 18 | reactCode: '', 19 | description: '', 20 | fileName: '', 21 | buttonText: '', 22 | placeholder: '', 23 | image: '', 24 | s3file: '', 25 | fontColor: '', 26 | fontWeight: '', 27 | fontFamily: '', 28 | fontStyle: '', 29 | }); 30 | 31 | // uploading files 32 | function handleFileChange(e) { 33 | const file = e.target.files[0]; 34 | const reader = new FileReader(); 35 | const imgtag = document.getElementById('imageupload'); 36 | imgtag.title = file.name; 37 | 38 | reader.onload = function(event) { 39 | imgtag.src = event.target.result; 40 | }; 41 | 42 | reader.readAsDataURL(file); 43 | setUserData({ 44 | ...userData, 45 | s3file: file 46 | }); 47 | } 48 | 49 | // typed input updating state 50 | function handleChange(e) { 51 | setUserData({ 52 | ...userData, 53 | [e.target.name]: e.target.value 54 | }); 55 | } 56 | 57 | // 58 | async function handleClick(e) { 59 | e.preventDefault(); 60 | try { 61 | let image = await Storage.put(`${userData.fileName}.jpg`, userData.s3file); 62 | 63 | const { htmlTags, buttonText, placeholder, searchTags, description, fileName } = userData; 64 | 65 | let reactCode; 66 | 67 | switch (htmlTags) { 68 | case 'button': 69 | reactCode = `<${htmlTags} style={}>`; 70 | break; 71 | case 'input': 72 | reactCode = `<${htmlTags} placeholder=${placeholder}>`; 73 | break; 74 | case 'h1': 75 | reactCode = `<${htmlTags} style={}>`; 76 | break; 77 | case 'h2': 78 | reactCode = `<${htmlTags} style={}>`; 79 | break; 80 | case 'h3': 81 | reactCode = `<${htmlTags} style={}>`; 82 | break; 83 | case 'p': 84 | reactCode = `<${htmlTags} style={}>`; 85 | break; 86 | case 'ul': 87 | reactCode = `<${htmlTags} style={}>`; 88 | break; 89 | case 'li': 90 | reactCode = `<${htmlTags} style={}>`; 91 | break; 92 | case 'img': 93 | reactCode = `<${htmlTags} alt='' src='' style={}/>`; 94 | break; 95 | default: 96 | reactCode = `<${htmlTags}>`; 97 | break; 98 | } 99 | 100 | // send new data to database 101 | pool 102 | .query( 103 | 'INSERT INTO individual_ui(tags, react_code, file_name, type, description) VALUES($1, $2, $3, $4, $5 )', 104 | [ searchTags, reactCode, fileName, htmlTags, description ] 105 | ) 106 | .then((data) => { 107 | // update the global state/Context 108 | pool.query('SELECT * FROM individual_ui').then((data) => { 109 | let item = data.rows[data.rows.length - 1]; // just added item 110 | Storage.get(`${item.file_name}.jpg`).then((url) => { 111 | item.url = url; 112 | dispatch({ 113 | type: 'generator_add_details', 114 | payload: { 115 | item: item 116 | } 117 | }); 118 | props.history.push('/detailPage'); 119 | }); 120 | }); 121 | }) 122 | .catch((err) => console.log(err)); 123 | } catch (err) { 124 | console.warn(err); 125 | } 126 | } 127 | 128 | return ( 129 |
    130 |
    131 |

    UI Generator

    132 |
    133 |
    134 | 135 |
    136 | 137 |
    138 |
    139 |
    140 |
    141 | 153 | {userData.htmlTags === 'input' && ( 154 | 160 | )} 161 | 167 | 168 | 174 | 177 |
    178 |
    179 |
    180 | ); 181 | } 182 | 183 | export default withRouter(Generator); 184 | -------------------------------------------------------------------------------- /src/containers/HierarchyContainer.jsx: -------------------------------------------------------------------------------- 1 | import '../assets/css/BuildPage.css'; 2 | import React, { useState, useEffect } from 'react'; 3 | import BuildItem from '../components/BuildItem.jsx'; 4 | 5 | const HierarchyContainer = (props) => { 6 | const {items} = props; 7 | 8 | function renderItems(items, level = 0) { 9 | return items.map((item) => { 10 | if (Array.isArray(item)) return renderItems(item, level+1); 11 | return ; 12 | }); 13 | } 14 | 15 | 16 | return ( 17 |
    18 |
    19 |

    HIERARCHY

    20 | {items && renderItems(items)} 21 |
    22 |
    23 | ); 24 | }; 25 | 26 | export default HierarchyContainer; 27 | -------------------------------------------------------------------------------- /src/containers/LeftContainer.jsx: -------------------------------------------------------------------------------- 1 | // import "../assets/css/LeftContainer.css"; 2 | import React, { useState } from "react"; 3 | import { Context } from "../context/MyProvider.js"; 4 | const cloneDeep = require("lodash.clonedeep"); 5 | import UiLibrary from "./UiLibrary.jsx"; 6 | 7 | const StyleContainer = (props) => { 8 | const { globalState, dispatch } = React.useContext(Context); 9 | const [innerHTML, setInnerHTML] = useState(""); 10 | const [navName, setNavName] = useState(""); 11 | const [navColor, setNavColor] = useState(""); 12 | const [buttonStyle, setButtonStyle] = useState({ 13 | width: "", 14 | height: "", 15 | borderRadius: "", 16 | border: "", 17 | backgroundColor: "", 18 | boxShadow: "", 19 | color: "", 20 | }); 21 | const [imgSource, setImageSource] = useState({ 22 | src: "", 23 | }); 24 | const [input, setInput] = useState({ 25 | fontColor: "", 26 | fontWeight: "", 27 | fontFamily: "", 28 | fontStyle: "", 29 | }); 30 | 31 | function handleChange(e) { 32 | setInput({ ...input, [e.target.name]: e.target.value }); 33 | } 34 | 35 | function handleInnerHTML(e) { 36 | setInnerHTML(e.target.value); 37 | } 38 | 39 | function handleImageSource(e) { 40 | setImageSource({ ...imgSource, [e.target.name]: e.target.value }); 41 | } 42 | 43 | function handleNavColor(e) { 44 | setNavColor(e.target.value); 45 | } 46 | function handleNavName(e) { 47 | setNavName(e.target.value); 48 | } 49 | 50 | function handleButtonStyle(e) { 51 | setButtonStyle({ ...buttonStyle, [e.target.name]: e.target.value }); 52 | } 53 | 54 | function handleClick(e) { 55 | e.preventDefault(); 56 | 57 | let code = cloneDeep(globalState.clickedItem.react_code); 58 | let style; 59 | let splitCode; 60 | if ( 61 | globalState.clickedItem.type !== "img" && 62 | globalState.clickedItem.type !== "ul" && 63 | globalState.clickedItem.type !== "button" 64 | ) { 65 | splitCode = code.split("{}>"); 66 | style = `{{fontColor: '${input.fontColor}', fontWeight: '${input.fontWeight}', fontFamily: '${input.fontFamily}' }}>${innerHTML}`; 67 | } else if (globalState.clickedItem.type === "img") { 68 | (splitCode = code.split("' src='' style={")), 69 | (style = `${imgSource.src.split(".")[0]}' src='${ 70 | imgSource.src 71 | }' style={{height: '${imgSource.height}', width: '${ 72 | imgSource.width 73 | }'}`); 74 | } else if (globalState.clickedItem.type === "ul") { 75 | splitCode = code.split("{}>"); 76 | style = `{{listStyleType: 'none', margin: 0, overflow: 'hidden', backgroundColor: '${navColor}'}}>${navName}`; 77 | } else if (globalState.clickedItem.type === "button") { 78 | splitCode = code.split("{}>"); 79 | style = `{{width: '${buttonStyle.width}', height: '${buttonStyle.height}', borderRadius: '${buttonStyle.borderRadius}', border: '${buttonStyle.border}', backgroundColor: '${buttonStyle.backgroundColor}', boxShadow:'${buttonStyle.boxShadow}', fontWeight: '${input.fontWeight}', fontFamily: '${input.fontFamily}', fontColor: '${input.fontColor}', fontStyle: '${input.fontStyle}'}}>${innerHTML}`; 80 | } 81 | 82 | globalState.clickedItem.react_code = splitCode[0] + style + splitCode[1]; 83 | 84 | dispatch({ 85 | type: "updateBuildUiItems", 86 | payload: globalState.clickedItem, 87 | }); 88 | } 89 | 90 | return ( 91 |
    92 |
    93 |

    Styling

    94 |
    95 |
    96 | {globalState.clickedItem.type === "img" && ( 97 | <> 98 | 104 | 110 | 116 | 117 | )} 118 | {globalState.clickedItem.type === "ul" && ( 119 | <> 120 | 126 | 132 | 133 | )} 134 | {globalState.clickedItem.type === "button" && ( 135 | <> 136 | 142 | 148 | 154 | 160 | 166 | 172 | 173 | )} 174 | {globalState.clickedItem.type !== "img" && 175 | globalState.clickedItem.type !== "ul" && ( 176 | <> 177 | 183 | 189 | 195 | 201 | 207 | 208 | )} 209 | 212 |
    213 |
    214 | ); 215 | }; 216 | 217 | export default StyleContainer; 218 | -------------------------------------------------------------------------------- /src/containers/StyleContainer.jsx: -------------------------------------------------------------------------------- 1 | // import "../assets/css/LeftContainer.css"; 2 | import React, { useState } from "react"; 3 | import { Context } from "../context/MyProvider.js"; 4 | const cloneDeep = require("lodash.clonedeep"); 5 | import UiLibrary from "./UiLibrary.jsx"; 6 | 7 | const StyleContainer = (props) => { 8 | const { globalState, dispatch } = React.useContext(Context); 9 | const [innerHTML, setInnerHTML] = useState(""); 10 | const [navName, setNavName] = useState(""); 11 | const [navColor, setNavColor] = useState(""); 12 | const [buttonStyle, setButtonStyle] = useState({ 13 | width: "", 14 | height: "", 15 | borderRadius: "", 16 | border: "", 17 | backgroundColor: "", 18 | boxShadow: "", 19 | color: "", 20 | }); 21 | const [imgSource, setImageSource] = useState({ 22 | src: "", 23 | }); 24 | const [input, setInput] = useState({ 25 | fontColor: "", 26 | fontWeight: "", 27 | fontFamily: "", 28 | fontStyle: "", 29 | }); 30 | 31 | function handleChange(e) { 32 | setInput({ ...input, [e.target.name]: e.target.value }); 33 | } 34 | 35 | function handleInnerHTML(e) { 36 | setInnerHTML(e.target.value); 37 | } 38 | 39 | function handleImageSource(e) { 40 | setImageSource({ ...imgSource, [e.target.name]: e.target.value }); 41 | } 42 | 43 | function handleNavColor(e) { 44 | setNavColor(e.target.value); 45 | } 46 | function handleNavName(e) { 47 | setNavName(e.target.value); 48 | } 49 | 50 | function handleButtonStyle(e) { 51 | setButtonStyle({ ...buttonStyle, [e.target.name]: e.target.value }); 52 | } 53 | 54 | function handleClick(e) { 55 | e.preventDefault(); 56 | 57 | let code = cloneDeep(globalState.clickedItem.react_code); 58 | let style; 59 | let splitCode; 60 | if ( 61 | globalState.clickedItem.type !== "img" && 62 | globalState.clickedItem.type !== "ul" && 63 | globalState.clickedItem.type !== "button" 64 | ) { 65 | splitCode = code.split("{}>"); 66 | style = `{{fontColor: '${input.fontColor}', fontWeight: '${input.fontWeight}', fontFamily: '${input.fontFamily}' }}>${innerHTML}`; 67 | } else if (globalState.clickedItem.type === "img") { 68 | (splitCode = code.split("' src='' style={")), 69 | (style = `${imgSource.src.split(".")[0]}' src='${ 70 | imgSource.src 71 | }' style={{height: '${imgSource.height}', width: '${ 72 | imgSource.width 73 | }'}`); 74 | } else if (globalState.clickedItem.type === "ul") { 75 | splitCode = code.split("{}>"); 76 | style = `{{listStyleType: 'none', margin: 0, overflow: 'hidden', backgroundColor: '${navColor}'}}>${navName}`; 77 | } else if (globalState.clickedItem.type === "button") { 78 | splitCode = code.split("{}>"); 79 | style = `{{width: '${buttonStyle.width}', height: '${buttonStyle.height}', borderRadius: '${buttonStyle.borderRadius}', border: '${buttonStyle.border}', backgroundColor: '${buttonStyle.backgroundColor}', boxShadow:'${buttonStyle.boxShadow}', fontWeight: '${input.fontWeight}', fontFamily: '${input.fontFamily}', fontColor: '${input.fontColor}', fontStyle: '${input.fontStyle}'}}>${innerHTML}`; 80 | } 81 | 82 | globalState.clickedItem.react_code = splitCode[0] + style + splitCode[1]; 83 | console.log(globalState.clickedItem) 84 | dispatch({ 85 | type: "updateBuildUiItems", 86 | payload: globalState.clickedItem, 87 | }); 88 | } 89 | 90 | return ( 91 |
    92 |

    Styling

    93 |
    94 | {globalState.clickedItem.type === "img" && ( 95 | <> 96 | 102 | 108 | 114 | 115 | )} 116 | {globalState.clickedItem.type === "ul" && ( 117 | <> 118 | 124 | 130 | 131 | )} 132 | {globalState.clickedItem.type === "button" && ( 133 | <> 134 | 140 | 146 | 152 | 158 | 164 | 170 | 171 | )} 172 | {globalState.clickedItem.type !== "img" && 173 | globalState.clickedItem.type !== "ul" && ( 174 | <> 175 | 181 | 187 | 193 | 199 | 205 | 206 | )} 207 | 210 |
    211 |
    212 | ); 213 | }; 214 | 215 | export default StyleContainer; 216 | -------------------------------------------------------------------------------- /src/containers/UiItem.jsx: -------------------------------------------------------------------------------- 1 | import "../assets/css/UiItem.css"; 2 | import React from "react"; 3 | import { Context } from "../context/MyProvider.js"; 4 | import { withRouter } from "react-router-dom"; 5 | const cloneDeep = require("lodash.clonedeep"); 6 | 7 | const UiItem = (props) => { 8 | const { globalState, dispatch } = React.useContext(Context); 9 | 10 | const onClick = (e) => { 11 | if (props.page === "uilibrary") { 12 | dispatch({ 13 | type: "uiLibrary_details", 14 | payload: cloneDeep(props.item), 15 | }); 16 | props.history.push("/detailPage"); 17 | } else if (props.page === "buildpage") { 18 | if (props.type === "div") { 19 | dispatch({ 20 | type: "updateBuildUiItems", 21 | payload: cloneDeep(props.item), 22 | }); 23 | } else { 24 | dispatch({ type: "showPopup", payload: cloneDeep(props.item) }); 25 | } 26 | } 27 | }; 28 | 29 | return ( 30 |
    31 | {props.file_name} 32 |

    {props.file_name}

    33 |

    {props.type}

    34 |

    {props.id}

    35 |

    {props.description}

    36 | 39 |
    40 | ); 41 | }; 42 | 43 | export default withRouter(UiItem); 44 | -------------------------------------------------------------------------------- /src/containers/UiLibrary.jsx: -------------------------------------------------------------------------------- 1 | import '../assets/css/UiLibrary.css'; 2 | import React, { useEffect, useState } from 'react'; 3 | import { Context } from '../context/MyProvider.js'; 4 | import UiItem from './UiItem.jsx'; 5 | import { withRouter } from 'react-router-dom'; 6 | import { Storage } from 'aws-amplify'; 7 | 8 | const UiLibrary = (props) => { 9 | const { globalState, dispatch } = React.useContext(Context); 10 | 11 | const renderItems = () => { 12 | return globalState.uiItems.map((item) => { 13 | const { id, name, file_name, type, description, url } = item; 14 | 15 | return ( 16 | 27 | ); 28 | }); 29 | }; 30 | 31 | return ( 32 |
    33 |
    34 |

    UiLibrary

    35 |
    36 |
    {renderItems()}
    37 |
    38 | ); 39 | }; 40 | 41 | export default withRouter(UiLibrary); 42 | -------------------------------------------------------------------------------- /src/context/MyProvider.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { Storage } from 'aws-amplify'; 3 | const cloneDeep = require('lodash.clonedeep'); 4 | let counter = 0; 5 | let toggle = false; 6 | export const Context = React.createContext(); 7 | 8 | function findIndex(array, id) { 9 | let index; 10 | 11 | for (let i = 0; i < array.length; i++) { 12 | if (Array.isArray(array[i])) { 13 | let nestedIndex = findIndex(array[i], id); 14 | if (nestedIndex !== undefined) { 15 | index = [ i, nestedIndex ]; 16 | break; 17 | } 18 | } else { 19 | if (array[i].buildId === id) { 20 | index = i; 21 | 22 | break; 23 | } 24 | } 25 | } 26 | return index; 27 | } 28 | 29 | function shoveItIn(buildUiItems, itemToMove) { 30 | if (Array.isArray(buildUiItems)) { 31 | buildUiItems.push(itemToMove); 32 | itemToMove.level += 1; 33 | return buildUiItems; 34 | } else { 35 | if (buildUiItems.type === 'div') { 36 | // if itemsToMove is an array 37 | itemToMove.level += 1; 38 | if (Array.isArray(itemToMove)) { 39 | return [ buildUiItems ].concat(itemToMove); 40 | } else { 41 | return [ buildUiItems, itemToMove ]; 42 | } 43 | } else { 44 | alert('This element is not nestable.'); 45 | return buildUiItems; 46 | } 47 | } 48 | } 49 | 50 | function pullOut(arr, targetIndex) { 51 | // pull out target and return updated nested arr 52 | if (targetIndex === 0) return arr; 53 | return arr.filter((el, index) => { 54 | if (index === targetIndex) el.level--; 55 | return index !== targetIndex; 56 | }); 57 | 58 | // [[{div}, {button}, {input}, {input2}]] => [[{div}, {input}, {input2}], {button}] // return [{div}, {input}, {input2}] 59 | // {div} index1 60 | // index1& index2 ({button}) => index1+1 (1) 61 | // if there was anything in buildUiItemsCopy at index 1 and onwards, just add it to the back 62 | } 63 | 64 | export const MyProvider = (props) => { 65 | // uiItems = all items 66 | // details = latest item's details from generator 67 | const initialState = { 68 | uiItems: [], 69 | details: {}, 70 | buildUiItems: [], 71 | showPopup: false, 72 | clickedItem: {}, 73 | language: 'react' 74 | }; 75 | 76 | const [ globalState, dispatch ] = React.useReducer(reducer, initialState); 77 | 78 | function reducer(state, action) { 79 | let index; 80 | let buildUiItemsCopy; 81 | let temp; 82 | let uiItemsCopy; 83 | 84 | switch (action.type) { 85 | case 'add_uis': 86 | return { 87 | ...state, 88 | uiItems: action.payload 89 | }; 90 | case 'generator_add_details': 91 | const { item } = action.payload; //uiItems = data.rows from generator 92 | let copy = [ ...state.uiItems, item ]; 93 | return { 94 | ...state, 95 | details: item, 96 | uiItems: [ ...copy ] 97 | }; 98 | case 'uiLibrary_details': 99 | return { 100 | ...state, 101 | details: action.payload 102 | }; 103 | case 'update_url': 104 | // updating the url for specific uiItem 105 | uiItemsCopy = [ ...state.uiItems ]; 106 | const uiItem = uiItemsCopy.filter((item) => item.id === parseInt(action.payload.id)); 107 | uiItem[0].url = action.payload.url; 108 | return { 109 | ...state, 110 | uiItems: uiItemsCopy 111 | }; 112 | case 'clearCode': 113 | return { 114 | ...state, 115 | language: 'react', 116 | buildUiItems: [] 117 | }; 118 | case 'updateBuildUiItems': 119 | uiItemsCopy = cloneDeep(state.uiItems); 120 | const newItemsCopy = action.payload; 121 | 122 | // update popup if true to hide left container 123 | // clear clickedItem 124 | let popup = state.showPopup; 125 | let clickedItem = state.clickedItem; 126 | if(state.showPopup) { 127 | popup = false; 128 | clickedItem = {}; 129 | } 130 | 131 | newItemsCopy.level = 0; 132 | newItemsCopy.buildId = Math.floor(Math.random() * 1000); 133 | counter++; 134 | buildUiItemsCopy = [ ...state.buildUiItems ]; 135 | if (counter === 2 && !toggle) { 136 | toggle = true; 137 | buildUiItemsCopy.push(newItemsCopy); 138 | counter = 0; 139 | console.log('line 139: buildUiItems: ', state.buildUiItems) 140 | return { 141 | ...state, 142 | buildUiItems: buildUiItemsCopy, 143 | showPopup: popup, 144 | clickedItem: clickedItem 145 | }; 146 | } else if (counter === 1 && toggle) { 147 | buildUiItemsCopy.push(newItemsCopy); 148 | counter = 0; 149 | console.log('line 149: buildUiItems: ', state.buildUiItems) 150 | return { 151 | ...state, 152 | buildUiItems: buildUiItemsCopy, 153 | showPopup: popup, 154 | clickedItem: clickedItem 155 | }; 156 | } else { 157 | return { ...state }; 158 | } 159 | case 'upClick': 160 | buildUiItemsCopy = [ ...state.buildUiItems ]; 161 | index = findIndex(buildUiItemsCopy, action.payload.buildId); 162 | // when index is arr (nested) 163 | if (Array.isArray(index)) { 164 | // index = [1,0] 165 | const [ index1, index2 ] = index; 166 | if (index1 !== 0) { 167 | temp = buildUiItemsCopy[index1]; 168 | buildUiItemsCopy[index1] = buildUiItemsCopy[index1 - 1]; 169 | buildUiItemsCopy[index1 - 1] = temp; 170 | } 171 | // don't let nested arr move! Already first item 172 | } else { 173 | // when index is num (not nested) 174 | if (index !== 0) { 175 | temp = buildUiItemsCopy[index]; 176 | buildUiItemsCopy[index] = buildUiItemsCopy[index - 1]; 177 | buildUiItemsCopy[index - 1] = temp; 178 | } 179 | } 180 | return { 181 | ...state, 182 | buildUiItems: buildUiItemsCopy 183 | }; 184 | case 'downClick': 185 | buildUiItemsCopy = [ ...state.buildUiItems ]; 186 | index = findIndex(buildUiItemsCopy, action.payload.buildId); 187 | if (Array.isArray(index)) { 188 | // index = [1,0] 189 | const [ index1, index2 ] = index; 190 | if (index1 !== buildUiItemsCopy.length - 1) { 191 | // make sure item is not last 192 | temp = buildUiItemsCopy[index1 + 1]; 193 | buildUiItemsCopy[index1 + 1] = buildUiItemsCopy[index1]; 194 | buildUiItemsCopy[index1] = temp; 195 | } 196 | } else { 197 | if (index !== buildUiItemsCopy.length - 1) { 198 | temp = buildUiItemsCopy[index]; 199 | buildUiItemsCopy[index] = buildUiItemsCopy[index + 1]; 200 | buildUiItemsCopy[index + 1] = temp; 201 | } 202 | } 203 | return { 204 | ...state, 205 | buildUiItems: buildUiItemsCopy 206 | }; 207 | case 'leftClick': 208 | buildUiItemsCopy = cloneDeep(state.buildUiItems); 209 | 210 | // Edge Cases 211 | // case 1: NO: [[{div}, {button}]] 212 | // don't want [[[{div}, {button}]]] button wanting to shove into div again 213 | // case 2: YES: [{div}, [{div2}, {button}], {button2}] => [[{div}, {div2}, {button}], {button2}] 214 | 215 | index = findIndex(buildUiItemsCopy, action.payload.buildId); 216 | let updatedBuildState; 217 | 218 | // case 1 & 2 if index === number 219 | // case 2: index = 1 220 | if (typeof index === 'number') { 221 | let temp = shoveItIn(buildUiItemsCopy[index - 1], buildUiItemsCopy[index]); 222 | // if no error, then modify, otherwise leave alone 223 | if (temp !== state.buildUiItems[index - 1]) { 224 | updatedBuildState = temp; 225 | 226 | buildUiItemsCopy[index - 1] = updatedBuildState; 227 | buildUiItemsCopy = buildUiItemsCopy.slice(0, index).concat(buildUiItemsCopy.slice(index + 1)); 228 | } 229 | } else { 230 | let [ index1, index2 ] = index; 231 | 232 | if (index2 > 0) { 233 | // if already nested, dont next another level 234 | return { ...state }; 235 | } else if (index2 === 0) { 236 | // moving a nested array into a div (above the nested array) 237 | updatedBuildState = shoveItIn(buildUiItemsCopy[index1 - 1], buildUiItemsCopy[index1]); 238 | 239 | const afterIndex1 = buildUiItemsCopy.slice(index1 + 1); // [{}, {}] 240 | const beforeIndex1 = buildUiItemsCopy.slice(0, index1 - 1); // [[{div}, {input}]] 241 | buildUiItemsCopy = [ ...beforeIndex1, updatedBuildState, ...afterIndex1 ]; 242 | } else { 243 | // General Case: pushing a button/input into a nested array above it [[{div},{button}], {button}, [{div}, {input}]] => [[{div},{button}, {button}]] 244 | const itemToMove = buildUiItemsCopy[index1][index2]; // [[{div}, [{div}, {button}]] {button}]