🎨(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 = {}, support = {},
silence_livekit_debug_logs = false, silence_livekit_debug_logs = false,
custom_css_url = '', custom_css_url = '',
} = data || {} } = data ?? {}
useAnalytics(analytics) useAnalytics(analytics)
useSupport(support) useSupport(support)

View File

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

View File

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

View File

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

View File

@@ -9,7 +9,7 @@ type useRaisedHandProps = {
export function useRaisedHand({ participant }: useRaisedHandProps) { export function useRaisedHand({ participant }: useRaisedHandProps) {
// fixme - refactor this part to rely on attributes // fixme - refactor this part to rely on attributes
const { metadata } = useParticipantInfo({ participant }) const { metadata } = useParticipantInfo({ participant })
const parsedMetadata = JSON.parse(metadata || '{}') const parsedMetadata = JSON.parse(metadata ?? '{}')
const toggleRaisedHand = () => { const toggleRaisedHand = () => {
if (isLocal(participant)) { 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> <P>
<Trans <Trans
i18nKey="settings:account.currentlyLoggedAs" i18nKey="settings:account.currentlyLoggedAs"
values={{ user: user?.full_name || user?.email }} values={{ user: user?.full_name ?? user?.email }}
components={[<Badge />]} components={[<Badge />]}
/> />
</P> </P>

View File

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

View File

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