Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: animate twice when sending message #362

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading