Skip to content

Commit

Permalink
fix: animate twice when sending message (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
hfdem committed Aug 12, 2024
1 parent b9429f4 commit e247345
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 17 additions & 5 deletions client/src/components/Messaging/Message.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, { useCallback, useContext, useEffect, useState } from "react";

import styles from "./styles/Message.module.css";
import Image from "../Image";

import { ThemeContext } from "../../ThemeContext";
import { Timestamp } from "mongodb";

Expand Down Expand Up @@ -51,16 +49,30 @@ export const Message = ({
}, []);

const [darkMode] = useContext(ThemeContext);
let messageClass;

if (owner) {
if (!local) {
messageClass = `${styles.messageRight} ${styles.noanimate}`;
} else {
messageClass = styles.messageRight;
}
} else {
messageClass = styles.messageLeft;
}

return (
<div className={owner === true ? styles.messageRight : styles.messageLeft}>
<div className={messageClass}>
<div className={styles.messageInfo}>
<div className={styles.sentReceived}>You {owner === true ? "sent" : "received"}</div>
<div className={styles.sentReceived}>
You {owner ? "sent" : "received"}
</div>
<div className={`${styles.messageContainer} ${!darkMode && styles.lightModeContainer}`}>
{image && <Image src={image} maxWidth="300px" maxHeight="300px" />}
{body}
{timestamp && (
<span className={styles.timestamp}>
{(owner === true ? "sent at " : "received at ") +
{(owner ? "sent at " : "received at ") +
new Date().toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })}
</span>
)}
Expand Down
4 changes: 4 additions & 0 deletions client/src/components/Messaging/styles/Message.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
animation: fade-in-right 0.4s cubic-bezier(0.39, 0.575, 0.565, 1) both;
}

.noanimate {
animation: none !important; /* disable animation */
}

.messageLeft + .messageLeft .sentReceived {
display: none;
}
Expand Down

0 comments on commit e247345

Please sign in to comment.