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 / SubHeader.js
Created November 13, 2021 16:33
SubHeader.js - Discord Clone
const SubHeader = (props) => {
const { title } = props;
return (
<div className="friends__sub-header">
<span>{title}</span>
</div>
);
};
export default SubHeader;
@hieptl
hieptl / Pending.js
Created November 13, 2021 16:37
Pending.js - Discord Clone
const Pending = (props) => {
const { user, onAccepted, onRejected } = props;
const accept = () => {
onAccepted(user);
};
const reject = () => {
onRejected(user);
};
@hieptl
hieptl / Login.js
Created November 13, 2021 16:41
Login.js - Login CometChat - Discord Clone
...
const loginCometChat = (user) => {
const authKey = `${process.env.REACT_APP_COMETCHAT_AUTH_KEY}`;
cometChat.login(user.id, authKey).then(
User => {
localStorage.setItem('auth', JSON.stringify(user));
setUser(user);
setIsLoading(false);
@hieptl
hieptl / SignUp.js
Created November 14, 2021 02:02
SignUp.js - Create CometChat Account - Discord Clone
const createCometChatAccount = ({ userUuid, fullname, userAvatar }) => {
const authKey = `${process.env.REACT_APP_COMETCHAT_AUTH_KEY}`;
const user = new cometChat.User(userUuid);
user.setName(fullname);
user.setAvatar(userAvatar);
cometChat.createUser(user, authKey).then(
user => {
setIsLoading(false);
}, error => {
@hieptl
hieptl / Sidebars.js
Created November 14, 2021 02:59
Sidebar.js - Listen to Custom Messages - Discord Clone
...
useEffect(() => {
...
if (cometChat && user) {
listenCustomMessages();
}
return () => {
...
if (cometChat) {
cometChat.removeMessageListener(user.id);
@hieptl
hieptl / Pendings.js
Created November 14, 2021 03:33
Pendings.js - Add CometChat Friend and Send Custom Message - Discord Clone
...
const sendCustomMessage = ({ message, type, receiverId }) => {
const receiverID = receiverId;
const customType = type;
const receiverType = cometChat.RECEIVER_TYPE.USER;
const customData = {
message
};
const customMessage = new cometChat.CustomMessage(
receiverID,
@hieptl
hieptl / Server.js
Last active November 22, 2021 12:05
Server.js - Discord Clone
import { useEffect, useContext } from 'react';
import Sidebars from './Sidebars';
import Main from './Main';
import Context from '../../context';
const Server = () => {
const { setSelectedChannel } = useContext(Context);
useEffect(() => {
return () => {
@hieptl
hieptl / Sidebars.js
Last active November 22, 2021 12:06
Sidebars.js - Server - Discord Clone
import { useState, useEffect, useContext } from 'react';
import withModal from '../common/Modal';
import Create from '../channel/Create';
import Channels from '../channel/Channels';
import Context from '../../context';
import { realTimeDb } from '../../firebase';
const Sidebars = (props) => {
const { toggleModal } = props;
@hieptl
hieptl / Sidebars.js
Created November 14, 2021 03:54
Sidebars.js - Listen to Custom Message - Server - Discord Clone
...
useEffect(() => {
if (cometChat) {
listenCustomMessages();
}
return () => {
if (cometChat) {
cometChat.removeMessageListener(user.id);
}
}
@hieptl
hieptl / Channels.js
Last active November 22, 2021 11:56
Channels.js - Discord Clone
import { useState } from "react";
import Channel from './Channel';
const Channels = (props) => {
const { title, channelType, channels, onItemClicked } = props;
const [isExpanded, setIsExpanded] = useState(false);
const toggleExpand = () => {
setIsExpanded(previous => !previous);