♻️(frontend) refactor ParticipantName component for internationalization
Component now supports i18n. The participant tile needs further refactoring as it still mixes LiveKit CSS with custom styling.
This commit is contained in:
committed by
aleb_the_flash
parent
e519f00342
commit
bc76c44fe9
@@ -0,0 +1,42 @@
|
|||||||
|
import { Text } from '@/primitives'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { useParticipantInfo } from '@livekit/components-react'
|
||||||
|
import { Participant } from 'livekit-client'
|
||||||
|
|
||||||
|
export const ParticipantName = ({
|
||||||
|
participant,
|
||||||
|
isScreenShare = false,
|
||||||
|
}: {
|
||||||
|
participant: Participant
|
||||||
|
isScreenShare: boolean
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation('rooms', { keyPrefix: 'participantTile' })
|
||||||
|
|
||||||
|
const { identity, name } = useParticipantInfo({ participant })
|
||||||
|
const displayedName = name != '' ? name : identity
|
||||||
|
|
||||||
|
if (isScreenShare) {
|
||||||
|
return (
|
||||||
|
<Text
|
||||||
|
variant="sm"
|
||||||
|
style={{
|
||||||
|
paddingBottom: '0.1rem',
|
||||||
|
marginLeft: '0.4rem',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t('screenShare', { name: displayedName })}
|
||||||
|
</Text>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Text
|
||||||
|
variant="sm"
|
||||||
|
style={{
|
||||||
|
paddingBottom: '0.1rem',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{displayedName}
|
||||||
|
</Text>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@ import {
|
|||||||
AudioTrack,
|
AudioTrack,
|
||||||
ConnectionQualityIndicator,
|
ConnectionQualityIndicator,
|
||||||
LockLockedIcon,
|
LockLockedIcon,
|
||||||
ParticipantName,
|
|
||||||
ParticipantTileProps,
|
ParticipantTileProps,
|
||||||
ScreenShareIcon,
|
ScreenShareIcon,
|
||||||
useEnsureTrackRef,
|
useEnsureTrackRef,
|
||||||
@@ -29,6 +28,7 @@ import { MutedMicIndicator } from './MutedMicIndicator'
|
|||||||
import { ParticipantPlaceholder } from './ParticipantPlaceholder'
|
import { ParticipantPlaceholder } from './ParticipantPlaceholder'
|
||||||
import { ParticipantTileFocus } from './ParticipantTileFocus'
|
import { ParticipantTileFocus } from './ParticipantTileFocus'
|
||||||
import { FullScreenShareWarning } from './FullScreenShareWarning'
|
import { FullScreenShareWarning } from './FullScreenShareWarning'
|
||||||
|
import { ParticipantName } from './ParticipantName'
|
||||||
|
|
||||||
export function TrackRefContextIfNeeded(
|
export function TrackRefContextIfNeeded(
|
||||||
props: React.PropsWithChildren<{
|
props: React.PropsWithChildren<{
|
||||||
@@ -97,6 +97,8 @@ export const ParticipantTile: (
|
|||||||
participant: trackReference.participant,
|
participant: trackReference.participant,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const isScreenShare = trackReference.source != Track.Source.Camera
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={ref} style={{ position: 'relative' }} {...elementProps}>
|
<div ref={ref} style={{ position: 'relative' }} {...elementProps}>
|
||||||
<TrackRefContextIfNeeded trackRef={trackReference}>
|
<TrackRefContextIfNeeded trackRef={trackReference}>
|
||||||
@@ -129,45 +131,50 @@ export const ParticipantTile: (
|
|||||||
{!disableMetadata && (
|
{!disableMetadata && (
|
||||||
<div className="lk-participant-metadata">
|
<div className="lk-participant-metadata">
|
||||||
<HStack gap={0.25}>
|
<HStack gap={0.25}>
|
||||||
<MutedMicIndicator
|
{!isScreenShare && (
|
||||||
participant={trackReference.participant}
|
<MutedMicIndicator
|
||||||
/>
|
participant={trackReference.participant}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<div
|
<div
|
||||||
className="lk-participant-metadata-item"
|
className="lk-participant-metadata-item"
|
||||||
style={{
|
style={{
|
||||||
minHeight: '24px',
|
padding: '0.1rem 0.25rem',
|
||||||
backgroundColor: isHandRaised ? 'white' : undefined,
|
backgroundColor:
|
||||||
color: isHandRaised ? 'black' : undefined,
|
isHandRaised && !isScreenShare ? 'white' : undefined,
|
||||||
|
color:
|
||||||
|
isHandRaised && !isScreenShare ? 'black' : undefined,
|
||||||
transition: 'background 200ms ease, color 400ms ease',
|
transition: 'background 200ms ease, color 400ms ease',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{trackReference.source === Track.Source.Camera ? (
|
{isHandRaised && !isScreenShare && (
|
||||||
<>
|
<RiHand
|
||||||
{isHandRaised && (
|
color="black"
|
||||||
<RiHand
|
size={16}
|
||||||
color="black"
|
style={{
|
||||||
size={16}
|
marginRight: '0.4rem',
|
||||||
style={{
|
minWidth: '16px',
|
||||||
marginInlineEnd: '.25rem', // fixme - match TrackMutedIndicator styling
|
animationDuration: '300ms',
|
||||||
animationDuration: '300ms',
|
animationName: 'wave_hand',
|
||||||
animationName: 'wave_hand',
|
animationIterationCount: '2',
|
||||||
animationIterationCount: '2',
|
}}
|
||||||
}}
|
/>
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{isEncrypted && (
|
|
||||||
<LockLockedIcon
|
|
||||||
style={{ marginRight: '0.25rem' }}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<ParticipantName />
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<ScreenShareIcon style={{ marginRight: '0.25rem' }} />
|
|
||||||
<ParticipantName>'s screen</ParticipantName>
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
|
{isScreenShare && (
|
||||||
|
<ScreenShareIcon
|
||||||
|
style={{
|
||||||
|
maxWidth: '20px',
|
||||||
|
width: '100%',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{isEncrypted && !isScreenShare && (
|
||||||
|
<LockLockedIcon style={{ marginRight: '0.25rem' }} />
|
||||||
|
)}
|
||||||
|
<ParticipantName
|
||||||
|
isScreenShare={isScreenShare}
|
||||||
|
participant={trackReference.participant}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</HStack>
|
</HStack>
|
||||||
<ConnectionQualityIndicator className="lk-participant-metadata-item" />
|
<ConnectionQualityIndicator className="lk-participant-metadata-item" />
|
||||||
|
|||||||
@@ -363,5 +363,8 @@
|
|||||||
"message": "",
|
"message": "",
|
||||||
"stop": "",
|
"stop": "",
|
||||||
"ignore": ""
|
"ignore": ""
|
||||||
|
},
|
||||||
|
"participantTile": {
|
||||||
|
"screenShare": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -364,5 +364,8 @@
|
|||||||
"message": "To avoid infinite loop display, do not share your entire screen. Instead, share a tab or another window.",
|
"message": "To avoid infinite loop display, do not share your entire screen. Instead, share a tab or another window.",
|
||||||
"stop": "Stop presenting",
|
"stop": "Stop presenting",
|
||||||
"ignore": "Ignore"
|
"ignore": "Ignore"
|
||||||
|
},
|
||||||
|
"participantTile": {
|
||||||
|
"screenShare": "{{name}}'s screen"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -364,5 +364,8 @@
|
|||||||
"message": "Pour éviter l'affichage en boucle infinie, ne partagez pas l'intégralité de votre écran. Partagez plutôt un onglet ou une autre fenêtre.",
|
"message": "Pour éviter l'affichage en boucle infinie, ne partagez pas l'intégralité de votre écran. Partagez plutôt un onglet ou une autre fenêtre.",
|
||||||
"stop": "Arrêter la présentation",
|
"stop": "Arrêter la présentation",
|
||||||
"ignore": "Ignorer"
|
"ignore": "Ignorer"
|
||||||
|
},
|
||||||
|
"participantTile": {
|
||||||
|
"screenShare": "Écran de {{name}}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -364,5 +364,8 @@
|
|||||||
"message": "Om niet oneindige uw scherm in zichzelf te delen, kunt u beter niet het hele scherm delen. Deel in plaats daarvan een tab of een ander venster.",
|
"message": "Om niet oneindige uw scherm in zichzelf te delen, kunt u beter niet het hele scherm delen. Deel in plaats daarvan een tab of een ander venster.",
|
||||||
"stop": "Stop met presenteren",
|
"stop": "Stop met presenteren",
|
||||||
"ignore": "Negeren"
|
"ignore": "Negeren"
|
||||||
|
},
|
||||||
|
"participantTile": {
|
||||||
|
"screenShare": "{{name}} scherm"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user