Skip to content

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

TypeScript fluxerfluxerapp

refactor(app): flatten ternaries in channel modals and banners

Hampus4e62992320e7
diff --git a/fluxer_app/src/features/channel/components/NewMessagesBar.tsx b/fluxer_app/src/features/channel/components/NewMessagesBar.tsx
index dc8b1acad..d3ef1f681 100644
--- a/fluxer_app/src/features/channel/components/NewMessagesBar.tsx
+++ b/fluxer_app/src/features/channel/components/NewMessagesBar.tsx
@@ -9,6 +9,7 @@ import {msg} from '@lingui/core/macro';
import {Plural, Trans, useLingui} from '@lingui/react/macro';
import {CheckIcon} from '@phosphor-icons/react';
import {observer} from 'mobx-react-lite';
+import type React from 'react';
const JUMP_TO_FIRST_UNREAD_MESSAGE_DESCRIPTOR = msg({
message: 'Jump to first unread message',
@@ -52,6 +53,26 @@ export const NewMessagesBar = observer(
const sameDay = isSameDayBase(oldestUnreadMessageTimestamp);
const compactTime = DateUtils.getFormattedCompactDateTime(oldestUnreadMessageTimestamp);
const shortTime = sameDay ? DateUtils.getFormattedTime(oldestUnreadMessageTimestamp) : compactTime;
+ let jumpLabel: React.ReactNode;
+ if (isEstimated && isMobile) {
+ jumpLabel = i18n._(NEW_SINCE_DESCRIPTOR, {unreadCount, shortTime});
+ } else if (isEstimated) {
+ jumpLabel = i18n._(NEW_MESSAGES_SINCE_DESCRIPTOR, {unreadCount, compactTime});
+ } else if (isMobile) {
+ jumpLabel = i18n._(NEW_SINCE_2_DESCRIPTOR, {unreadCount, shortTime});
+ } else {
+ jumpLabel = (
+ <Trans>
+ <Plural
+ value={unreadCount}
+ one="# new message"
+ other="# new messages"
+ data-flx="channel.new-messages-bar.plural"
+ />{' '}
+ since {compactTime}
+ </Trans>
+ );
+ }
return (
<div className={styles.newMessagesBarBanner} data-flx="channel.new-messages-bar.new-messages-bar">
<button
@@ -61,25 +82,7 @@ export const NewMessagesBar = observer(
aria-label={i18n._(JUMP_TO_FIRST_UNREAD_MESSAGE_DESCRIPTOR)}
data-flx="channel.new-messages-bar.new-messages-bar-text.jump-to-oldest-unread.button"
>
- {isEstimated ? (
- isMobile ? (
- i18n._(NEW_SINCE_DESCRIPTOR, {unreadCount, shortTime})
- ) : (
- i18n._(NEW_MESSAGES_SINCE_DESCRIPTOR, {unreadCount, compactTime})
- )
- ) : isMobile ? (
- i18n._(NEW_SINCE_2_DESCRIPTOR, {unreadCount, shortTime})
- ) : (
- <Trans>
- <Plural
- value={unreadCount}
- one="# new message"
- other="# new messages"
- data-flx="channel.new-messages-bar.plural"
- />{' '}
- since {compactTime}
- </Trans>
- )}
+ {jumpLabel}
</button>
<button
type="button"
diff --git a/fluxer_app/src/features/channel/components/RecipientRemoveMessage.tsx b/fluxer_app/src/features/channel/components/RecipientRemoveMessage.tsx
index 21bb38c04..dcbaa5a76 100644
--- a/fluxer_app/src/features/channel/components/RecipientRemoveMessage.tsx
+++ b/fluxer_app/src/features/channel/components/RecipientRemoveMessage.tsx
@@ -9,6 +9,7 @@ import Users from '@app/features/user/state/Users';
import {Trans} from '@lingui/react/macro';
import {UserMinusIcon} from '@phosphor-icons/react';
import {observer} from 'mobx-react-lite';
+import type React from 'react';
interface RecipientRemoveMessageProps {
message: Message;
@@ -22,48 +23,55 @@ export const RecipientRemoveMessage = observer(({message}: RecipientRemoveMessag
return null;
}
const isSelfRemove = removedUserId === author.id;
- const messageContent = isSelfRemove ? (
- <Trans>
- <SystemMessageUsername
- key={author.id}
- author={author}
- guild={guild}
- message={message}
- data-flx="channel.recipient-remove-message.system-message-username"
- />{' '}
- has left the group.
- </Trans>
- ) : removedUser ? (
- <Trans>
- <SystemMessageUsername
- key={author.id}
- author={author}
- guild={guild}
- message={message}
- data-flx="channel.recipient-remove-message.system-message-username--2"
- />{' '}
- removed{' '}
- <SystemMessageUsername
- key={removedUser.id}
- author={removedUser}
- guild={guild}
- message={message}
- data-flx="channel.recipient-remove-message.system-message-username--3"
- />{' '}
- from the group.
- </Trans>
- ) : (
- <Trans>
- <SystemMessageUsername
- key={author.id}
- author={author}
- guild={guild}
- message={message}
- data-flx="channel.recipient-remove-message.system-message-username--4"
- />{' '}
- removed someone from the group.
- </Trans>
- );
+ let messageContent: React.ReactNode;
+ if (isSelfRemove) {
+ messageContent = (
+ <Trans>
+ <SystemMessageUsername
+ key={author.id}
+ author={author}
+ guild={guild}
+ message={message}
+ data-flx="channel.recipient-remove-message.system-message-username"
+ />{' '}
+ has left the group.
+ </Trans>
+ );
+ } else if (removedUser) {
+ messageContent = (
+ <Trans>
+ <SystemMessageUsername
+ key={author.id}
+ author={author}
+ guild={guild}
+ message={message}
+ data-flx="channel.recipient-remove-message.system-message-username--2"
+ />{' '}
+ removed{' '}
+ <SystemMessageUsername
+ key={removedUser.id}
+ author={removedUser}
+ guild={guild}
+ message={message}
+ data-flx="channel.recipient-remove-message.system-message-username--3"
+ />{' '}
+ from the group.
+ </Trans>
+ );
+ } else {
+ messageContent = (
+ <Trans>
+ <SystemMessageUsername
+ key={author.id}
+ author={author}
+ guild={guild}
+ message={message}
+ data-flx="channel.recipient-remove-message.system-message-username--4"
+ />{' '}
+ removed someone from the group.
+ </Trans>
+ );
+ }
return (
<SystemMessage
icon={UserMinusIcon}
diff --git a/fluxer_app/src/features/channel/components/modals/EditGroupModal.tsx b/fluxer_app/src/features/channel/components/modals/EditGroupModal.tsx
index 4eda63cf8..24317e7b9 100644
--- a/fluxer_app/src/features/channel/components/modals/EditGroupModal.tsx
+++ b/fluxer_app/src/features/channel/components/modals/EditGroupModal.tsx
@@ -14,6 +14,7 @@ import {msg} from '@lingui/core/macro';
import {Trans, useLingui} from '@lingui/react/macro';
import {PlusIcon} from '@phosphor-icons/react';
import {observer} from 'mobx-react-lite';
+import type React from 'react';
import {Controller} from 'react-hook-form';
const ICON_FILE_IS_TOO_LARGE_PLEASE_CHOOSE_A_DESCRIPTOR = msg({
@@ -95,6 +96,38 @@ export const EditGroupModal = observer(({channelId}: {channelId: string}) => {
return null;
}
const placeholderName = channel ? ChannelUtils.getDMDisplayName(channel) : '';
+ let iconPreview: React.ReactNode;
+ if (previewIconUrl) {
+ iconPreview = (
+ <div
+ className={styles.iconPreview}
+ style={{
+ backgroundImage: `url(${previewIconUrl})`,
+ }}
+ data-flx="channel.edit-group-modal.icon-preview"
+ />
+ );
+ } else if (iconPresentable) {
+ iconPreview = (
+ <div
+ className={styles.iconPreview}
+ style={{
+ backgroundImage: `url(${iconPresentable})`,
+ }}
+ data-flx="channel.edit-group-modal.icon-preview--2"
+ />
+ );
+ } else {
+ iconPreview = (
+ <div className={styles.iconPlaceholder} data-flx="channel.edit-group-modal.icon-placeholder">
+ <PlusIcon
+ weight="regular"
+ className={styles.iconPlaceholderIcon}
+ data-flx="channel.edit-group-modal.icon-placeholder-icon"
+ />
+ </div>
+ );
+ }
return (
<Modal.Root size="small" centered data-flx="channel.edit-group-modal.modal-root">
<Form form={form} onSubmit={handleSubmit} data-flx="channel.edit-group-modal.form.submit">
@@ -106,31 +139,7 @@ export const EditGroupModal = observer(({channelId}: {channelId: string}) => {
<Trans>Group icon</Trans>
</div>
<div className={styles.iconContainer} data-flx="channel.edit-group-modal.icon-container">
- {previewIconUrl ? (
- <div
- className={styles.iconPreview}
- style={{
- backgroundImage: `url(${previewIconUrl})`,
- }}
- data-flx="channel.edit-group-modal.icon-preview"
- />
- ) : iconPresentable ? (
- <div
- className={styles.iconPreview}
- style={{
- backgroundImage: `url(${iconPresentable})`,
- }}
- data-flx="channel.edit-group-modal.icon-preview--2"
- />
- ) : (
- <div className={styles.iconPlaceholder} data-flx="channel.edit-group-modal.icon-placeholder">
- <PlusIcon
- weight="regular"
- className={styles.iconPlaceholderIcon}
- data-flx="channel.edit-group-modal.icon-placeholder-icon"
- />
- </div>
- )}
+ {iconPreview}
<div className={styles.iconActions} data-flx="channel.edit-group-modal.icon-actions">
<div className={styles.iconButtonGroup} data-flx="channel.edit-group-modal.icon-button-group">
<Button
diff --git a/fluxer_app/src/features/channel/components/pickers/gif/ImportFavoriteGifsModal.tsx b/fluxer_app/src/features/channel/components/pickers/gif/ImportFavoriteGifsModal.tsx
index 5af9bc0f1..938426044 100644
--- a/fluxer_app/src/features/channel/components/pickers/gif/ImportFavoriteGifsModal.tsx
+++ b/fluxer_app/src/features/channel/components/pickers/gif/ImportFavoriteGifsModal.tsx
@@ -14,7 +14,7 @@ import {MAX_FAVORITE_GIFS} from '@fluxer/constants/src/LimitConstants';
import {msg} from '@lingui/core/macro';
import {useLingui} from '@lingui/react/macro';
import {observer} from 'mobx-react-lite';
-import {useCallback, useState} from 'react';
+import {type ReactNode, useCallback, useState} from 'react';
const IMPORT_FAVORITE_GIFS_DESCRIPTOR = msg({
message: 'Import favorite GIFs',
@@ -77,6 +77,128 @@ export const ImportFavoriteGifsModal = observer(function ImportFavoriteGifsModal
setText('');
}, []);
const isAtLimit = FavoriteGif.totalCount >= MAX_FAVORITE_GIFS;
+ let body: ReactNode;
+ let footerActions: ReactNode;
+ if (FavoriteGifImport.isDone) {
+ body = (
+ <div className={styles.body} data-flx="channel.pickers.gif.import-favorite-gifs-modal.body">
+ <p className={styles.description} data-flx="channel.pickers.gif.import-favorite-gifs-modal.description">
+ {FavoriteGifImport.skippedCount > 0
+ ? i18n._(IMPORT_COMPLETE_WITH_SKIPPED_DESCRIPTOR, {
+ importedCount: FavoriteGifImport.importedCount,
+ skippedCount: FavoriteGifImport.skippedCount,
+ })
+ : i18n._(IMPORT_COMPLETE_DESCRIPTOR, {
+ importedCount: FavoriteGifImport.importedCount,
+ })}
+ </p>
+ </div>
+ );
+ footerActions = (
+ <>
+ <Button
+ onClick={handleReset}
+ variant="secondary"
+ data-flx="channel.pickers.gif.import-favorite-gifs-modal.button.reset"
+ >
+ {i18n._(IMPORT_MORE_DESCRIPTOR)}
+ </Button>
+ <Button
+ onClick={handleClose}
+ variant="primary"
+ data-flx="channel.pickers.gif.import-favorite-gifs-modal.button.close"
+ >
+ {i18n._(DONE_DESCRIPTOR)}
+ </Button>
+ </>
+ );
+ } else if (FavoriteGifImport.isRunning) {
+ body = (
+ <div className={styles.body} data-flx="channel.pickers.gif.import-favorite-gifs-modal.body--2">
+ <p className={styles.description} data-flx="channel.pickers.gif.import-favorite-gifs-modal.description--2">
+ {i18n._(IMPORT_PROGRESS_DESCRIPTOR, {
+ processedCount: FavoriteGifImport.processedCount,
+ totalCount: FavoriteGifImport.totalToImport,
+ importedCount: FavoriteGifImport.importedCount,
+ })}
+ </p>
+ <div className={styles.progressTrack} data-flx="channel.pickers.gif.import-favorite-gifs-modal.progress-track">
+ <div
+ className={styles.progressBar}
+ style={{width: `${Math.round(FavoriteGifImport.progress * 100)}%`}}
+ data-flx="channel.pickers.gif.import-favorite-gifs-modal.progress-bar"
+ />
+ </div>
+ <p className={styles.muted} data-flx="channel.pickers.gif.import-favorite-gifs-modal.muted">
+ {i18n._(IMPORT_BACKGROUND_CONTINUES_DESCRIPTOR)}
+ </p>
+ </div>
+ );
+ footerActions = (
+ <>
+ <Button
+ onClick={handleClose}
+ variant="secondary"
+ data-flx="channel.pickers.gif.import-favorite-gifs-modal.button.close--2"
+ >
+ {i18n._(CLOSE_DESCRIPTOR)}
+ </Button>
+ <Button
+ onClick={handleCancel}
+ variant="danger"
+ data-flx="channel.pickers.gif.import-favorite-gifs-modal.button.cancel"
+ >
+ {i18n._(CANCEL_IMPORT_DESCRIPTOR)}
+ </Button>
+ </>
+ );
+ } else {
+ body = (
+ <div className={styles.body} data-flx="channel.pickers.gif.import-favorite-gifs-modal.body--3">
+ <p className={styles.description} data-flx="channel.pickers.gif.import-favorite-gifs-modal.description--3">
+ {i18n._(PASTE_GIF_URLS_DESCRIPTOR)}
+ </p>
+ {isAtLimit ? (
+ <p className={styles.danger} data-flx="channel.pickers.gif.import-favorite-gifs-modal.danger">
+ {i18n._(FAVORITE_GIF_LIMIT_REACHED_DESCRIPTOR)}
+ </p>
+ ) : (
+ <Textarea
+ label={i18n._(GIF_URLS_DESCRIPTOR)}
+ value={text}
+ onChange={(e) => setText(e.target.value)}
+ placeholder={EXAMPLE_GIF_URLS}
+ minRows={8}
+ maxRows={14}
+ spellCheck={false}
+ autoCapitalize="off"
+ autoCorrect="off"
+ autoComplete="off"
+ data-flx="channel.pickers.gif.import-favorite-gifs-modal.textarea.set-text"
+ />
+ )}
+ </div>
+ );
+ footerActions = (
+ <>
+ <Button
+ onClick={handleClose}
+ variant="secondary"
+ data-flx="channel.pickers.gif.import-favorite-gifs-modal.button.close--3"
+ >
+ {i18n._(CANCEL_DESCRIPTOR)}
+ </Button>
+ <Button
+ onClick={handleImport}
+ variant="primary"
+ disabled={!text.trim() || isAtLimit}
+ data-flx="channel.pickers.gif.import-favorite-gifs-modal.button.import"
+ >
+ {i18n._(IMPORT_DESCRIPTOR)}
+ </Button>
+ </>
+ );
+ }
return (
<Modal.Root size="small" data-flx="channel.pickers.gif.import-favorite-gifs-modal.modal-root">
<Modal.Header
@@ -84,124 +206,9 @@ export const ImportFavoriteGifsModal = observer(function ImportFavoriteGifsModal
onClose={handleClose}
data-flx="channel.pickers.gif.import-favorite-gifs-modal.modal-header"
/>
- <Modal.Content data-flx="channel.pickers.gif.import-favorite-gifs-modal.modal-content">
- {FavoriteGifImport.isDone ? (
- <div className={styles.body} data-flx="channel.pickers.gif.import-favorite-gifs-modal.body">
- <p className={styles.description} data-flx="channel.pickers.gif.import-favorite-gifs-modal.description">
- {FavoriteGifImport.skippedCount > 0
- ? i18n._(IMPORT_COMPLETE_WITH_SKIPPED_DESCRIPTOR, {
- importedCount: FavoriteGifImport.importedCount,
- skippedCount: FavoriteGifImport.skippedCount,
- })
- : i18n._(IMPORT_COMPLETE_DESCRIPTOR, {
- importedCount: FavoriteGifImport.importedCount,
- })}
- </p>
- </div>
- ) : FavoriteGifImport.isRunning ? (
- <div className={styles.body} data-flx="channel.pickers.gif.import-favorite-gifs-modal.body--2">
- <p className={styles.description} data-flx="channel.pickers.gif.import-favorite-gifs-modal.description--2">
- {i18n._(IMPORT_PROGRESS_DESCRIPTOR, {
- processedCount: FavoriteGifImport.processedCount,
- totalCount: FavoriteGifImport.totalToImport,
- importedCount: FavoriteGifImport.importedCount,
- })}
- </p>
- <div
- className={styles.progressTrack}
- data-flx="channel.pickers.gif.import-favorite-gifs-modal.progress-track"
- >
- <div
- className={styles.progressBar}
- style={{width: `${Math.round(FavoriteGifImport.progress * 100)}%`}}
- data-flx="channel.pickers.gif.import-favorite-gifs-modal.progress-bar"
- />
- </div>
- <p className={styles.muted} data-flx="channel.pickers.gif.import-favorite-gifs-modal.muted">
- {i18n._(IMPORT_BACKGROUND_CONTINUES_DESCRIPTOR)}
- </p>
- </div>
- ) : (
- <div className={styles.body} data-flx="channel.pickers.gif.import-favorite-gifs-modal.body--3">
- <p className={styles.description} data-flx="channel.pickers.gif.import-favorite-gifs-modal.description--3">
- {i18n._(PASTE_GIF_URLS_DESCRIPTOR)}
- </p>
- {isAtLimit ? (
- <p className={styles.danger} data-flx="channel.pickers.gif.import-favorite-gifs-modal.danger">
- {i18n._(FAVORITE_GIF_LIMIT_REACHED_DESCRIPTOR)}
- </p>
- ) : (
- <Textarea
- label={i18n._(GIF_URLS_DESCRIPTOR)}
- value={text}
- onChange={(e) => setText(e.target.value)}
- placeholder={EXAMPLE_GIF_URLS}
- minRows={8}
- maxRows={14}
- spellCheck={false}
- autoCapitalize="off"
- autoCorrect="off"
- autoComplete="off"
- data-flx="channel.pickers.gif.import-favorite-gifs-modal.textarea.set-text"
- />
- )}
- </div>
- )}
- </Modal.Content>
+ <Modal.Content data-flx="channel.pickers.gif.import-favorite-gifs-modal.modal-content">{body}</Modal.Content>
<Modal.Footer data-flx="channel.pickers.gif.import-favorite-gifs-modal.modal-footer">
- {FavoriteGifImport.isDone ? (
- <>
- <Button
- onClick={handleReset}
- variant="secondary"
- data-flx="channel.pickers.gif.import-favorite-gifs-modal.button.reset"
- >
- {i18n._(IMPORT_MORE_DESCRIPTOR)}
- </Button>
- <Button
- onClick={handleClose}
- variant="primary"
- data-flx="channel.pickers.gif.import-favorite-gifs-modal.button.close"
- >
- {i18n._(DONE_DESCRIPTOR)}
- </Button>
- </>
- ) : FavoriteGifImport.isRunning ? (
- <>
- <Button
- onClick={handleClose}
- variant="secondary"
- data-flx="channel.pickers.gif.import-favorite-gifs-modal.button.close--2"
- >
- {i18n._(CLOSE_DESCRIPTOR)}
- </Button>
- <Button
- onClick={handleCancel}
- variant="danger"
- data-flx="channel.pickers.gif.import-favorite-gifs-modal.button.cancel"
- >
- {i18n._(CANCEL_IMPORT_DESCRIPTOR)}
- </Button>
- </>
- ) : (
- <>
- <Button
- onClick={handleClose}
- variant="secondary"
- data-flx="channel.pickers.gif.import-favorite-gifs-modal.button.close--3"
- >
- {i18n._(CANCEL_DESCRIPTOR)}
- </Button>
- <Button
- onClick={handleImport}
- variant="primary"
- disabled={!text.trim() || isAtLimit}
- data-flx="channel.pickers.gif.import-favorite-gifs-modal.button.import"
- >
- {i18n._(IMPORT_DESCRIPTOR)}
- </Button>
- </>
- )}
+ {footerActions}
</Modal.Footer>
</Modal.Root>
);