This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import useContext. | |
import { useContext } from 'react'; | |
// import Context. | |
import Context from '../Context'; | |
// import cometchat ui. | |
import { CometChatMessages } from '../cometchat-pro-react-ui-kit/CometChatWorkspace/src'; | |
function Chat() { | |
const { user, currentRide } = useContext(Context); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const firebaseConfig = { | |
apiKey: `${config.apiKey}`, | |
authDomain: `${config.authDomain}`, | |
databaseURL: `${config.databaseURL}`, | |
projectId: `${config.projectId}`, | |
storageBucket: `${config.storageBucket}`, | |
messagingSenderId: `${config.messagingSenderId}`, | |
appId: `${config.appId}`, | |
measurementId: `${config.measurementId}` | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Login</title> | |
<link rel="stylesheet" href="/css/styles.css"> | |
<script defer src="https://widget-js.cometchat.io/v2/cometchatwidget.js"></script> | |
</head> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener('DOMContentLoaded', function() { | |
function shouldRedirectToHomePage(user, isLoginPage) { | |
return user && isLoginPage; | |
} | |
function shouldRedirectToLoginPage(user, isLoginPage) { | |
return !user && !isLoginPage; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const loading = document.getElementById('loading'); | |
function hideLoading() { | |
loading.classList.add('loading--hide'); | |
} | |
function showLoading() { | |
loading.classList.remove('loading--hide'); | |
loading.classList.add('loading--active'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
/** | |
* register a new account - register with firebase and cometchat. | |
* @param {*} object - user's information that will be used to register. | |
*/ | |
function registerNewAccount({email, password, confirmPassword}) { | |
if (validateNewAccount({email, password, confirmPassword})) { | |
// show loading indicator. | |
showLoading(); | |
// get user avatar. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
loginBtn.addEventListener('click', function() { | |
// show loading indicator. | |
showLoading(); | |
// get input user's credentials. | |
const email = emailLoginInputElement ? emailLoginInputElement.value : null; | |
const password = passwordLoginInputElement ? passwordLoginInputElement.value : null; | |
if(isUserCredentialsValid({email, password})) { | |
// if the user's credentials are valid, call Firebase authentication service. | |
auth.signInWithEmailAndPassword(email, password).then((userCredential) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Chat App with Vanilla JS</title> | |
<link rel="stylesheet" href="/css/styles.css"> | |
<script defer src="https://widget-js.cometchat.io/v2/cometchatwidget.js"></script> | |
</head> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener('DOMContentLoaded', function() { | |
// hide loading indicator. | |
hideLoading(); | |
// get authenticated user | |
CometChatWidget.init({ | |
"appID": `${config.CometChatAppId}`, | |
"appRegion": `${config.CometChatRegion}`, | |
"authKey": `${config.CometChatAuthKey}` | |
}).then(response => { | |
CometChatWidget.CometChat.getLoggedinUser().then( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
CometChatWidget.launch({ | |
"widgetID": `${config.CometChatWidgetId}`, | |
"target": "#cometchat", | |
"roundedCorners": "false", | |
"height": "100%", | |
"width": "100%", | |
"defaultID": `${user.uid}`, //default UID (user) or GUID (group) to show, | |
"defaultType": 'user' //user or group | |
}); |