Reset url hash when page is inactive (#3146)

Co-authored-by: Alexander Zinchuk <alx.zinchuk@gmail.com>
This commit is contained in:
Alexander Zinchuk 2023-05-03 20:21:15 +04:00
parent 171861f0dc
commit 46c6f8fb9b
2 changed files with 13 additions and 3 deletions

View File

@ -1,6 +1,8 @@
import type { FC } from '../../lib/teact/teact';
import React, { useCallback } from '../../lib/teact/teact';
import useHistoryBack from '../../hooks/useHistoryBack';
import Button from '../ui/Button';
import appInactivePath from '../../assets/app-inactive.png';
@ -11,6 +13,12 @@ const AppInactive: FC = () => {
window.location.reload();
}, []);
useHistoryBack({
isActive: true,
onBack: handleReload,
shouldResetUrlHash: true,
});
return (
<div id="AppInactive">
<div className="content">

View File

@ -231,13 +231,14 @@ window.addEventListener('popstate', ({ state }: PopStateEvent) => {
export default function useHistoryBack({
isActive,
shouldBeReplaced,
shouldResetUrlHash,
hash,
onBack,
}: {
isActive?: boolean;
shouldBeReplaced?: boolean;
hash?: string;
title?: string;
shouldResetUrlHash?: boolean;
onBack: VoidFunction;
}) {
// Active index of the record
@ -279,9 +280,10 @@ export default function useHistoryBack({
index: indexRef.current,
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(() => {
// Only process back on open records