Sign out: Fix some component errors (#4323)
This commit is contained in:
parent
033f8d4791
commit
511dbd13ae
@ -379,4 +379,7 @@ export default memo(withGlobal<OwnProps>(
|
||||
availableReactions: global.reactions.availableReactions,
|
||||
};
|
||||
},
|
||||
(global, { chatId }) => {
|
||||
return Boolean(selectChat(global, chatId));
|
||||
},
|
||||
)(ManageChannel));
|
||||
|
||||
@ -24,9 +24,9 @@ type OwnProps = {
|
||||
};
|
||||
|
||||
type StateProps = {
|
||||
chat: ApiChat;
|
||||
chat?: ApiChat;
|
||||
currentUserId?: string;
|
||||
isChannel: boolean;
|
||||
isChannel?: boolean;
|
||||
adminMembersById?: Record<string, ApiChatMember>;
|
||||
};
|
||||
|
||||
@ -47,7 +47,7 @@ const ManageChatAdministrators: FC<OwnProps & StateProps> = ({
|
||||
onBack: onClose,
|
||||
});
|
||||
|
||||
const canAddNewAdmins = Boolean(chat.isCreator || chat.adminRights?.addAdmins);
|
||||
const canAddNewAdmins = Boolean(chat?.isCreator || chat?.adminRights?.addAdmins);
|
||||
|
||||
const adminMembers = useMemo(() => {
|
||||
if (!adminMembersById) {
|
||||
@ -141,12 +141,12 @@ const ManageChatAdministrators: FC<OwnProps & StateProps> = ({
|
||||
|
||||
export default memo(withGlobal<OwnProps>(
|
||||
(global, { chatId }): StateProps => {
|
||||
const chat = selectChat(global, chatId)!;
|
||||
const chat = selectChat(global, chatId);
|
||||
|
||||
return {
|
||||
chat,
|
||||
currentUserId: global.currentUserId,
|
||||
isChannel: isChatChannel(chat),
|
||||
isChannel: chat && isChatChannel(chat),
|
||||
adminMembersById: selectChatFullInfo(global, chatId)?.adminMembersById,
|
||||
};
|
||||
},
|
||||
|
||||
@ -312,4 +312,7 @@ export default memo(withGlobal<OwnProps>(
|
||||
privateInviteLink: selectChatFullInfo(global, chatId)?.inviteLink,
|
||||
};
|
||||
},
|
||||
(global, { chatId }) => {
|
||||
return Boolean(selectChat(global, chatId) && selectManagement(global, chatId));
|
||||
},
|
||||
)(ManageChatPrivacyType));
|
||||
|
||||
@ -286,9 +286,7 @@ export default memo(withGlobal<OwnProps>(
|
||||
const chat = selectChat(global, chatId);
|
||||
const { linkedChatId } = selectChatFullInfo(global, chatId) || {};
|
||||
const { forDiscussionIds, byId: chatsByIds } = global.chats;
|
||||
const linkedChat = linkedChatId
|
||||
? selectChat(global, linkedChatId)
|
||||
: undefined;
|
||||
const linkedChat = linkedChatId ? selectChat(global, linkedChatId) : undefined;
|
||||
|
||||
return {
|
||||
chat,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import type { ChangeEvent } from 'react';
|
||||
import type { FC } from '../../../lib/teact/teact';
|
||||
import React, {
|
||||
memo, useCallback, useEffect, useMemo, useRef, useState,
|
||||
memo, useEffect, useMemo, useRef, useState,
|
||||
} from '../../../lib/teact/teact';
|
||||
import { getActions, withGlobal } from '../../../global';
|
||||
|
||||
@ -25,6 +25,7 @@ import renderText from '../../common/helpers/renderText';
|
||||
import useFlag from '../../../hooks/useFlag';
|
||||
import useHistoryBack from '../../../hooks/useHistoryBack';
|
||||
import useLang from '../../../hooks/useLang';
|
||||
import useLastCallback from '../../../hooks/useLastCallback';
|
||||
import useMedia from '../../../hooks/useMedia';
|
||||
|
||||
import AvatarEditable from '../../ui/AvatarEditable';
|
||||
@ -158,50 +159,50 @@ const ManageGroup: FC<OwnProps & StateProps> = ({
|
||||
}
|
||||
}, [progress]);
|
||||
|
||||
const handleClickEditType = useCallback(() => {
|
||||
const handleClickEditType = useLastCallback(() => {
|
||||
onScreenSelect(ManagementScreens.ChatPrivacyType);
|
||||
}, [onScreenSelect]);
|
||||
});
|
||||
|
||||
const handleClickDiscussion = useCallback(() => {
|
||||
const handleClickDiscussion = useLastCallback(() => {
|
||||
onScreenSelect(ManagementScreens.Discussion);
|
||||
}, [onScreenSelect]);
|
||||
});
|
||||
|
||||
const handleClickReactions = useCallback(() => {
|
||||
const handleClickReactions = useLastCallback(() => {
|
||||
onScreenSelect(ManagementScreens.Reactions);
|
||||
}, [onScreenSelect]);
|
||||
});
|
||||
|
||||
const handleClickPermissions = useCallback(() => {
|
||||
const handleClickPermissions = useLastCallback(() => {
|
||||
onScreenSelect(ManagementScreens.GroupPermissions);
|
||||
}, [onScreenSelect]);
|
||||
});
|
||||
|
||||
const handleClickAdministrators = useCallback(() => {
|
||||
const handleClickAdministrators = useLastCallback(() => {
|
||||
onScreenSelect(ManagementScreens.ChatAdministrators);
|
||||
}, [onScreenSelect]);
|
||||
});
|
||||
|
||||
const handleClickInvites = useCallback(() => {
|
||||
const handleClickInvites = useLastCallback(() => {
|
||||
onScreenSelect(ManagementScreens.Invites);
|
||||
}, [onScreenSelect]);
|
||||
});
|
||||
|
||||
const handleClickRequests = useCallback(() => {
|
||||
const handleClickRequests = useLastCallback(() => {
|
||||
onScreenSelect(ManagementScreens.JoinRequests);
|
||||
}, [onScreenSelect]);
|
||||
});
|
||||
|
||||
const handleSetPhoto = useCallback((file: File) => {
|
||||
const handleSetPhoto = useLastCallback((file: File) => {
|
||||
setPhoto(file);
|
||||
setIsProfileFieldsTouched(true);
|
||||
}, []);
|
||||
});
|
||||
|
||||
const handleTitleChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {
|
||||
const handleTitleChange = useLastCallback((e: ChangeEvent<HTMLInputElement>) => {
|
||||
setTitle(e.target.value);
|
||||
setIsProfileFieldsTouched(true);
|
||||
}, []);
|
||||
});
|
||||
|
||||
const handleAboutChange = useCallback((e: ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const handleAboutChange = useLastCallback((e: ChangeEvent<HTMLTextAreaElement>) => {
|
||||
setAbout(e.target.value);
|
||||
setIsProfileFieldsTouched(true);
|
||||
}, []);
|
||||
});
|
||||
|
||||
const handleUpdateGroup = useCallback(() => {
|
||||
const handleUpdateGroup = useLastCallback(() => {
|
||||
const trimmedTitle = title.trim();
|
||||
const trimmedAbout = about.trim();
|
||||
|
||||
@ -216,13 +217,13 @@ const ManageGroup: FC<OwnProps & StateProps> = ({
|
||||
about: trimmedAbout,
|
||||
photo,
|
||||
});
|
||||
}, [about, chatId, photo, title, updateChat]);
|
||||
});
|
||||
|
||||
const handleClickMembers = useCallback(() => {
|
||||
const handleClickMembers = useLastCallback(() => {
|
||||
onScreenSelect(ManagementScreens.GroupMembers);
|
||||
}, [onScreenSelect]);
|
||||
});
|
||||
|
||||
const handleTogglePreHistory = useCallback(() => {
|
||||
const handleTogglePreHistory = useLastCallback(() => {
|
||||
if (!chatFullInfo) {
|
||||
return;
|
||||
}
|
||||
@ -230,9 +231,9 @@ const ManageGroup: FC<OwnProps & StateProps> = ({
|
||||
const { isPreHistoryHidden } = chatFullInfo;
|
||||
|
||||
togglePreHistoryHidden({ chatId: chat.id, isEnabled: !isPreHistoryHidden });
|
||||
}, [chat.id, chatFullInfo]);
|
||||
});
|
||||
|
||||
const handleForumToggle = useCallback(() => {
|
||||
const handleForumToggle = useLastCallback(() => {
|
||||
setIsForumEnabled((current) => {
|
||||
const newIsForumEnabled = !current;
|
||||
|
||||
@ -242,7 +243,7 @@ const ManageGroup: FC<OwnProps & StateProps> = ({
|
||||
|
||||
return newIsForumEnabled;
|
||||
});
|
||||
}, [chatId, toggleForum]);
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!isChannelsPremiumLimitReached) {
|
||||
@ -298,7 +299,7 @@ const ManageGroup: FC<OwnProps & StateProps> = ({
|
||||
return Object.keys(chatFullInfo?.adminMembersById || {}).length;
|
||||
}, [chatFullInfo?.adminMembersById]);
|
||||
|
||||
const handleDeleteGroup = useCallback(() => {
|
||||
const handleDeleteGroup = useLastCallback(() => {
|
||||
if (isBasicGroup) {
|
||||
deleteChat({ chatId: chat.id });
|
||||
} else if (!chat.isCreator) {
|
||||
@ -309,10 +310,7 @@ const ManageGroup: FC<OwnProps & StateProps> = ({
|
||||
closeDeleteDialog();
|
||||
closeManagement();
|
||||
openChat({ id: undefined });
|
||||
}, [
|
||||
isBasicGroup, chat.isCreator, chat.id,
|
||||
closeDeleteDialog, closeManagement, leaveChannel, deleteChannel, deleteChat, openChat,
|
||||
]);
|
||||
});
|
||||
|
||||
if (chat.isRestricted || chat.isForbidden) {
|
||||
return undefined;
|
||||
@ -497,6 +495,9 @@ export default memo(withGlobal<OwnProps>(
|
||||
const isBasicGroup = isChatBasicGroup(chat);
|
||||
const { invites } = management.byChatId[chatId] || {};
|
||||
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 {
|
||||
chat,
|
||||
@ -504,13 +505,16 @@ export default memo(withGlobal<OwnProps>(
|
||||
progress,
|
||||
isBasicGroup,
|
||||
hasLinkedChannel,
|
||||
canChangeInfo: chat.isCreator || getHasAdminRight(chat, 'changeInfo'),
|
||||
canBanUsers: chat.isCreator || getHasAdminRight(chat, 'banUsers'),
|
||||
canInvite: chat.isCreator || getHasAdminRight(chat, 'inviteUsers'),
|
||||
canChangeInfo,
|
||||
canBanUsers,
|
||||
canInvite,
|
||||
exportedInvites: invites,
|
||||
isChannelsPremiumLimitReached: limitReachedModal?.limit === 'channels',
|
||||
availableReactions: global.reactions.availableReactions,
|
||||
canEditForum,
|
||||
};
|
||||
},
|
||||
(global, { chatId }) => {
|
||||
return Boolean(selectChat(global, chatId));
|
||||
},
|
||||
)(ManageGroup));
|
||||
|
||||
@ -443,4 +443,7 @@ export default memo(withGlobal<OwnProps>(
|
||||
adminMembersById: fullInfo?.adminMembersById,
|
||||
};
|
||||
},
|
||||
(global, { chatId }) => {
|
||||
return Boolean(selectChat(global, chatId));
|
||||
},
|
||||
)(ManageGroupAdminRights));
|
||||
|
||||
@ -378,4 +378,7 @@ export default memo(withGlobal<OwnProps>(
|
||||
members: fullInfo?.members,
|
||||
};
|
||||
},
|
||||
(global, { chatId }) => {
|
||||
return Boolean(selectChat(global, chatId));
|
||||
},
|
||||
)(ManageGroupUserPermissions));
|
||||
|
||||
@ -267,7 +267,7 @@ const ManageInvite: FC<OwnProps & StateProps> = ({
|
||||
|
||||
export default memo(withGlobal<OwnProps>(
|
||||
(global, { chatId }): StateProps => {
|
||||
const { editingInvite } = selectTabState(global).management.byChatId[chatId];
|
||||
const { editingInvite } = selectTabState(global).management.byChatId[chatId] || {};
|
||||
|
||||
return {
|
||||
editingInvite,
|
||||
|
||||
@ -186,7 +186,7 @@ const ManageInviteInfo: FC<OwnProps & StateProps> = ({
|
||||
|
||||
export default memo(withGlobal<OwnProps>(
|
||||
(global, { chatId }): StateProps => {
|
||||
const { inviteInfo } = selectTabState(global).management.byChatId[chatId];
|
||||
const { inviteInfo } = selectTabState(global).management.byChatId[chatId] || {};
|
||||
const { invite, importers, requesters } = inviteInfo || {};
|
||||
const chat = selectChat(global, chatId);
|
||||
const isChannel = chat && isChatChannel(chat);
|
||||
|
||||
@ -377,7 +377,7 @@ const ManageInvites: FC<OwnProps & StateProps> = ({
|
||||
|
||||
export default memo(withGlobal<OwnProps>(
|
||||
(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 isChannel = chat && isChatChannel(chat);
|
||||
|
||||
|
||||
@ -188,4 +188,7 @@ export default memo(withGlobal<OwnProps>(
|
||||
chat,
|
||||
};
|
||||
},
|
||||
(global, { chatId }) => {
|
||||
return Boolean(selectChat(global, chatId));
|
||||
},
|
||||
)(ManageReactions));
|
||||
|
||||
@ -16,7 +16,7 @@ import { getCurrentTabId } from '../../../util/establishMultitabRole';
|
||||
import { buildCollectionByKey } from '../../../util/iteratees';
|
||||
import { unsubscribe } from '../../../util/notifications';
|
||||
import { clearEncryptedSession, encryptSession, forgetPasscode } from '../../../util/passcode';
|
||||
import { parseInitialLocationHash, resetInitialLocationHash } from '../../../util/routing';
|
||||
import { parseInitialLocationHash, resetInitialLocationHash, resetLocationHash } from '../../../util/routing';
|
||||
import {
|
||||
clearLegacySessions,
|
||||
clearStoredSession,
|
||||
@ -171,6 +171,7 @@ addActionHandler('signOut', async (global, actions, payload): Promise<void> => {
|
||||
|
||||
try {
|
||||
resetInitialLocationHash();
|
||||
resetLocationHash();
|
||||
await unsubscribe();
|
||||
await callApi('destroy');
|
||||
await forceWebsync(false);
|
||||
|
||||
@ -21,6 +21,10 @@ export function resetInitialLocationHash() {
|
||||
parsedInitialLocationHash = undefined;
|
||||
}
|
||||
|
||||
export function resetLocationHash() {
|
||||
window.location.hash = '';
|
||||
}
|
||||
|
||||
export const createLocationHash = (chatId: string, type: MessageListType, threadId: ThreadId): string => {
|
||||
const displayType = type === 'thread' ? undefined : type;
|
||||
const parts = threadId === MAIN_THREAD_ID ? [chatId, displayType] : [chatId, threadId, displayType];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user