🎨(frontend) replace logical OR with nullish coalescing operator

Replace `||` operators and conditional checks with `??` where appropriate
for safer null/undefined handling. Nullish coalescing only triggers for
null/undefined values, preventing unexpected behavior with falsy values
like 0 or empty strings.
This commit is contained in:
lebaudantoine
2025-06-30 18:02:45 +02:00
committed by aleb_the_flash
parent b265c3c7cb
commit b058e6add9
8 changed files with 9 additions and 9 deletions

View File

@@ -14,7 +14,7 @@ export const AppInitialization = () => {
support = {},
silence_livekit_debug_logs = false,
custom_css_url = '',
} = data || {}
} = data ?? {}
useAnalytics(analytics)
useSupport(support)

View File

@@ -51,7 +51,7 @@ export const Avatar = ({
style,
...props
}: AvatarProps) => {
const initial = name?.trim()?.charAt(0) || ''
const initial = name?.trim()?.charAt(0) ?? ''
return (
<div
style={{

View File

@@ -14,7 +14,7 @@ export const ErrorScreen = ({
const { t } = useTranslation()
return (
<Screen layout="centered">
<CenteredContent title={title || t('error.heading')} withBackButton>
<CenteredContent title={title ?? t('error.heading')} withBackButton>
{!!body && (
<Center>
<Text as="p" variant="h3" centered>

View File

@@ -251,7 +251,7 @@ export const Home = () => {
</RightColumn>
</Columns>
<LaterMeetingDialog
roomId={laterRoomId || ''}
roomId={laterRoomId ?? ''}
onOpenChange={() => setLaterRoomId(null)}
/>
</Screen>

View File

@@ -9,7 +9,7 @@ type useRaisedHandProps = {
export function useRaisedHand({ participant }: useRaisedHandProps) {
// fixme - refactor this part to rely on attributes
const { metadata } = useParticipantInfo({ participant })
const parsedMetadata = JSON.parse(metadata || '{}')
const parsedMetadata = JSON.parse(metadata ?? '{}')
const toggleRaisedHand = () => {
if (isLocal(participant)) {
@@ -19,5 +19,5 @@ export function useRaisedHand({ participant }: useRaisedHandProps) {
}
}
return { isHandRaised: parsedMetadata.raised || false, toggleRaisedHand }
return { isHandRaised: parsedMetadata.raised ?? false, toggleRaisedHand }
}

View File

@@ -18,7 +18,7 @@ export const SettingsDialog = (props: SettingsDialogProps) => {
<P>
<Trans
i18nKey="settings:account.currentlyLoggedAs"
values={{ user: user?.full_name || user?.email }}
values={{ user: user?.full_name ?? user?.email }}
components={[<Badge />]}
/>
</P>

View File

@@ -17,7 +17,7 @@ export const AccountTab = ({ id, onOpenChange }: AccountTabProps) => {
const { saveUsername } = usePersistentUserChoices()
const room = useRoomContext()
const { user, isLoggedIn, logout } = useUser()
const [name, setName] = useState(room?.localParticipant.name || '')
const [name, setName] = useState(room?.localParticipant.name ?? '')
const handleOnSubmit = () => {
if (room) room.localParticipant.setName(name)

View File

@@ -9,7 +9,7 @@ export default defineConfig(({ mode }) => {
plugins: [react(), tsconfigPaths()],
server: {
port: parseInt(env.VITE_PORT) || 3000,
host: env.VITE_HOST || 'localhost',
host: env.VITE_HOST ?? 'localhost',
allowedHosts: ['.nip.io'],
},
}