Skip to content

Commit

Permalink
Add useRouter hook and update ChatFooter component
Browse files Browse the repository at this point in the history
  • Loading branch information
loicBRAVO committed Feb 13, 2024
1 parent 1607a87 commit e9c0635
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions frontend/src/components/Chat/ChatFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'react-toastify/dist/ReactToastify.css';
import { toast, ToastContainer } from 'react-toastify';
import { v4 as uuidv4 } from 'uuid';
import { useRoom } from "@/contexts/RoomContext";
import { useRouter } from "next/navigation";


function ChatFooter({ roomId }: { roomId: string }) {
Expand All @@ -26,6 +27,7 @@ function ChatFooter({ roomId }: { roomId: string }) {
const [image, setImage] = useState<string | null>(null);
const [showToast, setShowToast] = useState<boolean>(false);
const [toastMessage, setToastMessage] = useState<string>("");
const router = useRouter();
const onEmojiPick = (emojiObj: any) => {
setMessage((prevInput) => prevInput + emojiObj.emoji);
inputRef.current.focus();
Expand Down Expand Up @@ -134,6 +136,8 @@ function ChatFooter({ roomId }: { roomId: string }) {
case "quit":
const username = localStorage.getItem("name");
socket?.emit("leave_room", username, roomId);
setMyRooms(myRooms.filter((room) => room.id !== roomId));
router.push("/chat/1");
break;
case "users":
socket?.emit("users");
Expand Down

0 comments on commit e9c0635

Please sign in to comment.