mirror of
https://github.com/XFox111/TabsAsideExtension.git
synced 2026-04-22 07:58:01 +03:00
fix: when listLocation is "tab" or "pinned" add all tabs instead of selected #117
This commit is contained in:
@@ -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<CollectionContextType>(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 ?
|
||||
<Button icon={ <AddIcon /> } appearance="subtle" onClick={ handleAddSelected }>
|
||||
{ i18n.t("collections.menu.add_selected") }
|
||||
{ isTab ? i18n.t("collections.menu.add_all") : i18n.t("collections.menu.add_selected") }
|
||||
</Button>
|
||||
:
|
||||
<OpenCollectionButton />
|
||||
|
||||
@@ -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<CollectionContextType>(CollectionContext);
|
||||
const dialog = useDialog();
|
||||
@@ -65,7 +67,7 @@ export default function CollectionMoreButton({ onAddSelected }: CollectionMoreBu
|
||||
<MenuList>
|
||||
{ tabCount > 0 &&
|
||||
<MenuItem icon={ <AddIcon /> } onClick={ () => onAddSelected?.() }>
|
||||
{ i18n.t("collections.menu.add_selected") }
|
||||
{ isTab ? i18n.t("collections.menu.add_all") : i18n.t("collections.menu.add_selected") }
|
||||
</MenuItem>
|
||||
}
|
||||
<MenuItem icon={ <GroupIcon /> } onClick={ handleCreateGroup }>
|
||||
|
||||
@@ -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<GroupContextType>(GroupContext);
|
||||
const { hasPinnedGroup } = useContext<CollectionContextType>(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
|
||||
}
|
||||
|
||||
<MenuItem icon={ <AddIcon /> } onClick={ handleAddSelected }>
|
||||
{ i18n.t("groups.menu.add_selected") }
|
||||
{ isTab ? i18n.t("groups.menu.add_all") : i18n.t("groups.menu.add_selected") }
|
||||
</MenuItem>
|
||||
|
||||
<MenuItem icon={ <EditIcon /> } onClick={ handleEdit }>
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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: "Удалить группу"
|
||||
|
||||
@@ -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: "Видалити групу"
|
||||
|
||||
Reference in New Issue
Block a user