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]); }, [folderOrderedIds, foldersById]);
const handleSubmit = useCallback(() => { const handleSubmit = useCallback(() => {
const idsToRemove = initialSelectedFolderIds.filter((id) => !selectedFolderIds.includes(id)); const idsToRemove = initialSelectedFolderIds.filter((id) => !selectedFolderIds.includes(id)).map(Number);
const idsToAdd = selectedFolderIds.filter((id) => !initialSelectedFolderIds.includes(id)); const idsToAdd = selectedFolderIds.filter((id) => !initialSelectedFolderIds.includes(id)).map(Number);
editChatFolders({ chatId, idsToRemove, idsToAdd }); editChatFolders({ chatId, idsToRemove, idsToAdd });
onClose(); onClose();

View File

@ -79,6 +79,7 @@ type StateProps = {
animationLevel?: number; animationLevel?: number;
isSelected?: boolean; isSelected?: boolean;
canScrollDown?: boolean; canScrollDown?: boolean;
canChangeFolder?: boolean;
lastSyncTime?: number; lastSyncTime?: number;
}; };
@ -107,6 +108,7 @@ const Chat: FC<OwnProps & StateProps & DispatchProps> = ({
animationLevel, animationLevel,
isSelected, isSelected,
canScrollDown, canScrollDown,
canChangeFolder,
lastSyncTime, lastSyncTime,
openChat, openChat,
focusLastMessage, focusLastMessage,
@ -204,6 +206,7 @@ const Chat: FC<OwnProps & StateProps & DispatchProps> = ({
folderId, folderId,
isPinned, isPinned,
isMuted, isMuted,
canChangeFolder,
}); });
const lang = useLang(); const lang = useLang();
@ -377,6 +380,7 @@ export default memo(withGlobal<OwnProps>(
animationLevel: global.settings.byKey.animationLevel, animationLevel: global.settings.byKey.animationLevel,
isSelected, isSelected,
canScrollDown: isSelected && messageListType === 'thread', canScrollDown: isSelected && messageListType === 'thread',
canChangeFolder: Boolean(global.chatFolders.orderedIds),
lastSyncTime: global.lastSyncTime, lastSyncTime: global.lastSyncTime,
...(isOutgoing && { lastMessageOutgoingStatus: selectOutgoingStatus(global, chat.lastMessage) }), ...(isOutgoing && { lastMessageOutgoingStatus: selectOutgoingStatus(global, chat.lastMessage) }),
...(privateChatUserId && { ...(privateChatUserId && {

View File

@ -17,6 +17,7 @@ export default ({
folderId, folderId,
isPinned, isPinned,
isMuted, isMuted,
canChangeFolder,
}: { }: {
chat: ApiChat | undefined; chat: ApiChat | undefined;
user: ApiUser | undefined; user: ApiUser | undefined;
@ -25,6 +26,7 @@ export default ({
folderId?: number; folderId?: number;
isPinned?: boolean; isPinned?: boolean;
isMuted?: boolean; isMuted?: boolean;
canChangeFolder?: boolean;
}, isInSearch = false) => { }, isInSearch = false) => {
const lang = useLang(); const lang = useLang();
@ -42,11 +44,11 @@ export default ({
toggleChatUnread, toggleChatUnread,
} = getDispatch(); } = getDispatch();
const actionAddToFolder = { const actionAddToFolder = canChangeFolder ? {
title: lang('ChatList.Filter.AddToFolder'), title: lang('ChatList.Filter.AddToFolder'),
icon: 'folder', icon: 'folder',
handler: handleChatFolderChange, handler: handleChatFolderChange,
}; } : undefined;
const actionPin = isPinned const actionPin = isPinned
? { ? {
@ -57,7 +59,7 @@ export default ({
: { title: lang('PinToTop'), icon: 'pin', handler: () => toggleChatPinned({ id: chat.id, folderId }) }; : { title: lang('PinToTop'), icon: 'pin', handler: () => toggleChatPinned({ id: chat.id, folderId }) };
if (isInSearch) { if (isInSearch) {
return [actionPin, actionAddToFolder]; return compact([actionPin, actionAddToFolder]);
} }
const actionUnreadMark = chat.unreadCount || chat.hasUnreadMark const actionUnreadMark = chat.unreadCount || chat.hasUnreadMark
@ -101,5 +103,7 @@ export default ({
!isSelf && !isInFolder && actionArchive, !isSelf && !isInFolder && actionArchive,
actionDelete, actionDelete,
]); ]);
}, [chat, lang, handleChatFolderChange, isPinned, isInSearch, isMuted, handleDelete, folderId, isSelf]); }, [
chat, canChangeFolder, lang, handleChatFolderChange, isPinned, isInSearch, isMuted, handleDelete, folderId, isSelf,
]);
}; };