Safari: Fix loading error on account switch (#6547)
This commit is contained in:
parent
dbc363e79d
commit
eab1559134
@ -2,9 +2,11 @@ import { memo, useMemo } from '../../../lib/teact/teact';
|
|||||||
import { getActions } from '../../../global';
|
import { getActions } from '../../../global';
|
||||||
|
|
||||||
import type { ApiUser } from '../../../api/types';
|
import type { ApiUser } from '../../../api/types';
|
||||||
import type { CustomPeer } from '../../../types';
|
import type { AccountInfo, CustomPeer } from '../../../types';
|
||||||
|
|
||||||
|
import { temporarilySuspendCacheUpdate } from '../../../global/cache';
|
||||||
import { getCurrentMaxAccountCount, getCurrentProdAccountCount } from '../../../global/helpers';
|
import { getCurrentMaxAccountCount, getCurrentProdAccountCount } from '../../../global/helpers';
|
||||||
|
import { IS_SAFARI } from '../../../util/browser/windowEnvironment';
|
||||||
import { getAccountSlotUrl } from '../../../util/multiaccount';
|
import { getAccountSlotUrl } from '../../../util/multiaccount';
|
||||||
import { REM } from '../../common/helpers/mediaDimensions';
|
import { REM } from '../../common/helpers/mediaDimensions';
|
||||||
|
|
||||||
@ -43,12 +45,27 @@ const AccountMenuItems = ({
|
|||||||
|
|
||||||
const shouldShowLimit = currentCount >= maxCount;
|
const shouldShowLimit = currentCount >= maxCount;
|
||||||
|
|
||||||
const handleLimitClick = useLastCallback(() => {
|
const handleAccountClick = useLastCallback((account: AccountInfo) => {
|
||||||
showNotification({
|
if (account.userId === currentUser.id) {
|
||||||
title: lang('PremiumLimitAccountsTitle'),
|
onSelectCurrent?.();
|
||||||
message: currentUser.isPremium ? lang('PremiumLimitAccounts') : lang('PremiumLimitAccountsNoPremium'),
|
return;
|
||||||
duration: NOTIFICATION_DURATION,
|
}
|
||||||
});
|
|
||||||
|
// IDB locks up if we write large payload on navigation
|
||||||
|
if (IS_SAFARI) temporarilySuspendCacheUpdate();
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleNewAccountClick = useLastCallback(() => {
|
||||||
|
if (shouldShowLimit) {
|
||||||
|
showNotification({
|
||||||
|
title: lang('PremiumLimitAccountsTitle'),
|
||||||
|
message: currentUser.isPremium ? lang('PremiumLimitAccounts') : lang('PremiumLimitAccountsNoPremium'),
|
||||||
|
duration: NOTIFICATION_DURATION,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IS_SAFARI) temporarilySuspendCacheUpdate();
|
||||||
});
|
});
|
||||||
|
|
||||||
const newAccountUrl = useMemo(() => {
|
const newAccountUrl = useMemo(() => {
|
||||||
@ -96,7 +113,7 @@ const AccountMenuItems = ({
|
|||||||
previewUrl={account.avatarUri}
|
previewUrl={account.avatarUri}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
onClick={account.userId === currentUser.id ? onSelectCurrent : undefined}
|
onClick={() => handleAccountClick(account)}
|
||||||
href={account.userId !== currentUser.id ? getAccountSlotUrl(Number(slot)) : undefined}
|
href={account.userId !== currentUser.id ? getAccountSlotUrl(Number(slot)) : undefined}
|
||||||
>
|
>
|
||||||
{account.isTest && <span className="account-menu-item-test">T</span>}
|
{account.isTest && <span className="account-menu-item-test">T</span>}
|
||||||
@ -111,7 +128,7 @@ const AccountMenuItems = ({
|
|||||||
icon="add"
|
icon="add"
|
||||||
rel="noopener" // Allow referrer to be passed
|
rel="noopener" // Allow referrer to be passed
|
||||||
href={!shouldShowLimit ? newAccountUrl : undefined}
|
href={!shouldShowLimit ? newAccountUrl : undefined}
|
||||||
onClick={shouldShowLimit ? handleLimitClick : undefined}
|
onClick={handleNewAccountClick}
|
||||||
>
|
>
|
||||||
{lang('MenuAddAccount')}
|
{lang('MenuAddAccount')}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|||||||
@ -55,6 +55,7 @@ const updateCacheForced = () => updateCache(true);
|
|||||||
|
|
||||||
let isCaching = false;
|
let isCaching = false;
|
||||||
let isRemovingCache = false;
|
let isRemovingCache = false;
|
||||||
|
let cacheUpdateSuspensionTimestamp = 0;
|
||||||
let unsubscribeFromBeforeUnload: NoneToVoidFunction | undefined;
|
let unsubscribeFromBeforeUnload: NoneToVoidFunction | undefined;
|
||||||
|
|
||||||
export function cacheGlobal(global: GlobalState) {
|
export function cacheGlobal(global: GlobalState) {
|
||||||
@ -382,7 +383,15 @@ function updateCache(force?: boolean) {
|
|||||||
forceUpdateCache();
|
forceUpdateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function temporarilySuspendCacheUpdate() {
|
||||||
|
cacheUpdateSuspensionTimestamp = Date.now() + UPDATE_THROTTLE;
|
||||||
|
}
|
||||||
|
|
||||||
export function forceUpdateCache(noEncrypt = false) {
|
export function forceUpdateCache(noEncrypt = false) {
|
||||||
|
if (Date.now() < cacheUpdateSuspensionTimestamp) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const global = getGlobal();
|
const global = getGlobal();
|
||||||
const { hasPasscode, isScreenLocked } = global.passcode;
|
const { hasPasscode, isScreenLocked } = global.passcode;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user