From a706c3bc89fbc3fb9c659fa7274c0ee4d911093a Mon Sep 17 00:00:00 2001 From: Eugene Fox Date: Wed, 7 May 2025 00:28:48 +0300 Subject: [PATCH] fix: when listLocation is "tab" or "pinned" add all tabs instead of selected #117 --- .../components/collections/CollectionHeader.tsx | 11 ++++++++--- .../components/collections/CollectionMoreButton.tsx | 4 +++- .../components/collections/GroupMoreMenu.tsx | 9 +++++++-- locales/en.yml | 2 ++ locales/pt_BR.yml | 2 ++ locales/ru.yml | 2 ++ locales/uk.yml | 2 ++ 7 files changed, 26 insertions(+), 6 deletions(-) diff --git a/entrypoints/sidepanel/components/collections/CollectionHeader.tsx b/entrypoints/sidepanel/components/collections/CollectionHeader.tsx index 715ce97..c83249a 100644 --- a/entrypoints/sidepanel/components/collections/CollectionHeader.tsx +++ b/entrypoints/sidepanel/components/collections/CollectionHeader.tsx @@ -1,16 +1,19 @@ import { getCollectionTitle } from "@/entrypoints/sidepanel/utils/getCollectionTitle"; import getSelectedTabs from "@/entrypoints/sidepanel/utils/getSelectedTabs"; import useSettings from "@/hooks/useSettings"; -import { TabItem } from "@/models/CollectionModels"; +import { GroupItem, TabItem } from "@/models/CollectionModels"; import { Button, Caption1, makeStyles, mergeClasses, Subtitle2, tokens, Tooltip } from "@fluentui/react-components"; import { Add20Filled, Add20Regular, bundleIcon } from "@fluentui/react-icons"; import CollectionContext, { CollectionContextType } from "../../contexts/CollectionContext"; import { useCollections } from "../../contexts/CollectionsProvider"; import CollectionMoreButton from "./CollectionMoreButton"; import OpenCollectionButton from "./OpenCollectionButton"; +import saveTabsToCollection from "@/utils/saveTabsToCollection"; export default function CollectionHeader({ dragHandleRef, dragHandleProps }: CollectionHeaderProps): React.ReactElement { + const [listLocation] = useSettings("listLocation"); + const isTab: boolean = listLocation === "tab" || listLocation === "pinned"; const { updateCollection } = useCollections(); const { tabCount, collection, collectionIndex } = useContext(CollectionContext); const [alwaysShowToolbars] = useSettings("alwaysShowToolbars"); @@ -19,7 +22,9 @@ export default function CollectionHeader({ dragHandleRef, dragHandleProps }: Col const handleAddSelected = async () => { - const newTabs: TabItem[] = await getSelectedTabs(); + const newTabs: (TabItem | GroupItem)[] = isTab ? + (await saveTabsToCollection(false)).items : + await getSelectedTabs(); updateCollection({ ...collection, items: [...collection.items, ...newTabs] }, collectionIndex); }; @@ -53,7 +58,7 @@ export default function CollectionHeader({ dragHandleRef, dragHandleProps }: Col > { tabCount < 1 ? : diff --git a/entrypoints/sidepanel/components/collections/CollectionMoreButton.tsx b/entrypoints/sidepanel/components/collections/CollectionMoreButton.tsx index ec35684..f8156a0 100644 --- a/entrypoints/sidepanel/components/collections/CollectionMoreButton.tsx +++ b/entrypoints/sidepanel/components/collections/CollectionMoreButton.tsx @@ -10,6 +10,8 @@ import EditDialog from "../EditDialog"; export default function CollectionMoreButton({ onAddSelected }: CollectionMoreButtonProps): React.ReactElement { + const [listLocation] = useSettings("listLocation"); + const isTab: boolean = listLocation === "tab" || listLocation === "pinned"; const { removeItem, updateCollection } = useCollections(); const { tabCount, hasPinnedGroup, collection, collectionIndex } = useContext(CollectionContext); const dialog = useDialog(); @@ -65,7 +67,7 @@ export default function CollectionMoreButton({ onAddSelected }: CollectionMoreBu { tabCount > 0 && } onClick={ () => onAddSelected?.() }> - { i18n.t("collections.menu.add_selected") } + { isTab ? i18n.t("collections.menu.add_all") : i18n.t("collections.menu.add_selected") } } } onClick={ handleCreateGroup }> diff --git a/entrypoints/sidepanel/components/collections/GroupMoreMenu.tsx b/entrypoints/sidepanel/components/collections/GroupMoreMenu.tsx index abb23f4..3342161 100644 --- a/entrypoints/sidepanel/components/collections/GroupMoreMenu.tsx +++ b/entrypoints/sidepanel/components/collections/GroupMoreMenu.tsx @@ -11,9 +11,12 @@ import { Button, Menu, MenuItem, MenuList, MenuPopover, MenuTrigger, Tooltip } f import * as ic from "@fluentui/react-icons"; import { ReactElement } from "react"; import { openGroup } from "../../utils/opener"; +import saveTabsToCollection from "@/utils/saveTabsToCollection"; export default function GroupMoreMenu(): ReactElement { + const [listLocation] = useSettings("listLocation"); + const isTab: boolean = listLocation === "tab" || listLocation === "pinned"; const { group, indices } = useContext(GroupContext); const { hasPinnedGroup } = useContext(CollectionContext); const [deletePrompt] = useSettings("deletePrompt"); @@ -53,7 +56,9 @@ export default function GroupMoreMenu(): ReactElement const handleAddSelected = async () => { - const newTabs: TabItem[] = await getSelectedTabs(); + const newTabs: TabItem[] = isTab ? + (await saveTabsToCollection(false)).items.flatMap(i => i.type === "tab" ? i : i.items) : + await getSelectedTabs(); updateGroup({ ...group, items: [...group.items, ...newTabs] }, indices[0], indices[1]); }; @@ -74,7 +79,7 @@ export default function GroupMoreMenu(): ReactElement } } onClick={ handleAddSelected }> - { i18n.t("groups.menu.add_selected") } + { isTab ? i18n.t("groups.menu.add_all") : i18n.t("groups.menu.add_selected") } } onClick={ handleEdit }> diff --git a/locales/en.yml b/locales/en.yml index 9f0706f..a720d1a 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -161,6 +161,7 @@ collections: menu: delete: "Delete collection" add_selected: "Add selected tabs" + add_all: "Add selected tabs" add_group: "Add empty group" export_bookmarks: "Export to bookmarks" edit: "Edit collection" @@ -173,6 +174,7 @@ groups: menu: new_window: "Open in new window" add_selected: "Add selected tabs" + add_all: "Add selected tabs" edit: "Edit group" ungroup: "Ungroup" delete: "Delete group" diff --git a/locales/pt_BR.yml b/locales/pt_BR.yml index 2b1b7ae..94eba10 100644 --- a/locales/pt_BR.yml +++ b/locales/pt_BR.yml @@ -161,6 +161,7 @@ collections: menu: delete: "Excluir coleção" add_selected: "Adicionar abas selecionadas" + add_all: "Adicionar todas as abas" add_group: "Adicionar grupo vazio" export_bookmarks: "Exportar para favoritos" edit: "Editar coleção" @@ -173,6 +174,7 @@ groups: menu: new_window: "Abrir em nova janela" add_selected: "Adicionar abas selecionadas" + add_all: "Adicionar todas as abas" edit: "Editar grupo" ungroup: "Desagrupar" delete: "Excluir grupo" diff --git a/locales/ru.yml b/locales/ru.yml index 2c881be..f96d116 100644 --- a/locales/ru.yml +++ b/locales/ru.yml @@ -161,6 +161,7 @@ collections: menu: delete: "Удалить коллекцию" add_selected: "Добавить выбранные вкладки" + add_all: "Добавить все вкладки" add_group: "Добавить пустую группу" export_bookmarks: "Экспортировать в закладки" edit: "Редактировать коллекцию" @@ -173,6 +174,7 @@ groups: menu: new_window: "Открыть в новом окне" add_selected: "Добавить выбранные вкладки" + add_all: "Добавить все вкладки" edit: "Редактировать группу" ungroup: "Разгруппировать" delete: "Удалить группу" diff --git a/locales/uk.yml b/locales/uk.yml index 5471fa3..4aa1a49 100644 --- a/locales/uk.yml +++ b/locales/uk.yml @@ -161,6 +161,7 @@ collections: menu: delete: "Видалити колекцію" add_selected: "Додати вибрані вкладки" + add_all: "Додати всі вкладки" add_group: "Додати порожню групу" export_bookmarks: "Експортувати в закладки" edit: "Редагувати колекцію" @@ -173,6 +174,7 @@ groups: menu: new_window: "Відкрити у новому вікні" add_selected: "Додати вибрані вкладки" + add_all: "Додати всі вкладки" edit: "Редагувати групу" ungroup: "Розгрупувати" delete: "Видалити групу"