removed timers from component in favor of css transition (#2769)

* removed timers from component in favor of css transition

* removed semibold text

---------

Co-authored-by: Gabe Kangas <gabek@real-ity.com>
This commit is contained in:
Naz 2023-03-04 00:25:22 +01:00 committed by GitHub
parent cd2cd55549
commit 3629f318e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 15 deletions

View file

@ -4,13 +4,17 @@
width: 100%; width: 100%;
justify-content: center; justify-content: center;
position: absolute; position: absolute;
bottom: 50px; bottom: 75px;
color: var(--theme-color-components-text-on-light); color: var(--theme-color-components-text-on-light);
button { button {
background-color: var(--theme-color-background-light); background-color: var(--theme-color-background-light);
z-index: 9999; z-index: 9999;
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.1), 0 1px 5px 0 rgba(0, 0, 0, 0.12); box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.1), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
display: flex;
align-items: center;
opacity: 0;
animation: show 250ms forwards ease-in-out 500ms;
} }
} }
@ -38,3 +42,13 @@
.chatTextField { .chatTextField {
border-top: 1px solid lightgray; border-top: 1px solid lightgray;
} }
@keyframes show {
from {
opacity: 0;
transform: translateY(5px);
} to {
opacity: 1;
transform: translateY(0px);
}
}

View file

@ -99,22 +99,14 @@ export const ChatContainer: FC<ChatContainerProps> = ({
const [isAtBottom, setIsAtBottom] = useState(false); const [isAtBottom, setIsAtBottom] = useState(false);
const chatContainerRef = useRef(null); const chatContainerRef = useRef(null);
const showScrollToBottomButtonDelay = useRef(null);
const scrollToBottomDelay = useRef(null); const scrollToBottomDelay = useRef(null);
const collapsedMessageIds = new Set<string>(); const collapsedMessageIds = new Set<string>();
const setShowScrolltoBottomButtonWithDelay = (show: boolean) => {
showScrollToBottomButtonDelay.current = setTimeout(() => {
setShowScrollToBottomButton(show);
}, 1500);
};
useEffect( useEffect(
() => () =>
// Clear the timer when the component unmounts // Clear the timer when the component unmounts
() => { () => {
clearTimeout(showScrollToBottomButtonDelay.current);
clearTimeout(scrollToBottomDelay.current); clearTimeout(scrollToBottomDelay.current);
}, },
[], [],
@ -213,7 +205,6 @@ export const ChatContainer: FC<ChatContainerProps> = ({
const scrollChatToBottom = (ref, behavior = 'smooth') => { const scrollChatToBottom = (ref, behavior = 'smooth') => {
clearTimeout(scrollToBottomDelay.current); clearTimeout(scrollToBottomDelay.current);
clearTimeout(showScrollToBottomButtonDelay.current);
scrollToBottomDelay.current = setTimeout(() => { scrollToBottomDelay.current = setTimeout(() => {
ref.current?.scrollToIndex({ ref.current?.scrollToIndex({
index: messages.length - 1, index: messages.length - 1,
@ -230,7 +221,6 @@ export const ChatContainer: FC<ChatContainerProps> = ({
useEffect(() => { useEffect(() => {
setTimeout(() => { setTimeout(() => {
scrollChatToBottom(chatContainerRef, 'auto'); scrollChatToBottom(chatContainerRef, 'auto');
setShowScrolltoBottomButtonWithDelay(false);
}, 500); }, 500);
}, []); }, []);
@ -246,14 +236,11 @@ export const ChatContainer: FC<ChatContainerProps> = ({
itemContent={(index, message) => getViewForMessage(index, message)} itemContent={(index, message) => getViewForMessage(index, message)}
initialTopMostItemIndex={messages.length - 1} initialTopMostItemIndex={messages.length - 1}
followOutput={() => { followOutput={() => {
clearTimeout(showScrollToBottomButtonDelay.current);
if (isAtBottom) { if (isAtBottom) {
setShowScrollToBottomButton(false); setShowScrollToBottomButton(false);
scrollChatToBottom(chatContainerRef, 'auto'); scrollChatToBottom(chatContainerRef, 'auto');
return 'smooth'; return 'smooth';
} }
setShowScrolltoBottomButtonWithDelay(true);
return false; return false;
}} }}
@ -265,7 +252,7 @@ export const ChatContainer: FC<ChatContainerProps> = ({
if (bottom) { if (bottom) {
setShowScrollToBottomButton(false); setShowScrollToBottomButton(false);
} else { } else {
setShowScrolltoBottomButtonWithDelay(true); setShowScrollToBottomButton(true);
} }
}} }}
/> />