Reset url hash when page is inactive (#3146)
Co-authored-by: Alexander Zinchuk <alx.zinchuk@gmail.com>
This commit is contained in:
parent
171861f0dc
commit
46c6f8fb9b
@ -1,6 +1,8 @@
|
|||||||
import type { FC } from '../../lib/teact/teact';
|
import type { FC } from '../../lib/teact/teact';
|
||||||
import React, { useCallback } from '../../lib/teact/teact';
|
import React, { useCallback } from '../../lib/teact/teact';
|
||||||
|
|
||||||
|
import useHistoryBack from '../../hooks/useHistoryBack';
|
||||||
|
|
||||||
import Button from '../ui/Button';
|
import Button from '../ui/Button';
|
||||||
|
|
||||||
import appInactivePath from '../../assets/app-inactive.png';
|
import appInactivePath from '../../assets/app-inactive.png';
|
||||||
@ -11,6 +13,12 @@ const AppInactive: FC = () => {
|
|||||||
window.location.reload();
|
window.location.reload();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useHistoryBack({
|
||||||
|
isActive: true,
|
||||||
|
onBack: handleReload,
|
||||||
|
shouldResetUrlHash: true,
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="AppInactive">
|
<div id="AppInactive">
|
||||||
<div className="content">
|
<div className="content">
|
||||||
|
|||||||
@ -231,13 +231,14 @@ window.addEventListener('popstate', ({ state }: PopStateEvent) => {
|
|||||||
export default function useHistoryBack({
|
export default function useHistoryBack({
|
||||||
isActive,
|
isActive,
|
||||||
shouldBeReplaced,
|
shouldBeReplaced,
|
||||||
|
shouldResetUrlHash,
|
||||||
hash,
|
hash,
|
||||||
onBack,
|
onBack,
|
||||||
}: {
|
}: {
|
||||||
isActive?: boolean;
|
isActive?: boolean;
|
||||||
shouldBeReplaced?: boolean;
|
shouldBeReplaced?: boolean;
|
||||||
hash?: string;
|
hash?: string;
|
||||||
title?: string;
|
shouldResetUrlHash?: boolean;
|
||||||
onBack: VoidFunction;
|
onBack: VoidFunction;
|
||||||
}) {
|
}) {
|
||||||
// Active index of the record
|
// Active index of the record
|
||||||
@ -279,9 +280,10 @@ export default function useHistoryBack({
|
|||||||
index: indexRef.current,
|
index: indexRef.current,
|
||||||
historyUniqueSessionId,
|
historyUniqueSessionId,
|
||||||
},
|
},
|
||||||
hash: hash ? `#${hash}` : undefined,
|
// Space is a hack to make the browser completely remove the hash
|
||||||
|
hash: hash ? `#${hash}` : (shouldResetUrlHash ? ' ' : undefined),
|
||||||
});
|
});
|
||||||
}, [hash, onBack, shouldBeReplaced]);
|
}, [hash, onBack, shouldBeReplaced, shouldResetUrlHash]);
|
||||||
|
|
||||||
const processBack = useCallback(() => {
|
const processBack = useCallback(() => {
|
||||||
// Only process back on open records
|
// Only process back on open records
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user