Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

refactor(app): replace nested ternaries in invite and auth views

Hampus2bdf37befbb7
diff --git a/fluxer_app/src/features/auth/components/modals/RecoveryKitModal.tsx b/fluxer_app/src/features/auth/components/modals/RecoveryKitModal.tsx
index 6da8b35c0..9d6c855a0 100644
--- a/fluxer_app/src/features/auth/components/modals/RecoveryKitModal.tsx
+++ b/fluxer_app/src/features/auth/components/modals/RecoveryKitModal.tsx
@@ -348,12 +348,13 @@ const RecoveryKitModal = observer(
ModalCommands.popWithKey(RECOVERY_KIT_MODAL_KEY);
onDone?.();
}, [acknowledged, onDone]);
- const description =
- reason === 'recovered'
- ? i18n._(RECOVERY_KIT_RECOVERED_DESCRIPTOR)
- : reason === 'replaced'
- ? i18n._(RECOVERY_KIT_REPLACED_DESCRIPTOR)
- : i18n._(RECOVERY_KIT_CREATED_DESCRIPTOR);
+ let descriptionDescriptor = RECOVERY_KIT_CREATED_DESCRIPTOR;
+ if (reason === 'recovered') {
+ descriptionDescriptor = RECOVERY_KIT_RECOVERED_DESCRIPTOR;
+ } else if (reason === 'replaced') {
+ descriptionDescriptor = RECOVERY_KIT_REPLACED_DESCRIPTOR;
+ }
+ const description = i18n._(descriptionDescriptor);
const optionsBusy = loadingBackupCodes || buildingPdf;
return (
<Modal.Root size="small" centered onClose={handleDone} data-flx="auth.recovery-kit-modal.modal-root">
diff --git a/fluxer_app/src/features/auth/flow/ThemeHeader.tsx b/fluxer_app/src/features/auth/flow/ThemeHeader.tsx
index 80f081753..216e36bb4 100644
--- a/fluxer_app/src/features/auth/flow/ThemeHeader.tsx
+++ b/fluxer_app/src/features/auth/flow/ThemeHeader.tsx
@@ -17,13 +17,16 @@ const SHARED_THEME_DESCRIPTOR = msg({
});
export function ThemeHeader({prefix, sso = false}: {prefix: string; sso?: boolean}) {
const {i18n} = useLingui();
+ let iconSpotSuffix = 'div';
+ if (sso) {
+ iconSpotSuffix = 'div.sso';
+ } else if (prefix.includes('register')) {
+ iconSpotSuffix = 'div--2';
+ }
return (
<AuthPageHeader
icon={
- <div
- className={sharedStyles.themeIconSpot}
- data-flx={`${prefix}.${sso ? 'div.sso' : prefix.includes('register') ? 'div--2' : 'div'}`}
- >
+ <div className={sharedStyles.themeIconSpot} data-flx={`${prefix}.${iconSpotSuffix}`}>
<PaletteIcon
className={sharedStyles.themeIcon}
weight="fill"
diff --git a/fluxer_app/src/features/invite/components/InviteListItem.tsx b/fluxer_app/src/features/invite/components/InviteListItem.tsx
index 5b5b47c80..be4d2b5a8 100644
--- a/fluxer_app/src/features/invite/components/InviteListItem.tsx
+++ b/fluxer_app/src/features/invite/components/InviteListItem.tsx
@@ -161,7 +161,12 @@ export const InviteListItem: React.FC<{
handleRowClick();
}
};
- const itemClass = isMobile ? styles.mobileItem : showChannel ? styles.itemWithChannel : styles.itemWithoutChannel;
+ let itemClass = styles.itemWithoutChannel;
+ if (isMobile) {
+ itemClass = styles.mobileItem;
+ } else if (showChannel) {
+ itemClass = styles.itemWithChannel;
+ }
const itemContent = (
<>
<div className={styles.inviter} data-flx="invite.invite-list-item.inviter">
diff --git a/fluxer_app/src/features/invite/components/pages/InviteAuthPageState.tsx b/fluxer_app/src/features/invite/components/pages/InviteAuthPageState.tsx
index b3de5076b..a08c24955 100644
--- a/fluxer_app/src/features/invite/components/pages/InviteAuthPageState.tsx
+++ b/fluxer_app/src/features/invite/components/pages/InviteAuthPageState.tsx
@@ -67,11 +67,7 @@ export function useInviteAuthPage(code: string, runtimeSnapshot: RuntimeConfigSn
}
}, [guildInvite?.guild?.splash_card_alignment, setSplashCardAlignment]);
const isGroupDM = inviteData ? isGroupDmInvite(inviteData) : false;
- const guildFeatures = guildInvite?.guild.features
- ? Array.isArray(guildInvite.guild.features)
- ? guildInvite.guild.features
- : [...guildInvite.guild.features]
- : [];
+ const guildFeatures = Array.from(guildInvite?.guild.features ?? []);
const isInvitesDisabled = guildFeatures.includes(GuildFeatures.INVITES_DISABLED);
const isRaidDetected = guildFeatures.includes(GuildFeatures.RAID_DETECTED);
diff --git a/fluxer_app/src/features/invite/state/Invites.ts b/fluxer_app/src/features/invite/state/Invites.ts
index cb22695ab..4ee92d491 100644
--- a/fluxer_app/src/features/invite/state/Invites.ts
+++ b/fluxer_app/src/features/invite/state/Invites.ts
@@ -9,11 +9,10 @@ import {action, computed, makeAutoObservable, runInAction} from 'mobx';
type FetchStatus = 'idle' | 'pending' | 'success' | 'error';
-interface InviteSlot {
- loading: boolean;
- error: Error | null;
- data: Invite | null;
-}
+type InviteSlot =
+ | {loading: true; error: null; data: null}
+ | {loading: false; error: null; data: Invite | null}
+ | {loading: false; error: unknown; data: null};
const SETTIMEOUT_LIMIT_MS = 0x7fff_ffff;
@@ -212,7 +211,7 @@ class Invites {
nextPending.delete(resourceKey);
this.inviteSlots = new Map(this.inviteSlots).set(resourceKey, {
loading: false,
- error: error as Error,
+ error,
data: null,
});
this.pendingRequests = nextPending;
diff --git a/fluxer_app/src/features/invite/utils/InviteUtils.ts b/fluxer_app/src/features/invite/utils/InviteUtils.ts
index a5161934d..ebf1cbfb8 100644
--- a/fluxer_app/src/features/invite/utils/InviteUtils.ts
+++ b/fluxer_app/src/features/invite/utils/InviteUtils.ts
@@ -123,11 +123,9 @@ function isChannelVisibleToEveryone(channel: Channel, guild: Guild): boolean {
return (everyoneOverwrite.deny & Permissions.VIEW_CHANNEL) === 0n;
}
-export interface InviteCapability {
- canInvite: boolean;
- useVanityUrl: boolean;
- vanityUrlCode: string | null;
-}
+export type InviteCapability =
+ | {canInvite: boolean; useVanityUrl: false; vanityUrlCode: null}
+ | {canInvite: true; useVanityUrl: true; vanityUrlCode: string};
export function getInviteCapability(channelId: string | undefined, guildId: string | undefined): InviteCapability {
if (!channelId || !guildId || isSyncExcludedChannelId(channelId)) {