From 5bb26ffab838cca6e768440f380e4e3c2645fabd Mon Sep 17 00:00:00 2001 From: Cater <84566931+SuperCater@users.noreply.github.com> Date: Sat, 14 Sep 2024 12:17:48 -0400 Subject: [PATCH] feat(ChannelTabs): Adds close tabs to the left (#38) --- .../channelTabs/components/ContextMenus.tsx | 8 +++++++- src/equicordplugins/channelTabs/util/tabs.tsx | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/equicordplugins/channelTabs/components/ContextMenus.tsx b/src/equicordplugins/channelTabs/components/ContextMenus.tsx index a2642e72..38a74a62 100644 --- a/src/equicordplugins/channelTabs/components/ContextMenus.tsx +++ b/src/equicordplugins/channelTabs/components/ContextMenus.tsx @@ -8,7 +8,7 @@ import { Margins } from "@utils/margins"; import { closeModal, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, openModal } from "@utils/modal"; import { Button, ChannelStore, FluxDispatcher, Forms, i18n, Menu, ReadStateStore, ReadStateUtils, Select, Text, TextInput, useState } from "@webpack/common"; -import { bookmarkFolderColors, bookmarkPlaceholderName, closeOtherTabs, closeTab, closeTabsToTheRight, createTab, hasClosedTabs, isBookmarkFolder, openedTabs, reopenClosedTab, settings, toggleCompactTab } from "../util"; +import { bookmarkFolderColors, bookmarkPlaceholderName, closeOtherTabs, closeTab, closeTabsToTheLeft, closeTabsToTheRight, createTab, hasClosedTabs, isBookmarkFolder, openedTabs, reopenClosedTab, settings, toggleCompactTab } from "../util"; import { Bookmark, BookmarkFolder, Bookmarks, ChannelTabsProps, UseBookmarkMethods } from "../util/types"; export function BasicContextMenu() { @@ -319,6 +319,12 @@ export function TabContextMenu({ tab }: { tab: ChannelTabsProps; }) { disabled={openedTabs.indexOf(tab) === openedTabs.length - 1} action={() => closeTabsToTheRight(tab.id)} /> + closeTabsToTheLeft(tab.id)} + /> v.id === id); + if (i === -1) return logger.error("Couldn't find channel tab with ID " + id, openTabs); + + const tabsToTheLeft = openTabs.filter((_, ind) => ind < i); + closedTabs.push(...tabsToTheLeft.reverse()); + const tabsToTheRight = openTabs.filter((_, ind) => ind >= i); + replaceArray(openTabs, ...tabsToTheRight); + + if (!tabsToTheRight.some(v => v.id === currentlyOpenTab)) moveToTab(openTabs[0].id); + else update(); +} + export function handleChannelSwitch(ch: BasicChannelTabsProps) { const tab = openTabs.find(c => c.id === currentlyOpenTab); if (tab === undefined) return logger.error("Couldn't find the currently open channel " + currentlyOpenTab, openTabs);