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.
		
		
		
		
		
			
		
			
	
	
		
			44 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
		
		
			
		
	
	
			44 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
| 
											5 years ago
										 | import React from 'react'; | ||
| 
											4 years ago
										 | import { useMembersAvatars } from '../../../hooks/useMembersAvatars'; | ||
| 
											5 years ago
										 | import { Avatar, AvatarSize } from '../Avatar'; | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 | type Props = { | ||
| 
											5 years ago
										 |   size: number; | ||
| 
											4 years ago
										 |   closedGroupId: string; | ||
| 
											5 years ago
										 |   onAvatarClick?: () => void; | ||
| 
											4 years ago
										 | }; | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 | function getClosedGroupAvatarsSize(size: AvatarSize): AvatarSize { | ||
|  |   // Always use the size directly under the one requested
 | ||
|  |   switch (size) { | ||
|  |     case AvatarSize.S: | ||
|  |       return AvatarSize.XS; | ||
|  |     case AvatarSize.M: | ||
|  |       return AvatarSize.S; | ||
|  |     case AvatarSize.L: | ||
|  |       return AvatarSize.M; | ||
|  |     case AvatarSize.XL: | ||
|  |       return AvatarSize.L; | ||
|  |     case AvatarSize.HUGE: | ||
|  |       return AvatarSize.XL; | ||
|  |     default: | ||
|  |       throw new Error(`Invalid size request for closed group avatar: ${size}`); | ||
| 
											5 years ago
										 |   } | ||
| 
											4 years ago
										 | } | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 | export const ClosedGroupAvatar = (props: Props) => { | ||
|  |   const { closedGroupId, size, onAvatarClick } = props; | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 |   const memberAvatars = useMembersAvatars(closedGroupId); | ||
|  |   const avatarsDiameter = getClosedGroupAvatarsSize(size); | ||
| 
											4 years ago
										 |   const firstMemberId = memberAvatars?.[0]; | ||
|  |   const secondMemberID = memberAvatars?.[1]; | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 |   return ( | ||
|  |     <div className="module-avatar__icon-closed"> | ||
| 
											4 years ago
										 |       <Avatar size={avatarsDiameter} pubkey={firstMemberId || ''} onAvatarClick={onAvatarClick} /> | ||
|  |       <Avatar size={avatarsDiameter} pubkey={secondMemberID || ''} onAvatarClick={onAvatarClick} /> | ||
| 
											4 years ago
										 |     </div> | ||
|  |   ); | ||
|  | }; |