├── .env ├── .gitignore ├── LICENSE ├── README.md ├── package-lock.json ├── package.json ├── public └── index.html └── src ├── components ├── App.js ├── Chats.js ├── Login.js └── Profile.js ├── contexts └── AuthContext.js ├── firebase.js ├── index.css └── index.js /.env: -------------------------------------------------------------------------------- 1 | REACT_APP_CHAT_ENGINE_KEY=2324e4f1-c135-4088-b0eb-4e76b3e770fc 2 | REACT_APP_CHAT_ENGINE_ID=449b4767-24ac-45b2-8dee-da9201267c47 -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Alper Efe Şahin 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EfeChat 2 | This project created by Alper Efe Şahin. I used React.js, Firebase, CHAT Engine Lib. and Icon lib. You can login with Facebook or Google. You can create new chat group, add new users to chat group, you can remove his/her, and you can delete the chat group easily. Also you can upload file like pdf or images etc. 3 | 4 | Here you can see some gifs via EfeChat: 5 | 6 | **Chat Screen:** 7 | 8 | ![gif1](https://user-images.githubusercontent.com/67283777/124601991-17fc1800-de71-11eb-8549-f233ce23ca71.gif) 9 | 10 | **Creating New Group:** 11 | 12 | ![gif2](https://user-images.githubusercontent.com/67283777/124602098-2ea26f00-de71-11eb-8338-93003fb01a41.gif) 13 | 14 | **Creating and Deleting the group:** 15 | 16 | ![gif3](https://user-images.githubusercontent.com/67283777/124602178-44179900-de71-11eb-9424-70b20d3ad976.gif) 17 | 18 | **Typing property:** 19 | 20 | ![gif4](https://user-images.githubusercontent.com/67283777/124602332-68737580-de71-11eb-8ab1-703a3228c3c5.gif) 21 | 22 | **Uploading image:** 23 | 24 | ![gif5](https://user-images.githubusercontent.com/67283777/124602373-71644700-de71-11eb-9a82-9d686f9a9f26.gif) 25 | 26 | **Profile page, and Logout process:** 27 | 28 | ![gif6](https://user-images.githubusercontent.com/67283777/124602410-7cb77280-de71-11eb-9fdc-b5716fab9b61.gif) 29 | 30 | 31 | # Getting Started with Create React App 32 | 33 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 34 | 35 | ## Available Scripts 36 | 37 | In the project directory, you can run: 38 | 39 | ### `npm start` 40 | 41 | Runs the app in the development mode.\ 42 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 43 | 44 | The page will reload if you make edits.\ 45 | You will also see any lint errors in the console. 46 | 47 | ### `npm test` 48 | 49 | Launches the test runner in the interactive watch mode.\ 50 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 51 | 52 | ### `npm run build` 53 | 54 | Builds the app for production to the `build` folder.\ 55 | It correctly bundles React in production mode and optimizes the build for the best performance. 56 | 57 | The build is minified and the filenames include the hashes.\ 58 | Your app is ready to be deployed! 59 | 60 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 61 | 62 | ### `npm run eject` 63 | 64 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 65 | 66 | 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. 67 | 68 | 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. 69 | 70 | 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. 71 | 72 | ## Learn More 73 | 74 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 75 | 76 | To learn React, check out the [React documentation](https://reactjs.org/). 77 | 78 | ### Code Splitting 79 | 80 | 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) 81 | 82 | ### Analyzing the Bundle Size 83 | 84 | 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) 85 | 86 | ### Making a Progressive Web App 87 | 88 | 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) 89 | 90 | ### Advanced Configuration 91 | 92 | 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) 93 | 94 | ### Deployment 95 | 96 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 97 | 98 | ### `npm run build` fails to minify 99 | 100 | 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) 101 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-chat-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@ant-design/icons": "^4.6.2", 7 | "@testing-library/jest-dom": "^5.14.1", 8 | "@testing-library/react": "^11.2.7", 9 | "@testing-library/user-event": "^12.8.3", 10 | "axios": "^0.21.1", 11 | "firebase": "^8.7.0", 12 | "react": "^17.0.2", 13 | "react-chat-engine": "^1.10.5", 14 | "react-dom": "^17.0.2", 15 | "react-router-dom": "^5.2.0", 16 | "react-scripts": "4.0.3", 17 | "web-vitals": "^1.1.2" 18 | }, 19 | "scripts": { 20 | "start": "react-scripts start", 21 | "build": "react-scripts build", 22 | "test": "react-scripts test", 23 | "eject": "react-scripts eject" 24 | }, 25 | "eslintConfig": { 26 | "extends": [ 27 | "react-app", 28 | "react-app/jest" 29 | ] 30 | }, 31 | "browserslist": { 32 | "production": [ 33 | ">0.2%", 34 | "not dead", 35 | "not op_mini all" 36 | ], 37 | "development": [ 38 | "last 1 chrome version", 39 | "last 1 firefox version", 40 | "last 1 safari version" 41 | ] 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | React Chat App 7 | 8 | 9 | 10 |
11 | 12 | 13 | -------------------------------------------------------------------------------- /src/components/App.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | import { BrowserRouter as Router, Switch, Route } from "react-router-dom"; 4 | 5 | import { AuthProvider } from "../contexts/AuthContext"; 6 | 7 | import Chats from "./Chats"; 8 | import Login from "./Login"; 9 | import Profile from "./Profile"; 10 | 11 | function App() { 12 | return ( 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | ); 25 | } 26 | 27 | export default App; 28 | -------------------------------------------------------------------------------- /src/components/Chats.js: -------------------------------------------------------------------------------- 1 | import React, { useRef, useState, useEffect } from "react"; 2 | 3 | import axios from "axios"; 4 | import { useHistory } from "react-router-dom"; 5 | import { ChatEngine } from "react-chat-engine"; 6 | import { UserOutlined } from "@ant-design/icons"; 7 | import { useAuth } from "../contexts/AuthContext"; 8 | 9 | import { auth } from "../firebase"; 10 | 11 | export default function Chats() { 12 | const didMountRef = useRef(false); 13 | const [loading, setLoading] = useState(true); 14 | const { user } = useAuth(); 15 | const history = useHistory(); 16 | 17 | async function handleLogout() { 18 | await auth.signOut(); 19 | history.push("/"); 20 | } 21 | 22 | async function getFile(url) { 23 | let response = await fetch(url); 24 | let data = await response.blob(); 25 | return new File([data], "test.jpg", { type: "image/jpeg" }); 26 | } 27 | 28 | const goProfilePage = () => { 29 | history.push("/profile"); 30 | }; 31 | 32 | useEffect(() => { 33 | if (!didMountRef.current) { 34 | didMountRef.current = true; 35 | 36 | if (!user || user === null) { 37 | history.push("/"); 38 | return; 39 | } 40 | 41 | axios 42 | .get("https://api.chatengine.io/users/me/", { 43 | headers: { 44 | "project-id": process.env.REACT_APP_CHAT_ENGINE_ID, 45 | "user-name": user.email, 46 | "user-secret": user.uid, 47 | }, 48 | }) 49 | 50 | .then(() => setLoading(false)) 51 | 52 | .catch((e) => { 53 | let formdata = new FormData(); 54 | formdata.append("email", user.email); 55 | formdata.append("username", user.email); 56 | formdata.append("secret", user.uid); 57 | 58 | getFile(user.photoURL).then((avatar) => { 59 | formdata.append("avatar", avatar, avatar.name); 60 | 61 | axios 62 | .post("https://api.chatengine.io/users/", formdata, { 63 | headers: { 64 | "private-key": process.env.REACT_APP_CHAT_ENGINE_KEY, 65 | }, 66 | }) 67 | .then(() => setLoading(false)) 68 | .catch((e) => console.log("e", e.response)); 69 | }); 70 | }); 71 | } 72 | }, [user, history]); 73 | 74 | if (!user || loading) return
; 75 | 76 | return ( 77 |
78 |
79 |
EfeChat
80 | 81 |
82 | Logout 83 |
84 |
85 | Profile 86 |
87 |
88 | 89 | 95 |
96 | ); 97 | } 98 | -------------------------------------------------------------------------------- /src/components/Login.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { GoogleOutlined, FacebookOutlined } from "@ant-design/icons"; 3 | import firebase from "firebase/app"; 4 | import { auth } from "../firebase"; 5 | 6 | const Login = () => { 7 | return ( 8 |
9 |
10 |

Welcome To EfeChat

11 |
14 | auth.signInWithRedirect(new firebase.auth.GoogleAuthProvider()) 15 | } 16 | > 17 | Sign in With Google 18 |
19 |

20 |
23 | auth.signInWithRedirect(new firebase.auth.FacebookAuthProvider()) 24 | } 25 | > 26 | Sign in With Facebook 27 |
28 |
29 |
30 | ); 31 | }; 32 | 33 | export default Login; 34 | -------------------------------------------------------------------------------- /src/components/Profile.js: -------------------------------------------------------------------------------- 1 | import { useAuth } from "../contexts/AuthContext"; 2 | 3 | export default function Profile() { 4 | const { user } = useAuth(); 5 | 6 | return ( 7 |
8 |

Welcome to Profile Page

9 |
10 | profileImg 15 |
16 | 17 |
18 |

• Display name: {user.displayName}

19 |

• Email: {user.email}

20 |

• User id: {user.uid}

21 |
22 |
23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /src/contexts/AuthContext.js: -------------------------------------------------------------------------------- 1 | import React, { useContext, useState, useEffect } from "react"; 2 | 3 | import { useHistory } from "react-router-dom"; 4 | import { auth } from "../firebase"; 5 | 6 | const AuthContext = React.createContext(); 7 | 8 | export const useAuth = () => useContext(AuthContext); 9 | 10 | export const AuthProvider = ({ children }) => { 11 | const [loading, setLoading] = useState(true); 12 | const [user, setUser] = useState(null); 13 | const history = useHistory(); 14 | 15 | useEffect(() => { 16 | auth.onAuthStateChanged((user) => { 17 | setUser(user); 18 | setLoading(false); 19 | if (user) history.push("/chats"); 20 | }); 21 | }, [user, history]); 22 | 23 | const value = { user }; 24 | 25 | return ( 26 | 27 | {!loading && children} 28 | 29 | ); 30 | }; 31 | -------------------------------------------------------------------------------- /src/firebase.js: -------------------------------------------------------------------------------- 1 | import firebase from "firebase/app"; 2 | 3 | import "firebase/auth"; 4 | 5 | export const auth = firebase 6 | .initializeApp({ 7 | apiKey: "AIzaSyCr8isPY7CbWtswom67_paZeMeTNGDqLTY", 8 | authDomain: "new-react-chat-app-615eb.firebaseapp.com", 9 | projectId: "new-react-chat-app-615eb", 10 | storageBucket: "new-react-chat-app-615eb.appspot.com", 11 | messagingSenderId: "974799296411", 12 | appId: "1:974799296411:web:9cbe3107f32aac7ac4333e", 13 | }) 14 | .auth(); 15 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | /* Global */ 2 | 3 | * { 4 | font-family: Avenir, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji; 5 | } 6 | 7 | /* Chats Page */ 8 | 9 | .chats-page { 10 | position: absolute; 11 | top: 0px; 12 | left: 0px; 13 | width: 100vw; 14 | height: 100vh; 15 | } 16 | 17 | .nav-bar { 18 | width: 100%; 19 | height: 66px; 20 | background-color: #144ca7f5; 21 | } 22 | 23 | .logo-tab { 24 | position: absolute; 25 | left: 22px; 26 | top: 12px; 27 | font-size: 32px; 28 | font-weight: 700; 29 | color: white; 30 | } 31 | 32 | .logout-tab { 33 | position: absolute; 34 | top: 22px; 35 | right: 22px; 36 | color: white; 37 | cursor: pointer; 38 | font-size: medium; 39 | } 40 | 41 | .profile-section { 42 | position: absolute; 43 | right: 100px; 44 | top: 23.3px; 45 | font-size: medium; 46 | color: white; 47 | cursor: pointer; 48 | } 49 | 50 | ::-webkit-scrollbar { 51 | width: 0; 52 | background: transparent; 53 | } 54 | 55 | /* Login Page */ 56 | 57 | #login-page { 58 | background-image: linear-gradient(#40a9ff33, #096dd9); 59 | position: absolute; 60 | top: 0px; 61 | bottom: 0px; 62 | left: 0px; 63 | right: 0px; 64 | } 65 | 66 | #login-card { 67 | position: relative; 68 | top: calc(50vh - 144px); 69 | left: calc(50vw - 210px); 70 | padding-top: 36px; 71 | padding-bottom: 66px; 72 | width: 420px; 73 | text-align: center; 74 | background-color: white; 75 | border-radius: 22px; 76 | } 77 | 78 | .login-button { 79 | cursor: pointer; 80 | color: white; 81 | padding: 12px; 82 | border-radius: 8px; 83 | display: inline-block; 84 | } 85 | 86 | .facebook { 87 | background-color: #3b5998; 88 | } 89 | 90 | .google { 91 | background-color: #4285f4; 92 | color: white; 93 | } 94 | 95 | #loading-container { 96 | position: absolute; 97 | top: 0px; 98 | bottom: 0px; 99 | left: 0px; 100 | right: 0px; 101 | background-color: rgb(255, 255, 255, 0.22); 102 | } 103 | 104 | #loading-icon { 105 | font-size: 66px; 106 | position: relative; 107 | left: calc(50vw - 33px); 108 | top: calc(50vh - 22px); 109 | } 110 | 111 | /* Profile Page */ 112 | 113 | .profile-page { 114 | text-align: center; 115 | background-color: #E4F9F5; 116 | display: grid; 117 | background-image: linear-gradient(#40a9ff33, #096dd9d2); 118 | position: absolute; 119 | top: 0px; 120 | bottom: 0px; 121 | left: 0px; 122 | right: 0px; 123 | } 124 | 125 | .profile-page img { 126 | border-radius: 50%; 127 | width: 180px; 128 | } 129 | 130 | .profile-page p { 131 | font-weight: 500; 132 | color: white; 133 | } 134 | 135 | .middle-container { 136 | margin-top: 50px; 137 | margin-bottom: 50px; 138 | font-size: larger; 139 | } -------------------------------------------------------------------------------- /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 | 6 | ReactDOM.render( 7 | 8 | 9 | , 10 | document.getElementById("root") 11 | ); 12 | --------------------------------------------------------------------------------