Prevent warning on navigation for standalone composer (#41365)
This commit is contained in:
2 files changed
+15
-29
No files matched your search
@@ -47,7 +47,10 @@ export const RedesignComposeForm: React.FC<
|
||||
}) => {
|
||||
const type = useAppSelector(selectComposeType);
|
||||
|
||||
const { onEmojiPick, onSubmit } = useComposeHandlers(redirectOnSuccess);
|
||||
const { onEmojiPick, onSubmit } = useComposeHandlers({
|
||||
redirectOnSuccess,
|
||||
headless,
|
||||
});
|
||||
|
||||
const titleId = useId();
|
||||
const hintsId = useId();
|
||||
@@ -102,7 +105,13 @@ export const RedesignComposeForm: React.FC<
|
||||
const allowedAroundShortCode =
|
||||
'><\u0085\u0020\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029\u0009\u000a\u000b\u000c\u000d';
|
||||
|
||||
function useComposeHandlers(redirectOnSuccess?: boolean) {
|
||||
function useComposeHandlers({
|
||||
redirectOnSuccess,
|
||||
headless,
|
||||
}: {
|
||||
redirectOnSuccess?: boolean;
|
||||
headless?: boolean;
|
||||
}) {
|
||||
const text = useAppSelector((state) => state.compose.get('text') as string);
|
||||
|
||||
const dispatch = useAppDispatch();
|
||||
@@ -122,7 +131,7 @@ function useComposeHandlers(redirectOnSuccess?: boolean) {
|
||||
}
|
||||
|
||||
function closePage(event: BeforeUnloadEvent) {
|
||||
if (isComposerChanged) {
|
||||
if (isComposerChanged && !headless) {
|
||||
event.preventDefault();
|
||||
return true;
|
||||
}
|
||||
@@ -135,7 +144,7 @@ function useComposeHandlers(redirectOnSuccess?: boolean) {
|
||||
document.removeEventListener('keydown', escapeComposer);
|
||||
window.removeEventListener('beforeunload', closePage);
|
||||
};
|
||||
}, [dispatch, isComposerChanged, isModalOpen]);
|
||||
}, [dispatch, headless, isComposerChanged, isModalOpen]);
|
||||
|
||||
const onEmojiPick: OnEmojiPick = useCallback(
|
||||
(emoji) => {
|
||||
|
||||
@@ -1,28 +1,13 @@
|
||||
import { lazy, Suspense } from 'react';
|
||||
|
||||
import { AlertsController } from '@/mastodon/components/alerts_controller';
|
||||
import { LoadingIndicator } from '@/mastodon/components/loading_indicator';
|
||||
import ComposeFormContainer from '@/mastodon/features/compose/containers/compose_form_container';
|
||||
import LoadingBarContainer from '@/mastodon/features/ui/containers/loading_bar_container';
|
||||
import ModalContainer from '@/mastodon/features/ui/containers/modal_container';
|
||||
import { isRedesignEnabled } from '@/mastodon/utils/environment';
|
||||
|
||||
const ComposeLazyForm = lazy(() =>
|
||||
import('@/mastodon/features/compose/redesign/index').then(
|
||||
({ RedesignComposeForm }) => ({
|
||||
default: RedesignComposeForm,
|
||||
}),
|
||||
),
|
||||
);
|
||||
import { RedesignComposeForm } from '../../compose/redesign';
|
||||
|
||||
export const Compose: React.FC = () => {
|
||||
return (
|
||||
<>
|
||||
{isRedesignEnabled() ? (
|
||||
<RedesignCompose />
|
||||
) : (
|
||||
<ComposeFormContainer autoFocus withoutNavigation redirectOnSuccess />
|
||||
)}
|
||||
<RedesignComposeForm autoFocus headless redirectOnSuccess />
|
||||
<AlertsController />
|
||||
<ModalContainer />
|
||||
<LoadingBarContainer className='loading-bar' />
|
||||
@@ -30,13 +15,5 @@ export const Compose: React.FC = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const RedesignCompose: React.FC = () => {
|
||||
return (
|
||||
<Suspense fallback={<LoadingIndicator />}>
|
||||
<ComposeLazyForm autoFocus headless redirectOnSuccess />
|
||||
</Suspense>
|
||||
);
|
||||
};
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default Compose;
|
||||
Reference in new issue
Block a user