From 125db5e67b64bba096b0d9436bc019cee80667f7 Mon Sep 17 00:00:00 2001 From: sanket-kogekar Date: Sun, 8 Aug 2021 10:28:09 +0530 Subject: [PATCH 1/2] Restructure --- README.md | 70 ---------------- public/index.html | 2 +- src/App.js | 8 -- src/componentss/Chatbox.js | 81 ------------------ src/componentss/Landing.js | 111 ------------------------- src/componentss/Transitions/Failure.js | 35 -------- src/componentss/Transitions/Goodbye.js | 35 -------- src/componentss/Transitions/Loading.js | 71 ---------------- src/componentss/Transitions/Success.js | 61 -------------- src/contexts/AppContextProvider.js | 40 +-------- src/contexts/socket.js | 2 +- 11 files changed, 3 insertions(+), 513 deletions(-) delete mode 100644 README.md delete mode 100644 src/componentss/Chatbox.js delete mode 100644 src/componentss/Landing.js delete mode 100644 src/componentss/Transitions/Failure.js delete mode 100644 src/componentss/Transitions/Goodbye.js delete mode 100644 src/componentss/Transitions/Loading.js delete mode 100644 src/componentss/Transitions/Success.js diff --git a/README.md b/README.md deleted file mode 100644 index 0c83cde..0000000 --- a/README.md +++ /dev/null @@ -1,70 +0,0 @@ -# Getting Started with Create React App - -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). - -## Available Scripts - -In the project directory, you can run: - -### `npm start` - -Runs the app in the development mode.\ -Open [http://localhost:3000](http://localhost:3000) to view it in the browser. - -The page will reload if you make edits.\ -You will also see any lint errors in the console. - -### `npm test` - -Launches the test runner in the interactive watch mode.\ -See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `npm run build` - -Builds the app for production to the `build` folder.\ -It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.\ -Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `npm run eject` - -**Note: this is a one-way operation. Once you `eject`, you can’t go back!** - -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. - -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. - -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. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). - -### Code Splitting - -This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) - -### Analyzing the Bundle Size - -This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) - -### Making a Progressive Web App - -This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) - -### Advanced Configuration - -This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) - -### Deployment - -This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) - -### `npm run build` fails to minify - -This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) diff --git a/public/index.html b/public/index.html index 6252f08..904c9cd 100644 --- a/public/index.html +++ b/public/index.html @@ -3,7 +3,7 @@ - React App + ChatBoxPro diff --git a/src/App.js b/src/App.js index 55a61c0..27755e9 100644 --- a/src/App.js +++ b/src/App.js @@ -1,5 +1,4 @@ import "./App.css"; -// import Landing from "./componentss/Landing"; import AppContextProvider from "./contexts/AppContextProvider"; import { SocketContext, socket } from "./contexts/socket"; import SiteContainer from "./components/SiteContainer"; @@ -8,13 +7,6 @@ function App() { return ( - {/* */} diff --git a/src/componentss/Chatbox.js b/src/componentss/Chatbox.js deleted file mode 100644 index 346ba7a..0000000 --- a/src/componentss/Chatbox.js +++ /dev/null @@ -1,81 +0,0 @@ -import React, { useContext } from "react"; -import { AppContext } from "../contexts/AppContextProvider"; -import { makeStyles } from "@material-ui/core/styles"; -import { - IconButton, - TextField, - Input, - OutlinedInput, -} from "@material-ui/core/"; -import CancelRoundedIcon from "@material-ui/icons/CancelRounded"; -const thinkingImg = "https://loading.io/s/icon/lrdtah.svg"; - -const useStyles = makeStyles((theme) => ({ - thinkingAnimation: { - display: "flex", - justifyContent: "center", - height: "40vh", - width: "40vh", - marginLeft: "auto", - marginRight: "auto", - marginTop: "10%", - marginBottom: "5%", - }, - inputStyle: { - fontFamily: "Open Sans", - fontSize: "18.9px", - }, - inputCenter: { - textAlign: "center", - }, -})); - -function Chatbox() { - const classes = useStyles(); - const { state, actions } = useContext(AppContext); - const { connectionId, receivedMessage } = state; - const { disconnect } = actions; - - return ( -
-
- - {connectionId}  - { - disconnect(); - }} - > - - - -
-
- {!!receivedMessage ? ( -
-

{receivedMessage}

-
- ) : ( -
- Thinking Image -
- )} -
-
-
- - -
-
- ); -} - -export default Chatbox; diff --git a/src/componentss/Landing.js b/src/componentss/Landing.js deleted file mode 100644 index ed71506..0000000 --- a/src/componentss/Landing.js +++ /dev/null @@ -1,111 +0,0 @@ -import React, { useState, useContext, useEffect } from "react"; -import { AppContext } from "../contexts/AppContextProvider"; -import Success from "./Transitions/Success"; -import Failure from "./Transitions/Failure"; -import Chatbox from "./Chatbox"; -import { IconButton, Link, TextField } from "@material-ui/core/"; -import { makeStyles } from "@material-ui/core/styles"; -import ArrowBackIosRoundedIcon from "@material-ui/icons/ArrowBackIosRounded"; -import { SocketContext } from "../contexts/socket"; - -const useStyles = makeStyles((theme) => ({ - wrapCircleAroundIcon: { - border: "solid 2px", - }, -})); - -function Landing() { - const classes = useStyles(); - const [displayClientId, setDisplayClientId] = useState(true); - const socket = useContext(SocketContext); - const { state, actions } = useContext(AppContext); - const { clientId, connectionId, failureMessage } = state; - const { setClientId, setConnectionId, setFailureMessage, setChatRoom } = - actions; - - const [connectionIdValue, setConnectionIdValue] = useState(""); - - useEffect(() => { - // Receive unique Id to connect with others - socket.on("pushClientId", (id) => { - setClientId(id); - }); - // Connects to connectionId - socket.on("connection-details", (connectionDetails) => { - if (connectionDetails.status) { - setConnectionId(connectionDetails.connectionId); - setChatRoom(connectionDetails.chatRoom); - } else { - setFailureMessage(connectionDetails.message); - } - }); - socket.on("somebody-connected-with-you", (connectionDetails) => { - if (connectionDetails.status) { - setConnectionId(connectionDetails.connectionId); - setChatRoom(connectionDetails.chatRoom); - } - }); - }, []); - - const submitOnSixCharaters = (id) => { - const regex = /^[0-9\b]+$/; - if (id === "" || regex.test(id)) { - setConnectionIdValue(id); - if (id.length === 6 || id.length > 6) { - socket.emit("join", id.substring(0, 6)); - setConnectionIdValue(""); - } - } - }; - - if (displayClientId && !connectionId && !failureMessage) { - return ( - <> -

Share Your ID

-
-

{clientId}

-
- { - setDisplayClientId(false); - }} - > - Enter Friend's ID Instead? - - - ); - } else if (!displayClientId && !connectionId && !failureMessage) { - return ( - <> -

Your Friend's ID

-
- submitOnSixCharaters(event.target.value)} - /> -
-
- { - setDisplayClientId(true); - }} - > - - - - ); - } else if (!!connectionId && !failureMessage) { - return ; - } else if (!!failureMessage && !connectionId) { - return ; - } else if (!failureMessage && !!connectionId) { - return ; - } -} - -export default Landing; diff --git a/src/componentss/Transitions/Failure.js b/src/componentss/Transitions/Failure.js deleted file mode 100644 index 0da3ecd..0000000 --- a/src/componentss/Transitions/Failure.js +++ /dev/null @@ -1,35 +0,0 @@ -// import React, { useState, useEffect } from "react"; -// import { makeStyles } from "@material-ui/core/styles"; -// import progressGif from "../../assets/images/progress.gif"; - -// const useStyles = makeStyles((theme) => ({ -// failed: { -// display: "flex", -// justifyContent: "center", -// height: "100%", -// width: "100%", -// marginLeft: "auto", -// marginRight: "auto", -// marginTop: "10%", -// marginBottom: "5%", -// }, -// oneLiner: { -// textAlign: "center", -// }, -// })); - -// function Failure({ message }) { -// const classes = useStyles(); - -// return ( -//
-//
-// Failed! -//
-//

