├── public ├── favicon.ico └── index.html ├── .gitignore ├── src ├── index.js ├── components │ ├── ChatMessage.jsx │ ├── SignIn.jsx │ ├── CardUI.jsx │ └── ChatRoom.jsx ├── firebase.js ├── App.js └── App.css ├── package.json └── README.md /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arihant-jain-09/firechat-react/master/public/favicon.ico -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | ReactDOM.render( 6 | , 7 | document.getElementById('root') 8 | ); 9 | 10 | // If you want to start measuring performance in your app, pass a function 11 | // to log results (for example: reportWebVitals(console.log)) 12 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 13 | -------------------------------------------------------------------------------- /src/components/ChatMessage.jsx: -------------------------------------------------------------------------------- 1 | import {auth} from '../firebase' 2 | import CardUI from './CardUI' 3 | import {Grid,Paper} from '@material-ui/core' 4 | function ChatMessage (props){ 5 | const {text,uid,photoURL}=props.message; 6 | const messageClass=uid === auth.currentUser.uid?'sent':'received'; 7 | return( 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | ) 17 | } 18 | export default ChatMessage 19 | -------------------------------------------------------------------------------- /src/firebase.js: -------------------------------------------------------------------------------- 1 | import firebase from 'firebase/app'; 2 | import 'firebase/firestore'; 3 | import 'firebase/auth'; 4 | firebase.initializeApp({ 5 | apiKey: "AIzaSyBWZC9xWMKEQMuGPyncAFlaVGnHlNwnEDY", 6 | authDomain: "superchat-33ed4.firebaseapp.com", 7 | projectId: "superchat-33ed4", 8 | storageBucket: "superchat-33ed4.appspot.com", 9 | messagingSenderId: "305060583764", 10 | appId: "1:305060583764:web:f11e117b65ec65e718d0c1", 11 | measurementId: "G-45GES8K7BV" 12 | }) 13 | export const firestore=firebase.firestore(); 14 | export const auth=firebase.auth(); 15 | export default firebase; 16 | -------------------------------------------------------------------------------- /src/components/SignIn.jsx: -------------------------------------------------------------------------------- 1 | import firebase,{auth} from '../firebase' 2 | import {makeStyles,Button} from '@material-ui/core' 3 | const useStyles = makeStyles((theme)=>{ 4 | return{ 5 | maindiv:{ 6 | backgroundColor:"#282c34" 7 | }, 8 | div:{ 9 | backgroundColor:"#282c34", 10 | width:'100%', 11 | height:'500px' 12 | }, 13 | button:{ 14 | position:"relative", 15 | top:"100px", 16 | left:'325px', 17 | backgroundColor:"#0d47a1", 18 | color:"white", 19 | padding:"20px 30px", 20 | "&:hover":{ 21 | backgroundColor: "#1976d2" 22 | } 23 | }, 24 | 25 | } 26 | }) 27 | function SignIn(){ 28 | const classes = useStyles(); 29 | const signInWithGoogle=()=>{ 30 | const provider=new firebase.auth.GoogleAuthProvider(); 31 | auth.signInWithPopup(provider); 32 | } 33 | return( 34 |
35 | 36 |
37 |
38 | ) 39 | } 40 | export default SignIn 41 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "superchat", 3 | "version": "0.1.0", 4 | "private": true, 5 | "homepage": "https://arihant-jain-09.github.io/firechat-react", 6 | "dependencies": { 7 | "@material-ui/core": "^4.11.3", 8 | "@material-ui/icons": "^4.11.2", 9 | "@testing-library/jest-dom": "^5.11.10", 10 | "@testing-library/react": "^11.2.6", 11 | "@testing-library/user-event": "^12.8.3", 12 | "firebase": "^8.3.2", 13 | "react": "^17.0.2", 14 | "react-dom": "^17.0.2", 15 | "react-firebase-hooks": "^3.0.3", 16 | "react-scripts": "4.0.3", 17 | "web-vitals": "^1.1.1" 18 | }, 19 | "scripts": { 20 | "start": "react-scripts start", 21 | "build": "react-scripts build", 22 | "test": "react-scripts test", 23 | "eject": "react-scripts eject", 24 | "predeploy": "npm run build", 25 | "deploy": "gh-pages -d build" 26 | }, 27 | "eslintConfig": { 28 | "extends": [ 29 | "react-app", 30 | "react-app/jest" 31 | ] 32 | }, 33 | "browserslist": { 34 | "production": [ 35 | ">0.2%", 36 | "not dead", 37 | "not op_mini all" 38 | ], 39 | "development": [ 40 | "last 1 chrome version", 41 | "last 1 firefox version", 42 | "last 1 safari version" 43 | ] 44 | }, 45 | "devDependencies": { 46 | "gh-pages": "^3.1.0" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import {makeStyles,Grid,Container,AppBar,Toolbar,Typography,Button} from '@material-ui/core' 3 | import SignIn from './components/SignIn' 4 | import ChatRoom from './components/ChatRoom' 5 | import { useAuthState } from 'react-firebase-hooks/auth'; 6 | import {auth} from './firebase' 7 | const useStyles=makeStyles((theme)=>{ 8 | return{ 9 | 10 | appbar:{ 11 | width:'70%', 12 | marginLeft:"auto", 13 | marginRight:"auto" 14 | }, 15 | grid:{ 16 | display:'block', 17 | width:"70%", 18 | marginLeft:"auto", 19 | marginRight:"auto", 20 | }, 21 | typography:{ 22 | flexGrow:1, 23 | letterSpacing:'2px', 24 | } 25 | } 26 | }) 27 | function App() { 28 | const classes=useStyles(); 29 | const [user]=useAuthState(auth); 30 | return ( 31 |
32 | 33 | 34 | 35 | 36 | FireChat 37 | 38 | {user?:null} 39 | 40 | 41 | 42 | {user?:} 43 | 44 | 45 |
46 | ); 47 | } 48 | 49 | export default App; 50 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 33 | 34 | 35 | 36 |
37 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/components/CardUI.jsx: -------------------------------------------------------------------------------- 1 | import {Card,CardHeader,Avatar,Typography} from '@material-ui/core'; 2 | import {makeStyles} from '@material-ui/core'; 3 | const useStyles=makeStyles((theme)=>{ 4 | return{ 5 | card:{ 6 | height:theme.spacing(5), 7 | borderRadius:theme.spacing(0) 8 | }, 9 | cardHeader:{ 10 | height:theme.spacing(1.1), 11 | position:'relative', 12 | left:(props)=>{ 13 | if(props.messageClass==="sent"){ 14 | return '350px' 15 | } 16 | }, 17 | width:(props)=>{ 18 | if(props.messageClass==='received'){ 19 | return '50%' 20 | } 21 | } 22 | }, 23 | avatar:{ 24 | width:theme.spacing(3), 25 | height:theme.spacing(3) 26 | }, 27 | cardheadtypo:{ 28 | color:theme.palette.secondary.contrastText, 29 | // borderRadius:"16px 2px 2px 16px" , 30 | borderRadius:theme.spacing(2), 31 | padding: theme.spacing(1), 32 | paddingLeft:theme.spacing(2.2), 33 | backgroundColor:(props)=>{ 34 | if(props.messageClass==="sent"){ 35 | return theme.palette.secondary.light 36 | } 37 | else { 38 | return theme.palette.primary.light 39 | } 40 | } 41 | }, 42 | avatardefault:{ 43 | marginRight:theme.spacing(0.5) 44 | } 45 | } 46 | }) 47 | const Inputlength=(text)=>{ 48 | console.log(text); 49 | if(text.length<61) 50 | return text 51 | else{ 52 | return "Msg should be less than 60 characters" 53 | } 54 | } 55 | function CardUI(props){ 56 | const classes=useStyles(props); 57 | return
58 | 59 | } 63 | title={{Inputlength(props.text)}}/> 64 | 65 |
66 | } 67 | export default CardUI 68 | -------------------------------------------------------------------------------- /src/components/ChatRoom.jsx: -------------------------------------------------------------------------------- 1 | import React,{useState,useRef} from 'react' 2 | import firebase,{firestore,auth} from '../firebase' 3 | import { useCollectionData } from 'react-firebase-hooks/firestore'; 4 | import ChatMessage from './ChatMessage'; 5 | import {Button,makeStyles,Input} from '@material-ui/core' 6 | import SendIcon from '@material-ui/icons/Send'; 7 | const useStyles=makeStyles((theme)=>{ 8 | return{ 9 | text:{ 10 | marginTop:theme.spacing(1), 11 | marginBottom:theme.spacing(3), 12 | padding:'5px', 13 | width:'92%' 14 | }, 15 | input:{ 16 | backgroundColor:"white" 17 | }, 18 | btn:{ 19 | height:'42px', 20 | "&:hover":{ 21 | backgroundColor:"#506999" 22 | } 23 | } 24 | } 25 | }) 26 | 27 | function ChatRoom(){ 28 | const classes=useStyles(); 29 | const dummy = useRef(); 30 | const messageRef=firestore.collection('messages'); 31 | const query=messageRef.orderBy('createdAt').limit(25); 32 | //here we will use useCollectionData hook to look for changes in real time 33 | //it returns an object where each object is the chat message in database 34 | //Synatx useCollectionData(query,options) 35 | //options takes an Object idField to give id parameter to each message 36 | const [messages]=useCollectionData(query,{idField:'id'}); 37 | //it returns an object where each object is the chat message in database 38 | const [formValue,setformValue]=useState(''); 39 | //after user press Submit forms calls sendMessage 40 | const sendMessage=async (e)=>{ 41 | e.preventDefault(); 42 | const {uid,photoURL}=auth.currentUser; 43 | //to add data just use .add method which takes an object 44 | await messageRef.add({ 45 | text:formValue, 46 | createdAt:firebase.firestore.FieldValue.serverTimestamp(), 47 | uid, 48 | photoURL 49 | }) 50 | setformValue(''); 51 | dummy.current.scrollIntoView({behaviour:'smooth'}); 52 | } 53 | return( 54 | <> 55 |
56 | {/* if messages then only map */} 57 | {messages && messages.map((msg)=>)} 58 |
59 |
60 |
61 | setformValue(e.target.value)} value={formValue} /> 62 | 63 | 64 |
65 | 66 | ) 67 | } 68 | export default ChatRoom 69 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #282c34; 3 | } 4 | 5 | .App { 6 | text-align: center; 7 | max-width: 728px; 8 | margin: 0 auto; 9 | } 10 | 11 | .App header { 12 | background-color: #181717; 13 | height: 10vh; 14 | min-height: 50px; 15 | color: white; 16 | position: fixed; 17 | width: 100%; 18 | max-width: 728px; 19 | top: 0; 20 | display: flex; 21 | align-items: center; 22 | justify-content: space-between; 23 | z-index: 99; 24 | padding: 10px; 25 | box-sizing: border-box; 26 | } 27 | 28 | .App section { 29 | display: flex; 30 | flex-direction: column; 31 | justify-content: center; 32 | min-height: 100vh; 33 | background-color: rgb(40, 37, 53); 34 | } 35 | 36 | main { 37 | padding: 10px; 38 | height: 80vh; 39 | margin: 10vh 0 10vh; 40 | overflow-y: scroll; 41 | display: flex; 42 | flex-direction: column; 43 | } 44 | 45 | main::-webkit-scrollbar { 46 | width: 0.25rem; 47 | } 48 | 49 | main::-webkit-scrollbar-track { 50 | background: #1e1e24; 51 | } 52 | 53 | main::-webkit-scrollbar-thumb { 54 | background: #6649b8; 55 | } 56 | 57 | form { 58 | height: 10vh; 59 | position: fixed; 60 | bottom: 0; 61 | background-color: rgb(24, 23, 23); 62 | width: 100%; 63 | max-width: 728px; 64 | display: flex; 65 | font-size: 1.5rem; 66 | } 67 | 68 | form button { 69 | width: 20%; 70 | background-color: rgb(56, 56, 143); 71 | } 72 | 73 | 74 | input { 75 | line-height: 1.5; 76 | width: 100%; 77 | font-size: 1.5rem; 78 | background: rgb(58, 58, 58); 79 | color: white; 80 | outline: none; 81 | border: none; 82 | padding: 0 10px; 83 | } 84 | 85 | button { 86 | background-color: #282c34; /* Green */ 87 | border: none; 88 | color: white; 89 | padding: 15px 32px; 90 | text-align: center; 91 | text-decoration: none; 92 | display: inline-block; 93 | cursor: pointer; 94 | font-size: 1.25rem; 95 | } 96 | 97 | button:disabled { 98 | opacity: 0.5; 99 | cursor: not-allowed; 100 | } 101 | 102 | 103 | .sign-in { 104 | color: #282c34; 105 | background: white; 106 | max-width: 400px; 107 | margin: 0 auto; 108 | } 109 | 110 | 111 | 112 | 113 | ul, li { 114 | text-align: left; 115 | list-style: none; 116 | } 117 | 118 | p { 119 | max-width: 500px; 120 | margin-bottom: 12px; 121 | line-height: 24px; 122 | padding: 10px 20px; 123 | border-radius: 25px; 124 | position: relative; 125 | color: white; 126 | text-align: center; 127 | } 128 | 129 | .message { 130 | display: flex; 131 | align-items: center; 132 | } 133 | 134 | 135 | .sent { 136 | flex-direction: row-reverse; 137 | } 138 | 139 | .sent p { 140 | color: white; 141 | background: #0b93f6; 142 | align-self: flex-end; 143 | } 144 | .received p { 145 | background: #e5e5ea; 146 | color: black; 147 | } 148 | 149 | img { 150 | width: 40px; 151 | height: 40px; 152 | border-radius: 50%; 153 | margin: 2px 5px; 154 | } 155 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | Deployed => https://arihant-jain-09.github.io/firechat-react/ 4 | 5 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 6 | 7 | ## Available Scripts 8 | 9 | In the project directory, you can run: 10 | 11 | ### `npm start` 12 | 13 | Runs the app in the development mode.\ 14 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 15 | 16 | The page will reload if you make edits.\ 17 | You will also see any lint errors in the console. 18 | 19 | ### `npm test` 20 | 21 | Launches the test runner in the interactive watch mode.\ 22 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 23 | 24 | ### `npm run build` 25 | 26 | Builds the app for production to the `build` folder.\ 27 | It correctly bundles React in production mode and optimizes the build for the best performance. 28 | 29 | The build is minified and the filenames include the hashes.\ 30 | Your app is ready to be deployed! 31 | 32 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 33 | 34 | ### `npm run eject` 35 | 36 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 37 | 38 | 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. 39 | 40 | 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. 41 | 42 | 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. 43 | 44 | ## Learn More 45 | 46 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 47 | 48 | To learn React, check out the [React documentation](https://reactjs.org/). 49 | 50 | ### Code Splitting 51 | 52 | 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) 53 | 54 | ### Analyzing the Bundle Size 55 | 56 | 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) 57 | 58 | ### Making a Progressive Web App 59 | 60 | 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) 61 | 62 | ### Advanced Configuration 63 | 64 | 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) 65 | 66 | ### Deployment 67 | 68 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 69 | 70 | ### `npm run build` fails to minify 71 | 72 | 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) 73 | --------------------------------------------------------------------------------