Skip to content

Instantly share code, notes, and snippets.

View hieptl's full-sized avatar
🎯
Focusing

Hiep Le hieptl

🎯
Focusing
View GitHub Profile
@hieptl
hieptl / index.js
Last active September 2, 2021 05:19
Index.js - Logout - Javascript Chat App
...
logoutButon.addEventListener('click', function() {
const isLeaved = confirm('Do you want to log out?');
if (isLeaved) {
// logout from cometchat and then clear storage.
CometChatWidget.logout().then(response => {
// User successfully logged out.
// Perform any clean up if required.
// redirect to login page.
window.location.href = '/login.html';
@hieptl
hieptl / App.js
Created September 2, 2021 17:29
App.js - Mention Chat App
...
useEffect(() => {
initCometChat();
}, []);
/**
* init comet chat.
*/
const initCometChat = async () => {
const { CometChat } = await import('@cometchat-pro/chat');
@hieptl
hieptl / firebase.js
Created September 2, 2021 17:31
Firebase.js - Mention Chat App
import firebase from "firebase";
import "firebase/storage";
const firebaseConfig = {
apiKey: `${process.env.REACT_APP_FIREBASE_API_KEY}`,
authDomain: `${process.env.REACT_APP_FIREBASE_AUTH_DOMAIN}`,
databaseURL: `${process.env.REACT_APP_FIREBASE_DATABASE_URL}`,
projectId: `${process.env.REACT_APP_FIREBASE_PROJECT_ID}`,
storageBucket: `${process.env.REACT_APP_FIREBASE_STORAGE_BUCKET}`,
messagingSenderId: `${process.env.REACT_APP_FIREABSE_MESSAGING_SENDER_ID}`,
@hieptl
hieptl / login.js
Last active September 12, 2021 07:26
Login.js - Mention Chat App
// import useRef and useContext
import { useRef, useContext } from "react";
// import Context to get shared data from React context.
import Context from "../Context";
// import firebase authentication and real time database.
import { auth, realTimeDb } from "../firebase";
// import validator to validate user's credentials.
import validator from "validator";
// import custom componnets.
import withModal from "./Modal";
@hieptl
hieptl / signup.js
Last active September 12, 2021 07:27
SignUp.js - Mention Chat App
// import useRef, useContext
import { useRef, useContext } from "react";
// import Context to get shared data.
import Context from "../Context";
// import validator to validate user's information.
import validator from "validator";
// import firebase authentication.
import { auth, realTimeDb } from "../firebase";
// import uuid to generate id for users.
import { v4 as uuidv4 } from "uuid";
@hieptl
hieptl / header.js
Created September 3, 2021 03:43
Header.js - Mention Chat App
// import useContext
import { useContext } from 'react';
// import Context
import Context from '../Context';
// import react router
import { useHistory } from 'react-router-dom';
function Header() {
const { user, setUser } = useContext(Context);
@hieptl
hieptl / chat.js
Created September 3, 2021 03:45
Chat.js - Mention Chat App
// import cometchat components.
import {CometChatUI} from "../cometchat-pro-react-ui-kit/CometChatWorkspace/src";
function Chat() {
return (
<div className="chat-container">
{/* CometChat Components will be go here */}
<CometChatUI />
</div>
);
}
@hieptl
hieptl / tribute.css
Last active September 12, 2021 07:34
Tribute.css - Mention Chat App
.tribute-container {
background: #fff;
border-radius: 0.5rem;
border: 1px solid #E5E7EB;
max-height: 15rem;
overflow: auto;
padding: 0.75rem;
top: 27.625rem !important;
z-index: 10000;
}
@hieptl
hieptl / index.js
Created September 3, 2021 04:46
index.js - CometChatMessageComposer - Mention Chat App
...
import Tribute from "tributejs";
import "./tribute.css";
...
@hieptl
hieptl / index.js
Last active September 12, 2021 07:53
index.js - CometChatMessageComposer - Mention Chat App
...
import Tribute from "tributejs";
import "./tribute.css";
...
class CometChatMessageComposer extends React.PureComponent {
...
groupListenerId = "group_" + new Date().getTime();
...
constructor(props) {
super(props);