Fix duplicated folders; Hide redundant "Add to folder" item (#1596)

This commit is contained in:
Alexander Zinchuk 2021-12-21 12:17:04 +03:00
parent 8ca0f72060
commit 4fe0aeb446
3 changed files with 14 additions and 6 deletions

View File

@ -63,8 +63,8 @@ const ChatFolderModal: FC<OwnProps & StateProps & DispatchProps> = ({
}, [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();

View File

@ -79,6 +79,7 @@ type StateProps = {
animationLevel?: number;
isSelected?: boolean;
canScrollDown?: boolean;
canChangeFolder?: boolean;
lastSyncTime?: number;
};
@ -107,6 +108,7 @@ const Chat: FC<OwnProps & StateProps & DispatchProps> = ({
animationLevel,
isSelected,
canScrollDown,
canChangeFolder,
lastSyncTime,
openChat,
focusLastMessage,
@ -204,6 +206,7 @@ const Chat: FC<OwnProps & StateProps & DispatchProps> = ({
folderId,
isPinned,
isMuted,
canChangeFolder,
});
const lang = useLang();
@ -377,6 +380,7 @@ export default memo(withGlobal<OwnProps>(
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 && {

View File

@ -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,
]);
};