From 4fe0aeb4468095c9848a0020ce103b057cb3cab1 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 21 Dec 2021 12:17:04 +0300 Subject: [PATCH] Fix duplicated folders; Hide redundant "Add to folder" item (#1596) --- src/components/left/ChatFolderModal.tsx | 4 ++-- src/components/left/main/Chat.tsx | 4 ++++ src/hooks/useChatContextActions.ts | 12 ++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/components/left/ChatFolderModal.tsx b/src/components/left/ChatFolderModal.tsx index 0fa7b9fc9..ff9d43670 100644 --- a/src/components/left/ChatFolderModal.tsx +++ b/src/components/left/ChatFolderModal.tsx @@ -63,8 +63,8 @@ const ChatFolderModal: FC = ({ }, [folderOrderedIds, foldersById]); const handleSubmit = useCallback(() => { - const idsToRemove = initialSelectedFolderIds.filter((id) => !selectedFolderIds.includes(id)); - const idsToAdd = selectedFolderIds.filter((id) => !initialSelectedFolderIds.includes(id)); + const idsToRemove = initialSelectedFolderIds.filter((id) => !selectedFolderIds.includes(id)).map(Number); + const idsToAdd = selectedFolderIds.filter((id) => !initialSelectedFolderIds.includes(id)).map(Number); editChatFolders({ chatId, idsToRemove, idsToAdd }); onClose(); diff --git a/src/components/left/main/Chat.tsx b/src/components/left/main/Chat.tsx index 242fda2fa..73130157d 100644 --- a/src/components/left/main/Chat.tsx +++ b/src/components/left/main/Chat.tsx @@ -79,6 +79,7 @@ type StateProps = { animationLevel?: number; isSelected?: boolean; canScrollDown?: boolean; + canChangeFolder?: boolean; lastSyncTime?: number; }; @@ -107,6 +108,7 @@ const Chat: FC = ({ animationLevel, isSelected, canScrollDown, + canChangeFolder, lastSyncTime, openChat, focusLastMessage, @@ -204,6 +206,7 @@ const Chat: FC = ({ folderId, isPinned, isMuted, + canChangeFolder, }); const lang = useLang(); @@ -377,6 +380,7 @@ export default memo(withGlobal( animationLevel: global.settings.byKey.animationLevel, isSelected, canScrollDown: isSelected && messageListType === 'thread', + canChangeFolder: Boolean(global.chatFolders.orderedIds), lastSyncTime: global.lastSyncTime, ...(isOutgoing && { lastMessageOutgoingStatus: selectOutgoingStatus(global, chat.lastMessage) }), ...(privateChatUserId && { diff --git a/src/hooks/useChatContextActions.ts b/src/hooks/useChatContextActions.ts index d1b33aa47..23ef3e26a 100644 --- a/src/hooks/useChatContextActions.ts +++ b/src/hooks/useChatContextActions.ts @@ -17,6 +17,7 @@ export default ({ folderId, isPinned, isMuted, + canChangeFolder, }: { chat: ApiChat | undefined; user: ApiUser | undefined; @@ -25,6 +26,7 @@ export default ({ folderId?: number; isPinned?: boolean; isMuted?: boolean; + canChangeFolder?: boolean; }, isInSearch = false) => { const lang = useLang(); @@ -42,11 +44,11 @@ export default ({ toggleChatUnread, } = getDispatch(); - const actionAddToFolder = { + const actionAddToFolder = canChangeFolder ? { title: lang('ChatList.Filter.AddToFolder'), icon: 'folder', handler: handleChatFolderChange, - }; + } : undefined; const actionPin = isPinned ? { @@ -57,7 +59,7 @@ export default ({ : { title: lang('PinToTop'), icon: 'pin', handler: () => toggleChatPinned({ id: chat.id, folderId }) }; if (isInSearch) { - return [actionPin, actionAddToFolder]; + return compact([actionPin, actionAddToFolder]); } const actionUnreadMark = chat.unreadCount || chat.hasUnreadMark @@ -101,5 +103,7 @@ export default ({ !isSelf && !isInFolder && actionArchive, actionDelete, ]); - }, [chat, lang, handleChatFolderChange, isPinned, isInSearch, isMuted, handleDelete, folderId, isSelf]); + }, [ + chat, canChangeFolder, lang, handleChatFolderChange, isPinned, isInSearch, isMuted, handleDelete, folderId, isSelf, + ]); };