Sign out: Fix some component errors (#4323)

This commit is contained in:
Alexander Zinchuk 2024-03-01 14:02:47 -05:00
parent 033f8d4791
commit 511dbd13ae
13 changed files with 71 additions and 49 deletions

View File

@ -379,4 +379,7 @@ export default memo(withGlobal<OwnProps>(
availableReactions: global.reactions.availableReactions, availableReactions: global.reactions.availableReactions,
}; };
}, },
(global, { chatId }) => {
return Boolean(selectChat(global, chatId));
},
)(ManageChannel)); )(ManageChannel));

View File

@ -24,9 +24,9 @@ type OwnProps = {
}; };
type StateProps = { type StateProps = {
chat: ApiChat; chat?: ApiChat;
currentUserId?: string; currentUserId?: string;
isChannel: boolean; isChannel?: boolean;
adminMembersById?: Record<string, ApiChatMember>; adminMembersById?: Record<string, ApiChatMember>;
}; };
@ -47,7 +47,7 @@ const ManageChatAdministrators: FC<OwnProps & StateProps> = ({
onBack: onClose, onBack: onClose,
}); });
const canAddNewAdmins = Boolean(chat.isCreator || chat.adminRights?.addAdmins); const canAddNewAdmins = Boolean(chat?.isCreator || chat?.adminRights?.addAdmins);
const adminMembers = useMemo(() => { const adminMembers = useMemo(() => {
if (!adminMembersById) { if (!adminMembersById) {
@ -141,12 +141,12 @@ const ManageChatAdministrators: FC<OwnProps & StateProps> = ({
export default memo(withGlobal<OwnProps>( export default memo(withGlobal<OwnProps>(
(global, { chatId }): StateProps => { (global, { chatId }): StateProps => {
const chat = selectChat(global, chatId)!; const chat = selectChat(global, chatId);
return { return {
chat, chat,
currentUserId: global.currentUserId, currentUserId: global.currentUserId,
isChannel: isChatChannel(chat), isChannel: chat && isChatChannel(chat),
adminMembersById: selectChatFullInfo(global, chatId)?.adminMembersById, adminMembersById: selectChatFullInfo(global, chatId)?.adminMembersById,
}; };
}, },

View File

@ -312,4 +312,7 @@ export default memo(withGlobal<OwnProps>(
privateInviteLink: selectChatFullInfo(global, chatId)?.inviteLink, privateInviteLink: selectChatFullInfo(global, chatId)?.inviteLink,
}; };
}, },
(global, { chatId }) => {
return Boolean(selectChat(global, chatId) && selectManagement(global, chatId));
},
)(ManageChatPrivacyType)); )(ManageChatPrivacyType));

View File

@ -286,9 +286,7 @@ export default memo(withGlobal<OwnProps>(
const chat = selectChat(global, chatId); const chat = selectChat(global, chatId);
const { linkedChatId } = selectChatFullInfo(global, chatId) || {}; const { linkedChatId } = selectChatFullInfo(global, chatId) || {};
const { forDiscussionIds, byId: chatsByIds } = global.chats; const { forDiscussionIds, byId: chatsByIds } = global.chats;
const linkedChat = linkedChatId const linkedChat = linkedChatId ? selectChat(global, linkedChatId) : undefined;
? selectChat(global, linkedChatId)
: undefined;
return { return {
chat, chat,

View File

@ -1,7 +1,7 @@
import type { ChangeEvent } from 'react'; import type { ChangeEvent } from 'react';
import type { FC } from '../../../lib/teact/teact'; import type { FC } from '../../../lib/teact/teact';
import React, { import React, {
memo, useCallback, useEffect, useMemo, useRef, useState, memo, useEffect, useMemo, useRef, useState,
} from '../../../lib/teact/teact'; } from '../../../lib/teact/teact';
import { getActions, withGlobal } from '../../../global'; import { getActions, withGlobal } from '../../../global';
@ -25,6 +25,7 @@ import renderText from '../../common/helpers/renderText';
import useFlag from '../../../hooks/useFlag'; import useFlag from '../../../hooks/useFlag';
import useHistoryBack from '../../../hooks/useHistoryBack'; import useHistoryBack from '../../../hooks/useHistoryBack';
import useLang from '../../../hooks/useLang'; import useLang from '../../../hooks/useLang';
import useLastCallback from '../../../hooks/useLastCallback';
import useMedia from '../../../hooks/useMedia'; import useMedia from '../../../hooks/useMedia';
import AvatarEditable from '../../ui/AvatarEditable'; import AvatarEditable from '../../ui/AvatarEditable';
@ -158,50 +159,50 @@ const ManageGroup: FC<OwnProps & StateProps> = ({
} }
}, [progress]); }, [progress]);
const handleClickEditType = useCallback(() => { const handleClickEditType = useLastCallback(() => {
onScreenSelect(ManagementScreens.ChatPrivacyType); onScreenSelect(ManagementScreens.ChatPrivacyType);
}, [onScreenSelect]); });
const handleClickDiscussion = useCallback(() => { const handleClickDiscussion = useLastCallback(() => {
onScreenSelect(ManagementScreens.Discussion); onScreenSelect(ManagementScreens.Discussion);
}, [onScreenSelect]); });
const handleClickReactions = useCallback(() => { const handleClickReactions = useLastCallback(() => {
onScreenSelect(ManagementScreens.Reactions); onScreenSelect(ManagementScreens.Reactions);
}, [onScreenSelect]); });
const handleClickPermissions = useCallback(() => { const handleClickPermissions = useLastCallback(() => {
onScreenSelect(ManagementScreens.GroupPermissions); onScreenSelect(ManagementScreens.GroupPermissions);
}, [onScreenSelect]); });
const handleClickAdministrators = useCallback(() => { const handleClickAdministrators = useLastCallback(() => {
onScreenSelect(ManagementScreens.ChatAdministrators); onScreenSelect(ManagementScreens.ChatAdministrators);
}, [onScreenSelect]); });
const handleClickInvites = useCallback(() => { const handleClickInvites = useLastCallback(() => {
onScreenSelect(ManagementScreens.Invites); onScreenSelect(ManagementScreens.Invites);
}, [onScreenSelect]); });
const handleClickRequests = useCallback(() => { const handleClickRequests = useLastCallback(() => {
onScreenSelect(ManagementScreens.JoinRequests); onScreenSelect(ManagementScreens.JoinRequests);
}, [onScreenSelect]); });
const handleSetPhoto = useCallback((file: File) => { const handleSetPhoto = useLastCallback((file: File) => {
setPhoto(file); setPhoto(file);
setIsProfileFieldsTouched(true); setIsProfileFieldsTouched(true);
}, []); });
const handleTitleChange = useCallback((e: ChangeEvent<HTMLInputElement>) => { const handleTitleChange = useLastCallback((e: ChangeEvent<HTMLInputElement>) => {
setTitle(e.target.value); setTitle(e.target.value);
setIsProfileFieldsTouched(true); setIsProfileFieldsTouched(true);
}, []); });
const handleAboutChange = useCallback((e: ChangeEvent<HTMLTextAreaElement>) => { const handleAboutChange = useLastCallback((e: ChangeEvent<HTMLTextAreaElement>) => {
setAbout(e.target.value); setAbout(e.target.value);
setIsProfileFieldsTouched(true); setIsProfileFieldsTouched(true);
}, []); });
const handleUpdateGroup = useCallback(() => { const handleUpdateGroup = useLastCallback(() => {
const trimmedTitle = title.trim(); const trimmedTitle = title.trim();
const trimmedAbout = about.trim(); const trimmedAbout = about.trim();
@ -216,13 +217,13 @@ const ManageGroup: FC<OwnProps & StateProps> = ({
about: trimmedAbout, about: trimmedAbout,
photo, photo,
}); });
}, [about, chatId, photo, title, updateChat]); });
const handleClickMembers = useCallback(() => { const handleClickMembers = useLastCallback(() => {
onScreenSelect(ManagementScreens.GroupMembers); onScreenSelect(ManagementScreens.GroupMembers);
}, [onScreenSelect]); });
const handleTogglePreHistory = useCallback(() => { const handleTogglePreHistory = useLastCallback(() => {
if (!chatFullInfo) { if (!chatFullInfo) {
return; return;
} }
@ -230,9 +231,9 @@ const ManageGroup: FC<OwnProps & StateProps> = ({
const { isPreHistoryHidden } = chatFullInfo; const { isPreHistoryHidden } = chatFullInfo;
togglePreHistoryHidden({ chatId: chat.id, isEnabled: !isPreHistoryHidden }); togglePreHistoryHidden({ chatId: chat.id, isEnabled: !isPreHistoryHidden });
}, [chat.id, chatFullInfo]); });
const handleForumToggle = useCallback(() => { const handleForumToggle = useLastCallback(() => {
setIsForumEnabled((current) => { setIsForumEnabled((current) => {
const newIsForumEnabled = !current; const newIsForumEnabled = !current;
@ -242,7 +243,7 @@ const ManageGroup: FC<OwnProps & StateProps> = ({
return newIsForumEnabled; return newIsForumEnabled;
}); });
}, [chatId, toggleForum]); });
useEffect(() => { useEffect(() => {
if (!isChannelsPremiumLimitReached) { if (!isChannelsPremiumLimitReached) {
@ -298,7 +299,7 @@ const ManageGroup: FC<OwnProps & StateProps> = ({
return Object.keys(chatFullInfo?.adminMembersById || {}).length; return Object.keys(chatFullInfo?.adminMembersById || {}).length;
}, [chatFullInfo?.adminMembersById]); }, [chatFullInfo?.adminMembersById]);
const handleDeleteGroup = useCallback(() => { const handleDeleteGroup = useLastCallback(() => {
if (isBasicGroup) { if (isBasicGroup) {
deleteChat({ chatId: chat.id }); deleteChat({ chatId: chat.id });
} else if (!chat.isCreator) { } else if (!chat.isCreator) {
@ -309,10 +310,7 @@ const ManageGroup: FC<OwnProps & StateProps> = ({
closeDeleteDialog(); closeDeleteDialog();
closeManagement(); closeManagement();
openChat({ id: undefined }); openChat({ id: undefined });
}, [ });
isBasicGroup, chat.isCreator, chat.id,
closeDeleteDialog, closeManagement, leaveChannel, deleteChannel, deleteChat, openChat,
]);
if (chat.isRestricted || chat.isForbidden) { if (chat.isRestricted || chat.isForbidden) {
return undefined; return undefined;
@ -497,6 +495,9 @@ export default memo(withGlobal<OwnProps>(
const isBasicGroup = isChatBasicGroup(chat); const isBasicGroup = isChatBasicGroup(chat);
const { invites } = management.byChatId[chatId] || {}; const { invites } = management.byChatId[chatId] || {};
const canEditForum = !hasLinkedChannel && (getHasAdminRight(chat, 'changeInfo') || chat.isCreator); const canEditForum = !hasLinkedChannel && (getHasAdminRight(chat, 'changeInfo') || chat.isCreator);
const canChangeInfo = chat.isCreator || getHasAdminRight(chat, 'changeInfo');
const canBanUsers = chat.isCreator || getHasAdminRight(chat, 'banUsers');
const canInvite = chat.isCreator || getHasAdminRight(chat, 'inviteUsers');
return { return {
chat, chat,
@ -504,13 +505,16 @@ export default memo(withGlobal<OwnProps>(
progress, progress,
isBasicGroup, isBasicGroup,
hasLinkedChannel, hasLinkedChannel,
canChangeInfo: chat.isCreator || getHasAdminRight(chat, 'changeInfo'), canChangeInfo,
canBanUsers: chat.isCreator || getHasAdminRight(chat, 'banUsers'), canBanUsers,
canInvite: chat.isCreator || getHasAdminRight(chat, 'inviteUsers'), canInvite,
exportedInvites: invites, exportedInvites: invites,
isChannelsPremiumLimitReached: limitReachedModal?.limit === 'channels', isChannelsPremiumLimitReached: limitReachedModal?.limit === 'channels',
availableReactions: global.reactions.availableReactions, availableReactions: global.reactions.availableReactions,
canEditForum, canEditForum,
}; };
}, },
(global, { chatId }) => {
return Boolean(selectChat(global, chatId));
},
)(ManageGroup)); )(ManageGroup));

View File

@ -443,4 +443,7 @@ export default memo(withGlobal<OwnProps>(
adminMembersById: fullInfo?.adminMembersById, adminMembersById: fullInfo?.adminMembersById,
}; };
}, },
(global, { chatId }) => {
return Boolean(selectChat(global, chatId));
},
)(ManageGroupAdminRights)); )(ManageGroupAdminRights));

View File

@ -378,4 +378,7 @@ export default memo(withGlobal<OwnProps>(
members: fullInfo?.members, members: fullInfo?.members,
}; };
}, },
(global, { chatId }) => {
return Boolean(selectChat(global, chatId));
},
)(ManageGroupUserPermissions)); )(ManageGroupUserPermissions));

View File

@ -267,7 +267,7 @@ const ManageInvite: FC<OwnProps & StateProps> = ({
export default memo(withGlobal<OwnProps>( export default memo(withGlobal<OwnProps>(
(global, { chatId }): StateProps => { (global, { chatId }): StateProps => {
const { editingInvite } = selectTabState(global).management.byChatId[chatId]; const { editingInvite } = selectTabState(global).management.byChatId[chatId] || {};
return { return {
editingInvite, editingInvite,

View File

@ -186,7 +186,7 @@ const ManageInviteInfo: FC<OwnProps & StateProps> = ({
export default memo(withGlobal<OwnProps>( export default memo(withGlobal<OwnProps>(
(global, { chatId }): StateProps => { (global, { chatId }): StateProps => {
const { inviteInfo } = selectTabState(global).management.byChatId[chatId]; const { inviteInfo } = selectTabState(global).management.byChatId[chatId] || {};
const { invite, importers, requesters } = inviteInfo || {}; const { invite, importers, requesters } = inviteInfo || {};
const chat = selectChat(global, chatId); const chat = selectChat(global, chatId);
const isChannel = chat && isChatChannel(chat); const isChannel = chat && isChatChannel(chat);

View File

@ -377,7 +377,7 @@ const ManageInvites: FC<OwnProps & StateProps> = ({
export default memo(withGlobal<OwnProps>( export default memo(withGlobal<OwnProps>(
(global, { chatId }): StateProps => { (global, { chatId }): StateProps => {
const { invites, revokedInvites } = selectTabState(global).management.byChatId[chatId]; const { invites, revokedInvites } = selectTabState(global).management.byChatId[chatId] || {};
const chat = selectChat(global, chatId); const chat = selectChat(global, chatId);
const isChannel = chat && isChatChannel(chat); const isChannel = chat && isChatChannel(chat);

View File

@ -188,4 +188,7 @@ export default memo(withGlobal<OwnProps>(
chat, chat,
}; };
}, },
(global, { chatId }) => {
return Boolean(selectChat(global, chatId));
},
)(ManageReactions)); )(ManageReactions));

View File

@ -16,7 +16,7 @@ import { getCurrentTabId } from '../../../util/establishMultitabRole';
import { buildCollectionByKey } from '../../../util/iteratees'; import { buildCollectionByKey } from '../../../util/iteratees';
import { unsubscribe } from '../../../util/notifications'; import { unsubscribe } from '../../../util/notifications';
import { clearEncryptedSession, encryptSession, forgetPasscode } from '../../../util/passcode'; import { clearEncryptedSession, encryptSession, forgetPasscode } from '../../../util/passcode';
import { parseInitialLocationHash, resetInitialLocationHash } from '../../../util/routing'; import { parseInitialLocationHash, resetInitialLocationHash, resetLocationHash } from '../../../util/routing';
import { import {
clearLegacySessions, clearLegacySessions,
clearStoredSession, clearStoredSession,
@ -171,6 +171,7 @@ addActionHandler('signOut', async (global, actions, payload): Promise<void> => {
try { try {
resetInitialLocationHash(); resetInitialLocationHash();
resetLocationHash();
await unsubscribe(); await unsubscribe();
await callApi('destroy'); await callApi('destroy');
await forceWebsync(false); await forceWebsync(false);

View File

@ -21,6 +21,10 @@ export function resetInitialLocationHash() {
parsedInitialLocationHash = undefined; parsedInitialLocationHash = undefined;
} }
export function resetLocationHash() {
window.location.hash = '';
}
export const createLocationHash = (chatId: string, type: MessageListType, threadId: ThreadId): string => { export const createLocationHash = (chatId: string, type: MessageListType, threadId: ThreadId): string => {
const displayType = type === 'thread' ? undefined : type; const displayType = type === 'thread' ? undefined : type;
const parts = threadId === MAIN_THREAD_ID ? [chatId, displayType] : [chatId, threadId, displayType]; const parts = threadId === MAIN_THREAD_ID ? [chatId, displayType] : [chatId, threadId, displayType];