Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Google Authentication system and chat rooms feature #107

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
490 changes: 422 additions & 68 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.11.2",
"@material-ui/core": "^4.11.3",
"@material-ui/icons": "^4.11.2",
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.2.2",
"@testing-library/user-event": "^12.6.0",
"bcrypt": "^5.0.1",
"bootstrap": "^4.6.0",
"firebase": "^8.2.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.1",
"web-vitals": "^0.2.4"
},
Expand Down
90 changes: 12 additions & 78 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,83 +1,17 @@
.App {
text-align: center;
* {
margin: 0;
}

.Logo{
width:50px;
position:fixed;
right:70px;
top:25px;
.app {
height: 100vh;
display: grid;
place-items: center;
}

::placeholder{
font-weight: bold;
color:white;
opacity:1;
}

.NavBar{
background-color:#014293;
width:100%;
border-bottom:2px solid black;
height:100px;
position:fixed;
top:0px;
}

input{
background-color: black;
line-height: 30px;
width:250px;
}

.messenger{
display:inline-block;
position:fixed;
top:0px;
left:30px;
font-weight: bold;
font-size: 40px;
}

.dark{
position:fixed;
top:0px;
right:-150px;
outline: none;
}

footer{
position: fixed;
bottom:0;
height:10%;
width:100%;
background-color: #014293;
border-top:2px solid black;
}

.input{
margin-top:10px;
flex:1;
}

.blackName{
color:white !important;
}

.BlackNavBar{
background-color:black!important;
}

.dark_input{
color:white;
}

.footer_dark{
background-color: black;
}


.iconButton{
top:10px;
left:10px;
.app__container {
box-shadow: -1px 4px 20px -6px rgba(0, 0, 0, 0.3);
display: flex;
width: 85vw;
height: 90vh;
background-color: rgb(250, 250, 250);
}
123 changes: 31 additions & 92 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,102 +1,41 @@
import './App.css';
import {useState,useEffect,useRef} from 'react';
import {Button, Input,FormControl} from "@material-ui/core";
import Brightness4Icon from "@material-ui/icons/Brightness4"
import SendIcon from '@material-ui/icons/Send'
import logo from './logo.png';
import Messages from './Messages.js'
import db from "./firebase.js"
import firebase from "firebase";
import React, { useState } from "react";
import "./App.css";
import Sideroom from "./components/Sideroom";
import Chatroom from "./components/Chatroom";
import { Switch, BrowserRouter as Router, Route } from "react-router-dom";
import Login from "./components/Login";
import { useStateValue } from "./StateProvider";

function App() {

const [input,setInput]=useState("");
const [messages,setMessages]=useState([]);
const [username,setUsername]=useState("");
const [dark,setDark]=useState(false);
const messagesEndRef=useRef(null);

useEffect(()=>{
setUsername(prompt("Kindly Enter Your Name"));
},[])

useEffect(()=>{db.collection('messages').orderBy("timestamp","asc").onSnapshot(snapshot=>setMessages(snapshot.docs.map(doc=>doc.data())))},[])

useEffect(() => { scrollToBottom() }, [messages]);

const scrollToBottom = () => {
messagesEndRef.current?.scrollIntoView({ behavior: "auto" })
}

const newMessage= (event)=>{
event.preventDefault();
//setMessages([...messages,{message:input,username:username}]);
if(input!=="")
{
db.collection('messages').add({username:username,message:input,timestamp:firebase.firestore.FieldValue.serverTimestamp()})
}
setInput("");
}



const theme=(event)=>{
if(dark===false)
{
document.body.classList.add('dark-bg');
setDark(true);
}
else
{
document.body.classList.remove('dark-bg');
setDark(false);
}
}

let but;
if(dark)
{
but=<input className={`input ${dark?"dark_input":""}`} placeholder="Write Your Message" value={input} onChange={event=>setInput(event.target.value)} />
}
else
{
but=<Input className={`input ${dark?"dark_input":""}`} placeholder="Write Your Message" value={input} onChange={event=>setInput(event.target.value)} />
}
const [{ user }, dispatch] = useStateValue();

return (
<div className="App">
<nav className={`NavBar ${dark?"BlackNavBar":""}`} >
<Button variant="contained" className="dark" onClick={theme} ><Brightness4Icon /></Button>
<h1 className="messenger" ><span className={`${dark?"blackName":""} `} style={{color:"orange"}}>Mess</span><span className={`${dark?"blackName":""} `} style={{color:"deeppink"}} >enger</span></h1>
<img className="Logo" src={logo} alt="messenger-logo" />
</nav>
<div className="scroll" >
<br/><br/><br/><br/><br/>
{
messages.map(message=><Messages messages={message} username={username} dark={dark} key={genKey()}/>)
}
<div />
<br/><br/><br/><br/><br/>
</div>
<div ref={messagesEndRef} />
<footer className={`${dark?"footer_dark":""}`} >
<form>
<FormControl>
{but}
</FormControl>
<Button className="iconButton" onClick={newMessage} type="submit" variant="contained" color="primary" > <SendIcon /></Button>
</form>
</footer>
<div className="app">
{!user ? (
<Login />
) : (
<div className="app__container">
<Router>
<Sideroom />
<Switch>
<Route path="/rooms/:roomid">
<Chatroom />
</Route>
<Route path="/">
<Chatroom />
</Route>
</Switch>
</Router>

</div>
)}
</div>
);
}

// keys generator:- every new call to this function will give numbs like 0,1,2,3....
const genKey = (function (){
var keyCode = 0
return function incKey(){
return keyCode++;
}
})();

export default App;
48 changes: 0 additions & 48 deletions src/Messages.css

This file was deleted.

68 changes: 0 additions & 68 deletions src/Messages.js

This file was deleted.

12 changes: 12 additions & 0 deletions src/StateProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React, { createContext, useReducer, useContext } from "react";

export const StateContext = createContext();


export const StateProvider = ({ reducer, initialState, children }) => (
<StateContext.Provider value={useReducer(reducer, initialState)}>
{children}
</StateContext.Provider>
);

export const useStateValue = () => useContext(StateContext);
Loading