mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-15 00:38:27 +00:00
[Glitch] fix: Keep user on Compose page when changing screen size, #34937
Port 6166e61638 to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { useCallback, useEffect, useLayoutEffect } from 'react';
|
||||
|
||||
import { useLayout } from '@/flavours/glitch/hooks/useLayout';
|
||||
import { useAppDispatch, useAppSelector } from '@/flavours/glitch/store';
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
mountCompose,
|
||||
unmountCompose,
|
||||
} from 'flavours/glitch/actions/compose';
|
||||
import { useAppHistory } from 'flavours/glitch/components/router';
|
||||
import ServerBanner from 'flavours/glitch/components/server_banner';
|
||||
import { Search } from 'flavours/glitch/features/compose/components/search';
|
||||
import ComposeFormContainer from 'flavours/glitch/features/compose/containers/compose_form_container';
|
||||
@@ -54,3 +55,25 @@ export const ComposePanel: React.FC = () => {
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Redirect the user to the standalone compose page when the
|
||||
* sidebar composer is hidden due to a change in viewport size
|
||||
* while a post is being written.
|
||||
*/
|
||||
|
||||
export const RedirectToMobileComposeIfNeeded: React.FC = () => {
|
||||
const history = useAppHistory();
|
||||
|
||||
const shouldRedirect = useAppSelector((state) =>
|
||||
state.compose.get('should_redirect_to_compose_page'),
|
||||
);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (shouldRedirect) {
|
||||
history.push('/publish');
|
||||
}
|
||||
}, [history, shouldRedirect]);
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user