Skip to content

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

TypeScript fluxerfluxerapp

feat(app): hide dismiss-only dialog footers on desktop

Hampusfdcfe7e0f3c7
diff --git a/fluxer_app/src/features/app/components/alerts/GenericErrorModal.tsx b/fluxer_app/src/features/app/components/alerts/GenericErrorModal.tsx
index 46abb9483..e7992268f 100644
--- a/fluxer_app/src/features/app/components/alerts/GenericErrorModal.tsx
+++ b/fluxer_app/src/features/app/components/alerts/GenericErrorModal.tsx
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {ConfirmModal} from '@app/features/app/components/dialogs/ConfirmModal';
-import {UNDERSTOOD_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';
-import {useLingui} from '@lingui/react/macro';
import {observer} from 'mobx-react-lite';
interface GenericErrorModalProps {
@@ -11,17 +9,6 @@ interface GenericErrorModalProps {
'data-flx'?: string;
}
-export const GenericErrorModal: React.FC<GenericErrorModalProps> = observer(({title, message, 'data-flx': dataFlx}) => {
- const {i18n} = useLingui();
- return (
- <ConfirmModal
- title={title}
- description={message}
- primaryText={i18n._(UNDERSTOOD_DESCRIPTOR)}
- onPrimary={() => {}}
- secondaryText={false}
- hideCloseButton
- data-flx={dataFlx ?? 'app.generic-error-modal.confirm-modal'}
- />
- );
-});
+export const GenericErrorModal: React.FC<GenericErrorModalProps> = observer(({title, message, 'data-flx': dataFlx}) => (
+ <ConfirmModal title={title} description={message} data-flx={dataFlx ?? 'app.generic-error-modal.confirm-modal'} />
+));
diff --git a/fluxer_app/src/features/app/components/alerts/MaxFavoriteMemesModal.tsx b/fluxer_app/src/features/app/components/alerts/MaxFavoriteMemesModal.tsx
index f216ce2a1..ee592969f 100644
--- a/fluxer_app/src/features/app/components/alerts/MaxFavoriteMemesModal.tsx
+++ b/fluxer_app/src/features/app/components/alerts/MaxFavoriteMemesModal.tsx
@@ -3,7 +3,6 @@
import {GenericErrorModal} from '@app/features/app/components/alerts/GenericErrorModal';
import {ConfirmModal} from '@app/features/app/components/dialogs/ConfirmModal';
import {Limits} from '@app/features/app/utils/UserLimits';
-import {CLOSE_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';
import * as PremiumModalCommands from '@app/features/premium/commands/PremiumModalCommands';
import {getPremiumProductName, shouldShowPremiumFeatures} from '@app/features/premium/utils/PremiumUtils';
import Users from '@app/features/user/state/Users';
@@ -64,8 +63,6 @@ export const MaxFavoriteMemesModal = observer(() => {
<ConfirmModal
title={i18n._(SAVED_MEDIA_LIMIT_REACHED_DESCRIPTOR)}
description={description}
- secondaryText={i18n._(CLOSE_DESCRIPTOR)}
- hideCloseButton
data-flx="app.max-favorite-memes-modal.confirm-modal--2"
/>
);
diff --git a/fluxer_app/src/features/app/components/alerts/RateLimitedConfirmModal.tsx b/fluxer_app/src/features/app/components/alerts/RateLimitedConfirmModal.tsx
index a9fc68719..875c559aa 100644
--- a/fluxer_app/src/features/app/components/alerts/RateLimitedConfirmModal.tsx
+++ b/fluxer_app/src/features/app/components/alerts/RateLimitedConfirmModal.tsx
@@ -1,13 +1,11 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {ConfirmModal} from '@app/features/app/components/dialogs/ConfirmModal';
+import {CLOSE_DESCRIPTOR, TRY_AGAIN_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';
import {
- CLOSE_DESCRIPTOR,
- MINUTES_AND_SECONDS_DURATION_DESCRIPTOR,
- MINUTES_DURATION_PLURAL_DESCRIPTOR,
- SECONDS_DURATION_PLURAL_DESCRIPTOR,
- TRY_AGAIN_DESCRIPTOR,
-} from '@app/features/i18n/utils/CommonMessageDescriptors';
+ formatRateLimitDuration,
+ RATE_LIMITED_DURATION_BODY_DESCRIPTOR,
+} from '@app/features/i18n/utils/RateLimitDuration';
import {msg} from '@lingui/core/macro';
import {useLingui} from '@lingui/react/macro';
import {observer} from 'mobx-react-lite';
@@ -16,50 +14,40 @@ const RATE_LIMITED_FALLBACK_BODY_DESCRIPTOR = msg({
message: 'Slow down — wait a moment before trying again.',
comment: 'Modal body shown when an action is blocked by rate limiting. Keep plain.',
});
-const RATE_LIMITED_DURATION_BODY_DESCRIPTOR = msg({
- message: "You're being rate limited. Wait {duration} before trying again.",
- comment:
- 'Modal body shown when an action is blocked by rate limiting. {duration} is a localized short duration such as "2 minutes".',
-});
interface RateLimitedConfirmModalProps {
title: string;
retryAfter?: number;
onRetry?: () => void;
- hideCloseButton?: boolean;
describe?: (duration: string | undefined) => string;
}
export const RateLimitedConfirmModal = observer(
- ({title, retryAfter, onRetry, hideCloseButton, describe}: RateLimitedConfirmModalProps) => {
+ ({title, retryAfter, onRetry, describe}: RateLimitedConfirmModalProps) => {
const {i18n} = useLingui();
const hasRetryAfter = retryAfter != null;
- const formatRateLimitTime = (totalSeconds: number): string => {
- if (totalSeconds < 60) {
- return i18n._(SECONDS_DURATION_PLURAL_DESCRIPTOR, {seconds: totalSeconds});
- }
- const minutes = Math.floor(totalSeconds / 60);
- const seconds = totalSeconds % 60;
- if (seconds === 0) {
- return i18n._(MINUTES_DURATION_PLURAL_DESCRIPTOR, {minutes});
- }
- return i18n._(MINUTES_AND_SECONDS_DURATION_DESCRIPTOR, {minutes, seconds});
- };
+ let description: string;
+ if (describe) {
+ const duration = hasRetryAfter ? formatRateLimitDuration(i18n, retryAfter) : undefined;
+ description = describe(duration);
+ } else if (hasRetryAfter) {
+ description = i18n._(RATE_LIMITED_DURATION_BODY_DESCRIPTOR, {
+ duration: formatRateLimitDuration(i18n, retryAfter),
+ });
+ } else {
+ description = i18n._(RATE_LIMITED_FALLBACK_BODY_DESCRIPTOR);
+ }
+ if (!onRetry) {
+ return (
+ <ConfirmModal title={title} description={description} data-flx="app.rate-limited-confirm-modal.confirm-modal" />
+ );
+ }
return (
<ConfirmModal
title={title}
- description={
- describe
- ? describe(hasRetryAfter ? formatRateLimitTime(retryAfter) : undefined)
- : hasRetryAfter
- ? i18n._(RATE_LIMITED_DURATION_BODY_DESCRIPTOR, {
- duration: formatRateLimitTime(retryAfter),
- })
- : i18n._(RATE_LIMITED_FALLBACK_BODY_DESCRIPTOR)
- }
+ description={description}
secondaryText={hasRetryAfter ? i18n._(TRY_AGAIN_DESCRIPTOR) : i18n._(CLOSE_DESCRIPTOR)}
onSecondary={onRetry}
- hideCloseButton={hideCloseButton}
data-flx="app.rate-limited-confirm-modal.confirm-modal"
/>
);
diff --git a/fluxer_app/src/features/app/components/dialogs/ConfirmModal.tsx b/fluxer_app/src/features/app/components/dialogs/ConfirmModal.tsx
index 2b21ffa88..db2848dd5 100644
--- a/fluxer_app/src/features/app/components/dialogs/ConfirmModal.tsx
+++ b/fluxer_app/src/features/app/components/dialogs/ConfirmModal.tsx
@@ -43,12 +43,10 @@ interface ConfirmModalCommonProps {
title: React.ReactNode;
description: React.ReactNode;
message?: MessageModel;
- secondaryText?: React.ReactNode | false;
size?: ModalProps['size'];
onSecondary?: (checkboxChecked?: boolean) => void;
checkboxContent?: React.ReactElement<ConfirmModalCheckboxProps>;
toggleSwitchContent?: React.ReactElement<ConfirmModalSwitchProps>;
- hideCloseButton?: boolean;
showShiftBypassConfirmationTip?: boolean;
disableAutoDismiss?: boolean;
}
@@ -59,8 +57,10 @@ type ConfirmModalProps =
primaryText: React.ReactNode;
primaryVariant?: ConfirmModalPrimaryVariant;
onPrimary: (checkboxChecked?: boolean) => Promise<void> | void;
+ secondaryText?: React.ReactNode | false;
})
| (ConfirmModalCommonProps & {
+ secondaryText?: React.ReactNode;
primaryText?: never;
primaryVariant?: never;
onPrimary?: never;
@@ -79,7 +79,6 @@ export const ConfirmModal = observer(
onSecondary,
checkboxContent,
toggleSwitchContent,
- hideCloseButton,
showShiftBypassConfirmationTip = false,
disableAutoDismiss = false,
}: ConfirmModalProps) => {
@@ -140,9 +139,10 @@ export const ConfirmModal = observer(
ModalCommands.pop();
}
}, [onSecondary, checkboxChecked]);
+ const hasFooterAction = Boolean((onPrimary && primaryText) || onSecondary);
return (
<Modal.Root size={size} initialFocusRef={initialFocusRef} centered data-flx="app.confirm-modal.modal-root">
- <Modal.Header title={title} hideCloseButton={hideCloseButton} data-flx="app.confirm-modal.modal-header" />
+ <Modal.Header title={title} data-flx="app.confirm-modal.modal-header" />
<Modal.Content data-flx="app.confirm-modal.modal-content">
<Modal.ContentLayout data-flx="app.confirm-modal.modal-content-layout">
<Modal.Description data-flx="app.confirm-modal.modal-description">{description}</Modal.Description>
@@ -184,28 +184,32 @@ export const ConfirmModal = observer(
)}
</Modal.ContentLayout>
</Modal.Content>
- <Modal.Footer data-flx="app.confirm-modal.footer">
- {secondaryText !== false && (
- <Button
- onClick={handleSecondaryClick}
- variant="secondary"
- data-flx="app.confirm-modal.button.secondary-click"
- >
- {secondaryText ?? i18n._(CANCEL_DESCRIPTOR)}
- </Button>
- )}
- {onPrimary && primaryText && (
- <Button
- onClick={handlePrimaryClick}
- submitting={submitting}
- variant={primaryVariant}
- ref={initialFocusRef}
- data-flx="app.confirm-modal.button.primary-click"
- >
- {primaryText}
- </Button>
- )}
- </Modal.Footer>
+ {hasFooterAction ? (
+ <Modal.Footer data-flx="app.confirm-modal.footer">
+ {secondaryText !== false && (
+ <Button
+ onClick={handleSecondaryClick}
+ variant="secondary"
+ data-flx="app.confirm-modal.button.secondary-click"
+ >
+ {secondaryText ?? i18n._(CANCEL_DESCRIPTOR)}
+ </Button>
+ )}
+ {onPrimary && primaryText && (
+ <Button
+ onClick={handlePrimaryClick}
+ submitting={submitting}
+ variant={primaryVariant}
+ ref={initialFocusRef}
+ data-flx="app.confirm-modal.button.primary-click"
+ >
+ {primaryText}
+ </Button>
+ )}
+ </Modal.Footer>
+ ) : (
+ <Modal.DismissFooter label={secondaryText} data-flx="app.confirm-modal.dismiss-footer" />
+ )}
</Modal.Root>
);
},
diff --git a/fluxer_app/src/features/app/components/dialogs/Modal.module.css b/fluxer_app/src/features/app/components/dialogs/Modal.module.css
index fd3848ecd..e99469b75 100644
--- a/fluxer_app/src/features/app/components/dialogs/Modal.module.css
+++ b/fluxer_app/src/features/app/components/dialogs/Modal.module.css
@@ -150,10 +150,13 @@
}
.root.small {
- min-height: 12.5rem;
width: 27.5rem;
}
+.root.small:has(.footer, .formFooter) {
+ min-height: 12.5rem;
+}
+
.root.large {
min-height: 25rem;
width: 50rem;
@@ -428,7 +431,6 @@
display: flex;
flex-direction: column;
gap: 1rem;
- padding-bottom: 1rem;
}
.description {
diff --git a/fluxer_app/src/features/app/components/dialogs/Modal.tsx b/fluxer_app/src/features/app/components/dialogs/Modal.tsx
index 9bcb480be..26989c277 100644
--- a/fluxer_app/src/features/app/components/dialogs/Modal.tsx
+++ b/fluxer_app/src/features/app/components/dialogs/Modal.tsx
@@ -5,6 +5,7 @@ import {resolveModalBackdropMotionSpec, resolveModalMotionSpec} from '@app/featu
import {useModalResizePin, useWindowLiveResize} from '@app/features/app/components/dialogs/useModalResizePin';
import {useModalBackHandler} from '@app/features/app/hooks/useModalBackHandler';
import {CLOSE_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';
+import {Button} from '@app/features/ui/button/Button';
import * as PopoutCommands from '@app/features/ui/commands/PopoutCommands';
import {Scroller, type ScrollerHandle} from '@app/features/ui/components/Scroller';
import FocusRing from '@app/features/ui/focus_ring/FocusRing';
@@ -12,6 +13,7 @@ import FocusRingManager from '@app/features/ui/focus_ring/FocusRingManager';
import FocusRingScope from '@app/features/ui/focus_ring/FocusRingScope';
import {usePortalHost} from '@app/features/ui/overlay/PortalHostContext';
import KeyboardMode from '@app/features/ui/state/KeyboardMode';
+import MobileLayout from '@app/features/ui/state/MobileLayout';
import OverlayStack from '@app/features/ui/state/OverlayStack';
import {ModalStackContext} from '@app/features/ui/utils/ModalStackContext';
import {
@@ -51,6 +53,7 @@ const RootComponent = React.forwardRef<HTMLDivElement, ModalProps>(
onClose,
onAnimationComplete,
backdropSlot,
+ backdropTone = 'default',
transitionPreset = 'default',
disableHistoryManagement = false,
...props
@@ -123,6 +126,7 @@ const RootComponent = React.forwardRef<HTMLDivElement, ModalProps>(
transitionPreset,
prefersReducedMotion,
isMobile,
+ backdropTone,
});
const handleBackdropClickEvent = useCallback(
(event: React.MouseEvent) => {
@@ -407,6 +411,26 @@ export const Footer = React.forwardRef<HTMLDivElement, FooterProps>(
Footer.displayName = 'ModalFooter';
+interface DismissFooterProps {
+ label?: React.ReactNode;
+ onDismiss?: () => void;
+}
+
+export const DismissFooter = observer(({label, onDismiss, ...props}: DismissFooterProps) => {
+ const {i18n} = useLingui();
+ const {popOwningModal} = useModalContext();
+ if (!MobileLayout.enabled) {
+ return null;
+ }
+ return (
+ <Footer data-flx="app.modal.dismiss-footer" {...props}>
+ <Button variant="secondary" onClick={onDismiss ?? popOwningModal} data-flx="app.modal.dismiss-footer.button">
+ {label ?? i18n._(CLOSE_DESCRIPTOR)}
+ </Button>
+ </Footer>
+ );
+});
+
export const ScreenReaderLabel: React.FC<ScreenReaderLabelProps> = ({text, id}) => {
const modalContextValue = useModalContext();
const {labelId} = useScreenReaderLabelLogic({
diff --git a/fluxer_app/src/features/app/components/dialogs/ModalMotion.ts b/fluxer_app/src/features/app/components/dialogs/ModalMotion.ts
index 0fa873f01..2b53f5f80 100644
--- a/fluxer_app/src/features/app/components/dialogs/ModalMotion.ts
+++ b/fluxer_app/src/features/app/components/dialogs/ModalMotion.ts
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
-import type {ModalTransitionPreset} from '@app/features/ui/utils/ModalUtils';
+import type {ModalBackdropTone, ModalTransitionPreset} from '@app/features/ui/utils/ModalUtils';
export interface ModalMotionInput {
transitionPreset: ModalTransitionPreset;
@@ -12,11 +12,15 @@ export interface ModalBackdropMotionInput {
transitionPreset: ModalTransitionPreset;
prefersReducedMotion: boolean;
isMobile: boolean;
+ backdropTone: ModalBackdropTone;
}
const SETTLED_SURFACE = {opacity: 1, scale: 1} as const;
-const BACKDROP_RESTING_OPACITY = 0.85;
+const BACKDROP_RESTING_OPACITY: Record<ModalBackdropTone, number> = {
+ default: 0.85,
+ strong: 0.92,
+};
const BACKDROP_DISMISS_SPRING = {type: 'spring', stiffness: 1000, damping: 48, mass: 1} as const;
@@ -81,11 +85,13 @@ export function resolveModalBackdropMotionSpec({
transitionPreset,
prefersReducedMotion,
isMobile,
+ backdropTone,
}: ModalBackdropMotionInput) {
const mountsAtRest = (isMobile && !prefersReducedMotion) || transitionPreset === 'instant';
+ const restingOpacity = BACKDROP_RESTING_OPACITY[backdropTone];
const surface = {
- initial: {opacity: mountsAtRest ? BACKDROP_RESTING_OPACITY : 0},
- animate: {opacity: BACKDROP_RESTING_OPACITY},
+ initial: {opacity: mountsAtRest ? restingOpacity : 0},
+ animate: {opacity: restingOpacity},
exit: {opacity: 0},
};
if (prefersReducedMotion) {
diff --git a/fluxer_app/src/features/app/components/layout/app_layout/nagbars/DesktopNotificationNagbar.tsx b/fluxer_app/src/features/app/components/layout/app_layout/nagbars/DesktopNotificationNagbar.tsx
index cfdb7bd33..897852e3e 100644
--- a/fluxer_app/src/features/app/components/layout/app_layout/nagbars/DesktopNotificationNagbar.tsx
+++ b/fluxer_app/src/features/app/components/layout/app_layout/nagbars/DesktopNotificationNagbar.tsx
@@ -7,7 +7,7 @@ import {NagbarButton} from '@app/features/app/components/layout/NagbarButton';
import {NagbarContent} from '@app/features/app/components/layout/NagbarContent';
import {NAGBAR_TONES, NagbarToneKind} from '@app/features/app/components/layout/NagbarTones';
import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
-import {ENABLE_NOTIFICATIONS_DESCRIPTOR, OKAY_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';
+import {ENABLE_NOTIFICATIONS_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';
import {usePushSubscriptions} from '@app/features/notification/hooks/usePushSubscriptions';
import * as NotificationUtils from '@app/features/notification/utils/NotificationUtils';
import * as PushSubscriptionService from '@app/features/platform/push/PushSubscriptionService';
@@ -60,6 +60,7 @@ export const DesktopNotificationNagbar = observer(({isMobile}: {isMobile: boolea
const notificationSettingsPath = formatUserSettingsPath(i18n, 'notifications', 'notifications');
const handleEnable = () => {
if (typeof Notification === 'undefined') {
+ NagbarCommands.dismissNagbar('desktopNotificationDismissed');
ModalCommands.push(
modal(() => (
<ConfirmModal
@@ -69,12 +70,6 @@ export const DesktopNotificationNagbar = observer(({isMobile}: {isMobile: boolea
{i18n._(DEVICE_NOTIFICATIONS_UNSUPPORTED_DESCRIPTOR)}
</p>
}
- primaryText={i18n._(OKAY_DESCRIPTOR)}
- primaryVariant="primary"
- secondaryText={false}
- onPrimary={() => {
- NagbarCommands.dismissNagbar('desktopNotificationDismissed');
- }}
data-flx="app.app-layout.nagbars.desktop-notification-nagbar.handle-enable.confirm-modal"
/>
)),