Skip to content

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

TypeScript fluxerfluxerapp

feat(app): anchor toasts to settings headers

Hampusd41eb66093c0
diff --git a/fluxer_app/src/features/app/components/dialogs/components/SettingsModalHeader.tsx b/fluxer_app/src/features/app/components/dialogs/components/SettingsModalHeader.tsx
index afa095453..34c750609 100644
--- a/fluxer_app/src/features/app/components/dialogs/components/SettingsModalHeader.tsx
+++ b/fluxer_app/src/features/app/components/dialogs/components/SettingsModalHeader.tsx
@@ -8,12 +8,14 @@ import {UnsavedChangesBannerContent} from '@app/features/app/components/dialogs/
import {NativeDragRegion} from '@app/features/app/components/layout/NativeDragRegion';
import {CLOSE_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';
import type {TabData} from '@app/features/ui/state/UnsavedChanges';
+import {useToastAnchor} from '@app/features/ui/toast/ToastAnchor';
import {useLingui} from '@lingui/react/macro';
import {XIcon} from '@phosphor-icons/react';
import {clsx} from 'clsx';
import {AnimatePresence, motion} from 'framer-motion';
import {observer} from 'mobx-react-lite';
import type React from 'react';
+import {useRef} from 'react';
interface SettingsModalHeaderProps {
title: React.ReactNode;
@@ -28,17 +30,19 @@ export const SettingsModalHeader: React.FC<SettingsModalHeaderProps> = observer(
({title, pageLinkHref, showUnsavedBanner, flashBanner, tabData, onClose}) => {
const {i18n} = useLingui();
const prefersReducedMotion = Accessibility.useReducedMotion;
+ const headerRef = useRef<HTMLElement>(null);
+ useToastAnchor(headerRef);
+ let backgroundColor: string | undefined;
+ if (showUnsavedBanner) {
+ backgroundColor = flashBanner ? 'var(--status-danger)' : 'var(--background-primary)';
+ }
return (
<NativeDragRegion
+ ref={headerRef}
className={`${settingsModalStyles.desktopHeader} ${styles.headerTransition}`}
style={{
transitionDuration: prefersReducedMotion ? '0ms' : '200ms',
- backgroundColor:
- showUnsavedBanner && flashBanner
- ? 'var(--status-danger)'
- : showUnsavedBanner
- ? 'var(--background-primary)'
- : undefined,
+ backgroundColor,
}}
data-flx="app.settings-modal-header.header-transition"
>
diff --git a/fluxer_app/src/features/app/components/dialogs/shared/MobileEntitySettingsView.tsx b/fluxer_app/src/features/app/components/dialogs/shared/MobileEntitySettingsView.tsx
index 4a455d8ec..efa65bf29 100644
--- a/fluxer_app/src/features/app/components/dialogs/shared/MobileEntitySettingsView.tsx
+++ b/fluxer_app/src/features/app/components/dialogs/shared/MobileEntitySettingsView.tsx
@@ -8,6 +8,7 @@ import {
import {SETTINGS_FADE_VARIANTS} from '@app/features/app/components/dialogs/shared/SettingsTransitions';
import {usePreservedScrollerPosition} from '@app/features/app/components/dialogs/shared/UsePreservedScrollerPosition';
import {Scroller} from '@app/features/ui/components/Scroller';
+import {useToastAnchor} from '@app/features/ui/toast/ToastAnchor';
import styles from '@app/features/user/components/modals/UserSettingsModal.module.css';
import type {MobileNavigationState} from '@app/features/user/hooks/useMobileNavigation';
import {useUnsavedChangesFlash} from '@app/features/user/hooks/useUnsavedChangesFlash';
@@ -15,7 +16,7 @@ import type {Icon, IconWeight} from '@phosphor-icons/react';
import {AnimatePresence, motion} from 'framer-motion';
import {observer} from 'mobx-react-lite';
import type React from 'react';
-import {useCallback} from 'react';
+import {useCallback, useRef} from 'react';
interface MobileEntityTab {
type: string;
@@ -71,12 +72,18 @@ export const MobileEntitySettingsView = observer(function MobileEntitySettingsVi
},
[checkUnsavedChanges, onTabSelect],
);
+ const headerRef = useRef<HTMLDivElement>(null);
+ useToastAnchor(headerRef);
const showMobileList = mobileNav.isRootView;
const showMobileContent = !mobileNav.isRootView;
const {scrollerRef: listScrollerRef, handleScroll: handleListScroll} = usePreservedScrollerPosition(showMobileList);
return (
<div className={styles.mobileWrapper} data-flx="app.mobile-entity-settings-view.mobile-wrapper">
- <div className={styles.mobileHeaderContainer} data-flx="app.mobile-entity-settings-view.mobile-header-container">
+ <div
+ ref={headerRef}
+ className={styles.mobileHeaderContainer}
+ data-flx="app.mobile-entity-settings-view.mobile-header-container"
+ >
<AnimatePresence
mode="wait"
custom={mobileNav.direction}