{message}

-//

Going back in {counter}

-//
-// ); -// } - -// export default Failure; diff --git a/src/componentss/Transitions/Goodbye.js b/src/componentss/Transitions/Goodbye.js deleted file mode 100644 index a434d19..0000000 --- a/src/componentss/Transitions/Goodbye.js +++ /dev/null @@ -1,35 +0,0 @@ -import React, { useState, useEffect } from "react"; -import { makeStyles } from "@material-ui/core/styles"; -import progressGif from "../../assets/images/progress.gif"; - -const useStyles = makeStyles((theme) => ({ - goodBye: { - display: "flex", - justifyContent: "center", - height: "100%", - width: "100%", - marginLeft: "auto", - marginRight: "auto", - marginTop: "10%", - marginBottom: "5%", - }, - oneLiner: { - textAlign: "center", - }, -})); - -function Goodbye() { - const classes = useStyles(); - const oneLiner = "User '234534' Waved You a Good-Bye!"; - - return ( -
-
- GoodBye! -
-

{oneLiner}

-
- ); -} - -export default Goodbye; diff --git a/src/componentss/Transitions/Loading.js b/src/componentss/Transitions/Loading.js deleted file mode 100644 index 28b47b8..0000000 --- a/src/componentss/Transitions/Loading.js +++ /dev/null @@ -1,71 +0,0 @@ -import React, { useState, useEffect, useContext } from "react"; -import { makeStyles } from "@material-ui/core/styles"; -import progressGif from "../../assets/images/progress.gif"; -import { AppContext } from "../../contexts/AppContextProvider"; -import Success from "./Success"; -import Failure from "./Failure"; - -// const loadingImg = "https://cdn.auth0.com/blog/auth0-react-sample/assets/loading.svg"; - -const useStyles = makeStyles((theme) => ({ - loadingSpinner: { - display: "flex", - justifyContent: "center", - height: "100%", - width: "100%", - marginLeft: "auto", - marginRight: "auto", - marginTop: "10%", - marginBottom: "5%", - }, - oneLiner: { - textAlign: "center", - }, -})); - -function Loading() { - const classes = useStyles(); - const [oneLiner, setOneLiner] = useState(null); - const { state, actions } = useContext(AppContext); - const { connectionId, failureMessage } = state; - - const [displayComponent, setDisplayComponent] = useState(null); - - const getRandomInteger = (min, max) => { - return Math.floor(Math.random() * (max - min + 1) + min); - }; - - const oneLinerArray = [ - "Chatbox is live! It means whatever you type is shared instantly - Happy Chatting!", - "We do not record any user activity. No Logs. No History. No Database.", - "Welcome to the Next Generation chatbox. This is how it is supposed to be!", - "Synchronous chat: Chatbox Pro, Asynchronous chat: Every other app you know.", - ]; - - useEffect(() => { - setOneLiner(oneLinerArray[getRandomInteger(0, oneLinerArray.length - 1)]); - const timer = setTimeout(() => { - !!connectionId - ? setDisplayComponent("Success") - : setDisplayComponent("Failure"); - }, 1000); - return () => clearTimeout(timer); - }, []); - - if (displayComponent === "Success") { - return ; - } else if (displayComponent === "Failure") { - return ; - } else { - return ( -
-
- Connecting.. -
-

