├── src ├── component │ ├── SidebarChat │ │ ├── SidebarChat.module.scss │ │ └── SidebarChat.js │ ├── SignIn │ │ ├── WhatsApp.svg.png │ │ └── SignIn.js │ ├── Home │ │ ├── Home.module.scss │ │ └── Home.js │ ├── Sidebar │ │ ├── Sidebar.module.scss │ │ └── Sidebar.js │ └── Chat │ │ ├── Chat.module.scss │ │ └── Chat.js ├── index.css ├── index.js ├── RequireAuth │ └── RequireAuth.js ├── App.js └── firebase.js ├── firestore.indexes.json ├── .firebaserc ├── public ├── favicon.ico ├── robots.txt ├── manifest.json └── index.html ├── postcss.config.js ├── database.rules.json ├── tailwind.config.js ├── firestore.rules ├── .gitignore ├── firebase.json ├── .firebase └── hosting.YnVpbGQ.cache ├── package.json └── README.md /src/component/SidebarChat/SidebarChat.module.scss: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /firestore.indexes.json: -------------------------------------------------------------------------------- 1 | { 2 | "indexes": [], 3 | "fieldOverrides": [] 4 | } 5 | -------------------------------------------------------------------------------- /.firebaserc: -------------------------------------------------------------------------------- 1 | { 2 | "projects": { 3 | "default": "friends-app-a2a22" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grim-firefly/friends-app/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/component/SignIn/WhatsApp.svg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grim-firefly/friends-app/HEAD/src/component/SignIn/WhatsApp.svg.png -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | 'postcss-import': {}, 4 | tailwindcss: {}, 5 | autoprefixer: {}, 6 | }, 7 | } 8 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | body{ 6 | background-color: #dfdfdd; 7 | 8 | } 9 | /* @import './component/Home/Home.module.scss'; */ -------------------------------------------------------------------------------- /database.rules.json: -------------------------------------------------------------------------------- 1 | { 2 | /* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */ 3 | "rules": { 4 | ".read": false, 5 | ".write": false 6 | } 7 | } -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: [ 4 | "./src/**/*.{js,jsx,ts,tsx}", 5 | ], 6 | theme: { 7 | extend: {}, 8 | }, 9 | plugins: [], 10 | } 11 | -------------------------------------------------------------------------------- /firestore.rules: -------------------------------------------------------------------------------- 1 | rules_version = '2'; 2 | service cloud.firestore { 3 | match /databases/{database}/documents { 4 | match /{document=**} { 5 | allow read, write: if 6 | request.time < timestamp.date(2022, 9, 30); 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /src/component/Home/Home.module.scss: -------------------------------------------------------------------------------- 1 | .app__body { 2 | // background-color: #f8f8f8; 3 | background-color: #ececec; 4 | height: 90vh; 5 | width: 90vw; 6 | overflow: hidden; 7 | 8 | } 9 | 10 | @media (max-width: 1100px) { 11 | .app__body { 12 | width: 100%; 13 | } 14 | } -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | const root = ReactDOM.createRoot(document.getElementById('root')); 7 | root.render( 8 | // 9 | 10 | 11 | ); 12 | 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # dependencies 3 | /node_modules 4 | /.pnp 5 | .pnp.js 6 | 7 | # testing 8 | /coverage 9 | 10 | # production 11 | /build 12 | 13 | # misc 14 | .DS_Store 15 | .env.local 16 | .env.development.local 17 | .env.test.local 18 | .env.production.local 19 | 20 | npm-debug.log* 21 | yarn-debug.log* 22 | yarn-error.log* 23 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /src/RequireAuth/RequireAuth.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { useAuthState } from 'react-firebase-hooks/auth'; 3 | import { auth } from '../firebase'; 4 | import { Navigate, useLocation } from 'react-router-dom'; 5 | import SignIn from './../component/SignIn/SignIn'; 6 | const RequireAuth = ({ children }) => { 7 | const [user] = useAuthState(auth); 8 | const location = useLocation(); 9 | if (!user) { 10 | // return 11 | return 12 | } 13 | return children; 14 | } 15 | export default RequireAuth; -------------------------------------------------------------------------------- /src/component/Home/Home.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Chat from '../Chat/Chat'; 3 | import Sidebar from '../Sidebar/Sidebar'; 4 | import { Route, Routes } from 'react-router-dom'; 5 | import Style from './Home.module.scss'; 6 | const Home = () => { 7 | return ( 8 |
9 |
10 | {/* sidebar */} 11 | 12 | 13 | {/* 14 | } > 15 | } /> 16 | 17 | 18 | {/* chat */} 19 | 20 | {/* */} 21 |
22 |
23 | ); 24 | } 25 | export default Home; -------------------------------------------------------------------------------- /src/component/SidebarChat/SidebarChat.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Style from './SidebarChat.module.scss'; 3 | import { Link } from 'react-router-dom'; 4 | const SidebarChat = (props) => { 5 | return ( 6 | 7 |
8 |
9 | 10 |
11 |
12 |

{props.name}

13 |

{props.message}

14 |
15 |
16 | 17 | ); 18 | } 19 | export default SidebarChat; -------------------------------------------------------------------------------- /firebase.json: -------------------------------------------------------------------------------- 1 | { 2 | "hosting": { 3 | "public": "build", 4 | "ignore": [ 5 | "firebase.json", 6 | "**/.*", 7 | "**/node_modules/**" 8 | ], 9 | "rewrites": [ 10 | { 11 | "source": "**", 12 | "destination": "/index.html" 13 | } 14 | ] 15 | }, 16 | "database": { 17 | "rules": "database.rules.json" 18 | }, 19 | "firestore": { 20 | "rules": "firestore.rules", 21 | "indexes": "firestore.indexes.json" 22 | }, 23 | "emulators": { 24 | "firestore": { 25 | "port": 8080 26 | }, 27 | "database": { 28 | "port": 9000 29 | }, 30 | "hosting": { 31 | "port": 5000 32 | }, 33 | "pubsub": { 34 | "port": 8085 35 | }, 36 | "ui": { 37 | "enabled": true 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/component/SignIn/SignIn.js: -------------------------------------------------------------------------------- 1 | import React , {useEffect}from 'react'; 2 | import { useSignInWithGoogle, useAuthState } from 'react-firebase-hooks/auth'; 3 | import { auth } from '../../firebase'; 4 | import { useLocation, useNavigate } from 'react-router-dom'; 5 | import logo from './WhatsApp.svg.png'; 6 | const SignIn = () => { 7 | const [user] = useAuthState(auth); 8 | const [signInWithGoogle] = useSignInWithGoogle(auth); 9 | const location = useLocation(); 10 | const navigate = useNavigate(); 11 | const dest = location.state?.from || '/'; 12 | 13 | useEffect(() => { 14 | if (user) { 15 | navigate(dest); 16 | } 17 | }, [user]); 18 | 19 | return ( 20 |
21 |
22 | 23 |
24 |
25 | 27 |
28 |
29 | ); 30 | } 31 | export default SignIn; -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Home from './component/Home/Home'; 3 | import { BrowserRouter as Routers, Route, Routes } from 'react-router-dom'; 4 | import SignIn from './component/SignIn/SignIn'; 5 | import Chat from './component/Chat/Chat'; 6 | import RequireAuth from './RequireAuth/RequireAuth'; 7 | 8 | function App() { 9 | return ( 10 |
11 |

Friends App

12 | 13 | 14 | 16 | 17 | 18 | } replace > 19 | 21 | 22 | 23 | } /> 24 | 25 | } /> 26 | 27 | 28 |
29 | ); 30 | } 31 | 32 | export default App; 33 | -------------------------------------------------------------------------------- /src/firebase.js: -------------------------------------------------------------------------------- 1 | // Import the functions you need from the SDKs you need 2 | import { initializeApp } from "firebase/app"; 3 | import { getAnalytics } from "firebase/analytics"; 4 | import { getAuth } from "firebase/auth"; 5 | import { getFirestore } from "firebase/firestore"; 6 | // TODO: Add SDKs for Firebase products that you want to use 7 | // https://firebase.google.com/docs/web/setup#available-libraries 8 | 9 | // Your web app's Firebase configuration 10 | // For Firebase JS SDK v7.20.0 and later, measurementId is optional 11 | const firebaseConfig = { 12 | apiKey: process.env.REACT_APP_apiKey, 13 | authDomain: process.env.REACT_APP_authDomain, 14 | projectId: process.env.REACT_APP_projectId, 15 | storageBucket: process.env.REACT_APP_storageBucket, 16 | messagingSenderId: process.env.REACT_APP_messagingSenderId, 17 | appId: process.env.REACT_APP_appId, 18 | measurementId: process.env.REACT_APP_measurementId, 19 | }; 20 | 21 | // Initialize Firebase 22 | const app = initializeApp(firebaseConfig); 23 | const analytics = getAnalytics(app); 24 | const auth = getAuth(app); 25 | const db= getFirestore(app); 26 | export {auth} ; 27 | export default db; -------------------------------------------------------------------------------- /.firebase/hosting.YnVpbGQ.cache: -------------------------------------------------------------------------------- 1 | favicon.ico,1661661583974,eae62e993eb980ec8a25058c39d5a51feab118bd2100c4deebb2a9c158ec11f9 2 | manifest.json,1661665764578,aff3449bdc238776f5d6d967f19ec491b36aed5fb7f23ccff6500736fd58494a 3 | robots.txt,1661661584489,bfe106a3fb878dc83461c86818bf74fc1bdc7f28538ba613cd3e775516ce8b49 4 | asset-manifest.json,1662300120756,89fac8d17707176adadd07fd24f6b10aaec9f9e5efa0697928919d3eb9d5c171 5 | index.html,1662300120756,ec872d5178a216310d3d601b32dd122feb7ff3b7d2e7f15fe9c97f8e1d3a06c7 6 | static/css/main.9845b400.css.map,1662300120771,deaaeda292b77008c00f250af54af797275193887d921c5f3d3dec76380b1815 7 | static/js/main.4a21126b.js.LICENSE.txt,1662300120770,3c10b827033fd54fac3657ecfe0da368d5f83528ac987a9267df56d9221e93d7 8 | static/css/main.9845b400.css,1662300120770,6ee22952d5b47ff8c3dbc2605c1c11d066a7e3cc8b20e57ac8e8e8c3426546d2 9 | static/media/WhatsApp.svg.532a3fcbb9f0b6177731.png,1662300120770,399be1bd5a8f2647d4a0a56dbb7cf96906ce7f9da57392138d7ecead797d95ef 10 | static/js/main.4a21126b.js,1662300120771,76edfb918b710735fe27bb0f415aa965e08ce61eeaf40cc05d9c7adc60b2680a 11 | static/js/main.4a21126b.js.map,1662300120773,7daddf630558472d3771d42fa444604244d6683e294aa5b45c585db535460760 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "friends-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.5", 7 | "@testing-library/react": "^13.3.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "firebase": "^9.9.3", 10 | "react": "^18.2.0", 11 | "react-dom": "^18.2.0", 12 | "react-firebase-hooks": "^5.0.3", 13 | "react-icons": "^4.4.0", 14 | "react-router-dom": "^6.3.0", 15 | "react-scripts": "5.0.1", 16 | "sass": "^1.54.5", 17 | "web-vitals": "^2.1.4" 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 | "devDependencies": { 44 | "autoprefixer": "^10.4.8", 45 | "postcss": "^8.4.16", 46 | "postcss-import": "^14.1.0", 47 | "tailwindcss": "^3.1.8" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/component/Sidebar/Sidebar.module.scss: -------------------------------------------------------------------------------- 1 | .sidebar { 2 | flex: 0.3; 3 | border-right: 1px solid lightgray; 4 | display: flex; 5 | flex-direction: column; 6 | .addnew__room{ 7 | top: 100%; 8 | right: 0%; 9 | } 10 | .sidebar__btn { 11 | font-size: 20px; 12 | height: 40px; 13 | width: 40px; 14 | display: inline-flex; 15 | justify-content: center; 16 | align-items: center; 17 | transition: all 0.3s linear; 18 | color: gray; 19 | 20 | &:hover { 21 | background-color: #FFF; 22 | } 23 | 24 | } 25 | 26 | .sidebar__btn_head { 27 | // border: 1px solid #ccc; 28 | width: 50px; 29 | height: 50px; 30 | overflow: hidden; 31 | display: flex; 32 | justify-content: center; 33 | align-items: center; 34 | justify-items: center; 35 | 36 | img { 37 | width: 100%; 38 | height: 100%; 39 | display: block; 40 | object-fit: cover; 41 | } 42 | } 43 | 44 | 45 | .sidebar__search{ 46 | display: flex; 47 | align-items: center; 48 | background-color: #f6f6f6; 49 | height: 49px; 50 | padding: 10px; 51 | .searchbar__container{ 52 | display: flex; 53 | align-items: center; 54 | background-color: #FFF; 55 | width: 100%; 56 | height: 35px; 57 | border-radius: 20px; 58 | input{ 59 | margin-left: 10px; 60 | border: none; 61 | outline:none; 62 | } 63 | } 64 | } 65 | .sidebar__chat{ 66 | flex:1; 67 | background-color: rgb(255, 255, 255); 68 | } 69 | } -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/component/Chat/Chat.module.scss: -------------------------------------------------------------------------------- 1 | .app__chat { 2 | flex: 0.7; 3 | display: flex; 4 | flex-direction: column; 5 | 6 | .chat__header { 7 | display: flex; 8 | padding: 8px 20px; 9 | align-items: center; 10 | border-bottom: 1px solid lightgray; 11 | 12 | .sidebar__btn { 13 | font-size: 18px; 14 | height: 30px; 15 | width: 30px; 16 | display: inline-flex; 17 | justify-content: center; 18 | align-items: center; 19 | transition: all 0.3s linear; 20 | color: gray; 21 | 22 | &:hover { 23 | background-color: rgba(255, 255, 255, 0.2); 24 | } 25 | 26 | } 27 | } 28 | 29 | 30 | .chat__body { 31 | flex: 1; 32 | background: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png'); 33 | background-repeat: repeat; 34 | padding: 30px; 35 | overflow-y: scroll; 36 | 37 | .chat__message { 38 | background-color: #fff; 39 | font-size: 14px; 40 | padding: 10px; 41 | border-radius: 10px; 42 | width: fit-content; 43 | position: relative; 44 | margin-bottom: 20px; 45 | 46 | .chat__name { 47 | position: absolute; 48 | white-space: nowrap; 49 | font-size: xx-small; 50 | top: -15px; 51 | font-weight: bold; 52 | 53 | } 54 | 55 | .chat__timestamp { 56 | font-size: xx-small; 57 | margin-left: 10px; 58 | 59 | } 60 | } 61 | 62 | .chat__receiver { 63 | margin-left: auto; 64 | background-color: #dcf8c6; 65 | } 66 | } 67 | 68 | .chat__footer { 69 | display: flex; 70 | justify-content: space-between; 71 | align-items: center; 72 | height: 62px; 73 | border-top: 1px solid lightgray; 74 | 75 | .chat__massage__box { 76 | flex: 1; 77 | .send__message_form { 78 | flex: 1; 79 | display: flex; 80 | 81 | .send__massage__input { 82 | flex: 1; 83 | border: none; 84 | outline: none; 85 | border-radius: 30px; 86 | padding: 10px; 87 | 88 | } 89 | } 90 | } 91 | 92 | .footer__emoji__btn{ 93 | padding: 10px; 94 | color: gray; 95 | } 96 | 97 | } 98 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | 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. 37 | 38 | 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. 39 | 40 | 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. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | 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) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | 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) 55 | 56 | ### Making a Progressive Web App 57 | 58 | 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) 59 | 60 | ### Advanced Configuration 61 | 62 | 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) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | 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) 71 | -------------------------------------------------------------------------------- /src/component/Chat/Chat.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from 'react'; 2 | // import from 'react'; 3 | import Style from './Chat.module.scss'; 4 | import { BsSearch, BsThreeDotsVertical, BsEmojiHeartEyes, BsMic } from 'react-icons/bs'; 5 | import { IoAttachOutline } from 'react-icons/io5'; 6 | import { useParams } from 'react-router-dom'; 7 | import db, { auth } from '../../firebase'; 8 | import { collection, getDocs, doc, addDoc, onSnapshot, serverTimestamp, orderBy, query } from "firebase/firestore"; 9 | import { useAuthState } from 'react-firebase-hooks/auth'; 10 | const Chat = () => { 11 | const [input, setInput] = useState(''); 12 | const { roomId } = useParams(); 13 | const [roomName, setRoomName] = useState(''); 14 | const [message, setMessage] = useState([]); 15 | const connRef = collection(db, 'rooms'); 16 | const [user] = useAuthState(auth); 17 | 18 | useEffect(() => { 19 | if (roomId) { 20 | const getRoomName = async () => { 21 | onSnapshot(doc(connRef, roomId), (snapshot) => { 22 | setRoomName(snapshot.data().name); 23 | }); 24 | } 25 | 26 | 27 | const getMessages = async () => { 28 | const qq = query(collection(connRef, roomId, 'messages'), orderBy('timestamp', 'asc')); 29 | onSnapshot(qq, (snapshot) => { 30 | setMessage(snapshot.docs.map((doc) => doc.data())); 31 | }); 32 | } 33 | getRoomName(); 34 | getMessages(); 35 | 36 | 37 | 38 | } 39 | 40 | }, [roomId]); 41 | 42 | 43 | 44 | const sendMessage = (e) => { 45 | e.preventDefault(); 46 | if (roomId) { 47 | const addMessage = async () => { 48 | await addDoc(collection(connRef, roomId, 'messages'), { 49 | message: input, 50 | name: user.displayName, 51 | timestamp: serverTimestamp() 52 | }); 53 | } 54 | addMessage(); 55 | } 56 | setInput(''); 57 | } 58 | 59 | return ( 60 | < div className={`${Style.app__chat}` 61 | }> 62 |
63 |
64 | 65 |
66 |
67 |

