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 / Chat.tsx
Last active October 27, 2021 12:57
Chat.tsx - Load Messages - Ionic Chat App
...
const Chat: React.FC = () => {
const history = useHistory();
const { cometChat, user, selectedConversation, setCallType } = useContext(Context);
const [messages, setMessages] = useState<any>([]);
...
const messageRef = useRef<any>(null);
const messageBottomRef = useRef<any>(null);
@hieptl
hieptl / Message.tsx
Last active October 25, 2021 15:21
Message.tsx - Ionic Chat App
import React, { useContext } from 'react';
import Context from '../context';
import deliveredAtIcon from '../images/deliveredAt.png';
import readAtIcon from '../images/readAt.png';
const Message: React.FC<any> = (props) => {
const { message, messageType, deliveredAt, readAt, senderId, avatar, isRight } = props;
@hieptl
hieptl / Chat.tsx
Last active October 27, 2021 12:58
Chat.tsx - Send Text Message - Ionic Chat App
...
const Chat: React.FC = () => {
...
const { cometChat, user, selectedConversation, setCallType } = useContext(Context);
const [messages, setMessages] = useState<any>([]);
...
const messageRef = useRef<any>(null);
const messageBottomRef = useRef<any>(null);
...
@hieptl
hieptl / Chat.tsx
Last active October 27, 2021 12:58
Chat.tsx - Send Media Message - Ionic Chat App
...
import { Chooser } from '@ionic-native/chooser'
import { ImagePicker } from '@ionic-native/image-picker';
...
import imageIcon from '../images/image.png';
const Chat: React.FC = () => {
const history = useHistory();
const { cometChat, user, selectedConversation, setCallType } = useContext(Context);
@hieptl
hieptl / Chat.tsx
Last active October 28, 2021 10:32
Chat.tsx - Listen for Messages, Typing Indicators, Unread Count Message, and Read Receipts - Ionic Chat App
...
const Chat: React.FC = () => {
const history = useHistory();
const { cometChat, user, selectedConversation, setCallType } = useContext(Context);
const [messages, setMessages] = useState<any>([]);
...
const [isActionSheetShown, setIsActionSheetShown] = useState<any>(false);
@hieptl
hieptl / Chat.tsx
Last active October 27, 2021 05:39
Chat.tsx - Listen for Online/Offline Users - Ionic Chat App
...
const Chat: React.FC = () => {
...
const { cometChat, user, selectedConversation, setCallType } = useContext(Context);
...
useEffect(() => {
...
return () => {
if (selectedConversation) {
...
@hieptl
hieptl / App.tsx
Created October 18, 2021 15:50
App.tsx - Calling Feature - Ionic Chat App
...
const App: React.FC<any> = () => {
const callListenerId = useRef(uuidv4());
const [isLoading, setIsLoading] = useState(false);
const [cometChat, setCometChat] = useState<any>(null);
const [user, setUser] = useState<any>(null);
const [selectedConversation, setSelectedConversation] = useState<any>(null);
const [callType, setCallType] = useState<any>(null);
@hieptl
hieptl / Chat.tsx
Created October 18, 2021 15:55
Chat.tsx - Start Audio/Video Call - Ionic Chat App
...
const startAudioCall = () => {
if (cometChat && selectedConversation) {
setCallType(cometChat.CALL_TYPE.AUDIO);
}
};
const startVideoCall = () => {
if (cometChat && selectedConversation) {
setCallType(cometChat.CALL_TYPE.VIDEO);
@hieptl
hieptl / ManageGroup.tsx
Last active October 27, 2021 10:10
ManageGroup.tsx - Ionic Chat App
import React, { useContext } from 'react';
import { IonToolbar, IonTitle, IonHeader, IonButtons, IonBackButton, IonButton, IonIcon } from '@ionic/react';
import { trash, addCircle, removeCircle, exit } from 'ionicons/icons'
import { useHistory } from 'react-router';
import Context from '../context';
const ManageGroup: React.FC = () => {
@hieptl
hieptl / AddGroupMembers.tsx
Created October 18, 2021 16:02
AddGroupMembers.tsx - Ionic Chat App
import React, { useState, useEffect, useContext } from 'react';
import { IonToolbar, IonTitle, IonHeader, IonButtons, IonBackButton } from '@ionic/react';
import { useHistory } from 'react-router';
import { v4 as uuidv4 } from "uuid";
import Context from '../context';
const AddGroupMembers: React.FC = () => {