You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			84 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			84 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			TypeScript
		
	
| import React, { useContext, useLayoutEffect } from 'react';
 | |
| import { useSelector } from 'react-redux';
 | |
| import styled from 'styled-components';
 | |
| import { getQuotedMessageToAnimate } from '../../state/selectors/conversations';
 | |
| import { isDarkTheme } from '../../state/selectors/theme';
 | |
| import { ScrollToLoadedMessageContext } from './SessionMessagesListContainer';
 | |
| 
 | |
| const LastSeenBar = styled.div`
 | |
|   height: 2px;
 | |
|   flex-grow: 1;
 | |
|   min-width: 60px;
 | |
|   flex-shrink: 0;
 | |
| `;
 | |
| 
 | |
| const LastSeenText = styled.div`
 | |
|   margin-top: 3px;
 | |
|   font-size: var(--font-size-xs);
 | |
|   font-weight: 500;
 | |
|   line-height: 26px;
 | |
|   letter-spacing: 0.3px;
 | |
|   text-transform: uppercase;
 | |
|   text-align: center;
 | |
|   flex-shrink: 0;
 | |
|   margin-inline: 1rem;
 | |
| `;
 | |
| 
 | |
| const LastSeenBarContainer = styled.div<{ darkMode?: boolean }>`
 | |
|   padding-bottom: 35px;
 | |
|   max-width: 300px;
 | |
|   align-self: center;
 | |
|   padding-top: 28px;
 | |
|   display: flex;
 | |
|   flex-direction: row;
 | |
|   align-items: center;
 | |
| 
 | |
|   ${LastSeenBar} {
 | |
|     background-color: ${props =>
 | |
|       props.darkMode ? 'var(--primary-color)' : 'var(--text-primary-color)'};
 | |
|   }
 | |
| 
 | |
|   ${LastSeenText} {
 | |
|     color: ${props => (props.darkMode ? 'var(--primary-color)' : 'var(--text-primary-color)')};
 | |
|   }
 | |
| `;
 | |
| 
 | |
| export const SessionLastSeenIndicator = (props: {
 | |
|   messageId: string;
 | |
|   didScroll: boolean;
 | |
|   setDidScroll: (scroll: boolean) => void;
 | |
| }) => {
 | |
|   const darkMode = useSelector(isDarkTheme);
 | |
|   // if this unread-indicator is not unique it's going to cause issues
 | |
|   const quotedMessageToAnimate = useSelector(getQuotedMessageToAnimate);
 | |
|   const scrollToLoadedMessage = useContext(ScrollToLoadedMessageContext);
 | |
| 
 | |
|   const { messageId, didScroll, setDidScroll } = props;
 | |
| 
 | |
|   /**
 | |
|    * If this unread-indicator is rendered, we want to scroll here only if:
 | |
|    * 1. the conversation was not opened to a specific message (quoted message)
 | |
|    * 2. we already scrolled to this unread banner once for this convo https://github.com/oxen-io/session-desktop/issues/2308
 | |
|    *
 | |
|    * To achieve 2. we store the didScroll state in the parent and track the last rendered conversation in it.
 | |
|    */
 | |
| 
 | |
|   useLayoutEffect(() => {
 | |
|     if (!quotedMessageToAnimate && !didScroll) {
 | |
|       scrollToLoadedMessage(messageId, 'unread-indicator');
 | |
|       setDidScroll(true);
 | |
|     } else if (quotedMessageToAnimate) {
 | |
|       setDidScroll(true);
 | |
|     }
 | |
|   });
 | |
| 
 | |
|   return (
 | |
|     <LastSeenBarContainer id="unread-indicator" darkMode={darkMode}>
 | |
|       <LastSeenBar />
 | |
|       <LastSeenText>{window.i18n('unreadMessages')}</LastSeenText>
 | |
| 
 | |
|       <LastSeenBar />
 | |
|     </LastSeenBarContainer>
 | |
|   );
 | |
| };
 |