{oneLiner}

-
- ); - } -} - -export default Loading; diff --git a/src/componentss/Transitions/Success.js b/src/componentss/Transitions/Success.js deleted file mode 100644 index 3e3c07f..0000000 --- a/src/componentss/Transitions/Success.js +++ /dev/null @@ -1,61 +0,0 @@ -import React, { useState, useEffect, useContext } from "react"; -import { makeStyles } from "@material-ui/core/styles"; -import progressGif from "../../assets/images/progress.gif"; -import Chatbox from "./../Chatbox"; - -const useStyles = makeStyles((theme) => ({ - success: { - display: "flex", - justifyContent: "center", - height: "100%", - width: "100%", - marginLeft: "auto", - marginRight: "auto", - marginTop: "10%", - marginBottom: "5%", - }, - oneLiner: { - textAlign: "center", - }, -})); - -function Success() { - const classes = useStyles(); - const [oneLiner, setOneLiner] = useState(null); - - const getRandomInteger = (min, max) => { - return Math.floor(Math.random() * (max - min + 1) + min); - }; - - const [displayComponent, setDisplayComponent] = useState(null); - - useEffect(() => { - setOneLiner(oneLinerArray[getRandomInteger(0, oneLinerArray.length - 1)]); - const timer = setTimeout(() => { - setDisplayComponent("Chatbox"); - }, 2000); - return () => clearTimeout(timer); - }, []); - - const oneLinerArray = [ - "And BOOM! You are Connected!", - "Connection Successful!", - "Happy Chatting!", - "Connected! Say Hello to your friend!", - ]; - - if (displayComponent === "Chatbox") { - return ; - } else { - return ( -
-
- Success! -
-

{oneLiner}

-
- ); - } -} - -export default Success; diff --git a/src/contexts/AppContextProvider.js b/src/contexts/AppContextProvider.js index a6ad809..7990635 100644 --- a/src/contexts/AppContextProvider.js +++ b/src/contexts/AppContextProvider.js @@ -1,4 +1,4 @@ -import React, { useReducer } from "react"; +import React from "react"; import axios from "axios"; import ContextProvider from "./ContextProvider"; export const AppContext = React.createContext(); @@ -116,45 +116,7 @@ const useAction = (state, dispatch) => { const middleware = (params) => { const { state, dispatch, action, extensions } = params; - const { axios } = extensions; switch (action.type) { - case actionTypes.GET_CLIENT_ID: - // axios({ - // method: "GET", - // url: "http://localhost:5000/getId", - // headers: { - // withCredentials: false, - // "Content-Type": "application/json", - // //Accept: "application/json", - // //Origin: "http://localhost:3000", - // }, - // }).then((response) => { - // dispatch({ - // type: actionTypes.SET_CLIENT_ID, - // id: response.id, - // }); - // }); - break; - case actionTypes.CONNECT: - // axios({ - // method: "POST", - // url: `http://localhost:5000/connect` + action.id, - // headers: { - // withCredentials: false, - // "Content-Type": "application/json", - // //Accept: "application/json", - // //Origin: "http://localhost:3000", - // }, - // }).then((response) => { - // dispatch({ - // type: actionTypes.SET_CONNECTION_ID, - // id: response.id, - // }); - // REMEMBER TO ASSIGN FALSE TO displayLoading state - // }); - break; - case actionTypes.DISCONNECT: - break; default: return dispatch(action); } diff --git a/src/contexts/socket.js b/src/contexts/socket.js index cbf3587..f5632db 100644 --- a/src/contexts/socket.js +++ b/src/contexts/socket.js @@ -1,6 +1,6 @@ import { createContext } from "react"; import socketio from "socket.io-client"; -const SOCKET_URL = "http://localhost:5000/"; +const SOCKET_URL = process.env.SOCKET_URL || "http://localhost:5000/"; export const socket = socketio.connect(SOCKET_URL); export const SocketContext = createContext(); From 8c402451565ae20cc9b32015ab6b1a68d83d0825 Mon Sep 17 00:00:00 2001 From: sanket-kogekar Date: Sun, 8 Aug 2021 10:31:15 +0530 Subject: [PATCH 2/2] Removed unused axios lib. --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 35c8eba..5abb280 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,6 @@ "dependencies": { "@material-ui/core": "^4.11.4", "@material-ui/icons": "^4.11.2", - "axios": "^0.21.0", "react": "^17.0.2", "react-dom": "^17.0.2", "react-scripts": "4.0.3",