Skip to content

Commit

Permalink
FEAT : audio alert added for new msg
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamtala-dev committed May 1, 2024
1 parent 71590cb commit 558cba2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
Binary file added src/assets/audio/incoming.mp3
Binary file not shown.
6 changes: 4 additions & 2 deletions src/components/messages/MessageElement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ dayjs.extend(relativeTime);

const MessageElement = ({ message }) => {
const { userId, profilePicture } = useAuth();
const { conversation } = useConversation();
const { conversation, onlineUsers } = useConversation();
let isOnline =
userId === message.receiverId && onlineUsers.includes(message.senderId);

const formattedTime = dayjs(message.createdAt).fromNow();
const self = userId === message.senderId;
return (
<div
className={`chat ${self ? "chat-end" : "chat-start"} ${message?.shake && "animate-shake"}`}>
<div className="chat-image avatar">
<div className={`chat-image avatar ${isOnline && "online"} z-0`}>
<div className="w-8 rounded-full">
<img
alt="Tailwind CSS chat bubble component"
Expand Down
4 changes: 2 additions & 2 deletions src/components/messages/SendMessageForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ const SendMessageForm = () => {
onBlur={() => setInputFocused(false)}
/>
<button
className="border-none btn rounded-3xl disabled:bg-opacity-95 disabled:cursor-no-drop"
className="border-none btn rounded-3xl bg-green-300 disabled:bg-opacity-95 disabled:cursor-no-drop"
disabled={loading || !formState.isValid}>
{loading ? (
<span className="loading w-4 loading-spinner"></span>
) : (
<BsFillSendFill className="w-4" />
<BsFillSendFill className="w-4 text-black" />
)}
</button>
</form>
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/socket/useNewMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import { useEffect } from "react";
import { socket } from "../../socket/socket";
import { useConversation } from "../../stores/useConversation";
import scrollDown from "../../utils/scrollDown";
import incomingAudio from "../../assets/audio/incoming.mp3";

const useNewMessage = () => {
const { setMessage } = useConversation();
const notificationSound = new Audio(incomingAudio);

useEffect(() => {
const newMessageComes = (newMessage) => {
newMessage = { ...newMessage, shake: true };
setMessage(newMessage);
notificationSound.play();
return scrollDown();
};

Expand Down

0 comments on commit 558cba2

Please sign in to comment.