Skip to content

armgit / meet

Public Imported from GitHub
0

Open source video conferencing app powered by LiveKit. Built with Django and React.

♻️(frontend) extract Avatar in dedicated component

lebaudantoinee41656a76020
diff --git a/src/frontend/src/components/Avatar.tsx b/src/frontend/src/components/Avatar.tsx
new file mode 100644
index 00000000..0b42105a
--- /dev/null
+++ b/src/frontend/src/components/Avatar.tsx
@@ -0,0 +1,41 @@
+import { css } from '@/styled-system/css'
+import React from 'react'
+
+export type AvatarProps = React.HTMLAttributes<HTMLSpanElement> & {
+ name: string
+ size?: number
+ bgColor?: string
+ textColor?: string
+}
+
+export const Avatar = ({
+ name,
+ size = 32,
+ bgColor = '#3498db',
+ textColor = 'white',
+}: AvatarProps) => {
+ const initial = name?.trim()?.charAt(0).toUpperCase() || '*' // fixme use a proper fallback
+ return (
+ <div
+ className={css({
+ backgroundColor: bgColor,
+ color: textColor,
+ display: 'flex',
+ borderRadius: '50%',
+ justifyContent: 'center',
+ alignItems: 'center',
+ userSelect: 'none',
+ cursor: 'default',
+ flexGrow: 0,
+ flexShrink: 0,
+ })}
+ style={{
+ width: `${size}px`,
+ height: `${size}px`,
+ fontSize: `${size * 0.4}px`,
+ }}
+ >
+ {initial}
+ </div>
+ )
+}
diff --git a/src/frontend/src/features/rooms/livekit/components/controls/Participants/ParticipantsList.tsx b/src/frontend/src/features/rooms/livekit/components/controls/Participants/ParticipantsList.tsx
index 6a04b768..541a02d5 100644
--- a/src/frontend/src/features/rooms/livekit/components/controls/Participants/ParticipantsList.tsx
+++ b/src/frontend/src/features/rooms/livekit/components/controls/Participants/ParticipantsList.tsx
@@ -1,5 +1,4 @@
import { css } from '@/styled-system/css'
-import * as React from 'react'
import { useParticipants } from '@livekit/components-react'
import { Heading } from 'react-aria-components'
@@ -11,32 +10,7 @@ import { capitalize } from '@/utils/capitalize'
import { participantsStore } from '@/stores/participants'
import { useTranslation } from 'react-i18next'
import { allParticipantRoomEvents } from '@/features/rooms/livekit/constants/events'
-
-export type AvatarProps = React.HTMLAttributes<HTMLSpanElement> & {
- name: string
- size?: number
-}
-
-// TODO - extract inline styling in a centralized styling file, and avoid magic numbers
-export const Avatar = ({ name, size = 32 }: AvatarProps) => (
- <div
- className={css({
- minWidth: `${size}px`,
- minHeight: `${size}px`,
- backgroundColor: '#3498db',
- borderRadius: '50%',
- display: 'flex',
- justifyContent: 'center',
- alignItems: 'center',
- fontSize: '1.25rem',
- userSelect: 'none',
- cursor: 'default',
- color: 'white',
- })}
- >
- {name?.trim()?.charAt(0).toUpperCase()}
- </div>
-)
+import { Avatar } from '@/components/Avatar'
// TODO: Optimize rendering performance, especially for longer participant lists, even though they are generally short.
export const ParticipantsList = () => {