{roomName}

68 |

Last seen today at 10:30 PM

69 |
70 |
71 | 72 | 73 | 74 | 75 | 76 |
77 |
78 |
79 | { 80 | message.map((msg) => ( 81 |
82 | { 83 | msg.name == user.displayName ? 84 | '' : {msg.name} 85 | 86 | } 87 | 88 |

{msg.message}{new Date(msg.timestamp * 1000).toUTCString()}

89 |
90 | 91 | 92 | )) 93 | } 94 | 95 | 96 | 97 |
98 |
99 |
100 | 101 |
102 |
103 |
104 | { 105 | setInput(e.target.value) 106 | }} className={`${Style.send__massage__input}`} type="text" placeholder="Type a message" /> 107 | 108 |
109 |
110 |
111 | 112 | 113 | 114 | 115 |
116 |
117 | 118 | ); 119 | } 120 | export default Chat; -------------------------------------------------------------------------------- /src/component/Sidebar/Sidebar.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from 'react'; 2 | import { useState } from 'react'; 3 | import { HiOutlineUserCircle } from 'react-icons/hi'; 4 | import { FiMoreVertical } from 'react-icons/fi'; 5 | import { MdOutlineDonutLarge } from 'react-icons/md'; 6 | import { BsFillChatLeftTextFill, BsSearch } from 'react-icons/bs'; 7 | import Style from './Sidebar.module.scss'; 8 | import SidebarChat from '../SidebarChat/SidebarChat'; 9 | //firebase 10 | import db from '../../firebase'; 11 | import { collection, onSnapshot, doc, addDoc } from "firebase/firestore"; 12 | import { signOut } from 'firebase/auth'; 13 | import { auth } from '../../firebase'; 14 | import { useAuthState } from 'react-firebase-hooks/auth'; 15 | 16 | const Sidebar = () => { 17 | const [menu, setMenu] = useState(false); 18 | const [addNew, setAddNew] = useState(false); 19 | const [rooms, setRooms] = useState([]); 20 | const [NewRoomName, setNewRoomName] = useState(''); 21 | const connRef = collection(db, "rooms"); 22 | const [user] = useAuthState(auth); 23 | useEffect(() => { 24 | const getRooms = async () => { 25 | onSnapshot(connRef, (snapshot) => { 26 | setRooms(snapshot.docs.map((doc) => ({ id: doc.id, data: doc.data() }))); 27 | }); 28 | }; 29 | getRooms(); 30 | 31 | 32 | 33 | }, []); 34 | 35 | const addNewRoom = (e) => { 36 | e.preventDefault(); 37 | if (NewRoomName) { 38 | const addNewRoom = async () => { 39 | await addDoc(connRef, { 40 | name: NewRoomName 41 | }); 42 | } 43 | addNewRoom(); 44 | 45 | } 46 | setNewRoomName(''); 47 | setAddNew(false); 48 | 49 | } 50 | 51 | return ( 52 |
53 | {/* sidebar header */} 54 |
55 |
56 | 57 | 60 | 61 |
62 |
63 | 64 | 65 | 68 | 69 |
70 |
71 | { 72 | setNewRoomName(e.target.value); 73 | }} className=' rounded-lg px-1 border-none outline-none py-1' type="text" placeholder='Add new Room' name="newChat" id="" /> 74 | 75 |
76 |
77 | 78 | 79 |
80 | 81 | 82 | 83 | 84 |
85 | 86 | 87 |
88 |
89 | 90 | {/* sidebar search */} 91 |
92 |
93 | 94 | 95 | 96 |
97 |
98 | 99 | {/* sidebar chats */} 100 |
101 | { 102 | rooms.map(room => ( 103 | 104 | )) 105 | } 106 | 107 | 108 |
109 |
110 | ); 111 | } 112 | export default Sidebar; --------------------------------------------------------------------------------