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 / home.js
Created December 3, 2021 04:38
home.js - client - Zoom Clone
import { useEffect, useState, useContext } from 'react';
import axios from 'axios';
import { useHistory } from 'react-router';
import Header from '../common/Header';
import Create from './Create';
import Join from './Join';
import Context from '../../context';
const Home = () => {
const [meetings, setMeetings] = useState([]);
@hieptl
hieptl / create.js
Created December 3, 2021 04:36
create.js - client - Zoom Clone
import { useRef, useContext } from 'react';
import { v4 as uuidv4 } from "uuid";
import axios from 'axios';
import Context from '../../context';
const Create = (props) => {
const { toggleCreate } = props;
const { user, cometChat, setIsLoading, setHasNewMeeting } = useContext(Context);
@hieptl
hieptl / header.js
Created December 3, 2021 04:32
header.js - client - Zoom Clone
import { useContext } from 'react';
import Context from '../../context';
import { useHistory } from 'react-router-dom';
function Header(props) {
const { toggleCreate, toggleJoin } = props;
const { user, setUser, cometChat } = useContext(Context);
const history = useHistory();
@hieptl
hieptl / signup.js
Created December 3, 2021 04:29
signup.js - client - create cometchat account - Zoom Clone
const createCometChatAccount = async ({ id, fullname, avatar }) => {
const authKey = `${process.env.REACT_APP_COMETCHAT_AUTH_KEY}`;
const user = new cometChat.User(id);
user.setName(fullname);
user.setAvatar(avatar);
return await cometChat.createUser(user, authKey);
};
@hieptl
hieptl / signup.js
Created December 3, 2021 04:28
signup.js - client - Zoom Clone
import { useRef, useContext } from "react";
import validator from "validator";
import { v4 as uuidv4 } from "uuid";
import axios from 'axios';
import Context from "../../context";
function SignUp(props) {
const { toggleModal } = props;
const { cometChat, setIsLoading } = useContext(Context);
@hieptl
hieptl / modal.js
Created December 3, 2021 04:27
modal.js - client - Zoom Clone
import { useState } from 'react';
const withModal = ModalComponent => WrapperComponent => {
return function (props) {
const [isModalShown, setIsModalShown] = useState(false);
return (
<>
<WrapperComponent toggleModal={setIsModalShown} {...props} />
@hieptl
hieptl / login.js
Created December 3, 2021 04:26
login.js - client - login cometchat - Zoom Clone
const loginCometChat = async (user) => {
const authKey = `${process.env.REACT_APP_COMETCHAT_AUTH_KEY}`;
return await cometChat.login(user.id, authKey);
};
@hieptl
hieptl / login.js
Created December 3, 2021 04:25
login.js - client - Zoom Clone
import { useEffect, useRef, useContext } from "react";
import validator from "validator";
import { useHistory } from 'react-router-dom';
import axios from 'axios';
import withModal from "../common/Modal";
import SignUp from "../register/SignUp";
import Context from "../../context";
const Login = (props) => {
const { toggleModal } = props;
@hieptl
hieptl / app.js
Created December 3, 2021 04:15
app.js - client - init CometChat - Zoom Clone
...
useEffect(() => {
initCometChat();
}, []);
const initCometChat = async () => {
const { CometChat } = await import('@cometchat-pro/chat');
const appID = `${process.env.REACT_APP_COMETCHAT_APP_ID}`;
const region = `${process.env.REACT_APP_COMETCHAT_REGION}`;
const appSetting = new CometChat.AppSettingsBuilder().subscribePresenceForAllUsers().setRegion(region).build();
@hieptl
hieptl / meetings.js
Created December 3, 2021 04:13
meetings.js - server - get meeting by id - Zoom Clone
app.get("/meetings/:id/get", (req, res) => {
const id = req.params.id;
const findMeetingSql = "SELECT * FROM meeting WHERE meeting_uid = ?";
dbConn.query(findMeetingSql, [id], function (error, meeting) {
res.status(200).jsonp(meeting);
});
});