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 { getCollectionTitle } from "@/entrypoints/sidepanel/utils/getCollectionTitle";
|
||||||
import getSelectedTabs from "@/entrypoints/sidepanel/utils/getSelectedTabs";
|
import getSelectedTabs from "@/entrypoints/sidepanel/utils/getSelectedTabs";
|
||||||
import useSettings from "@/hooks/useSettings";
|
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 { Button, Caption1, makeStyles, mergeClasses, Subtitle2, tokens, Tooltip } from "@fluentui/react-components";
|
||||||
import { Add20Filled, Add20Regular, bundleIcon } from "@fluentui/react-icons";
|
import { Add20Filled, Add20Regular, bundleIcon } from "@fluentui/react-icons";
|
||||||
import CollectionContext, { CollectionContextType } from "../../contexts/CollectionContext";
|
import CollectionContext, { CollectionContextType } from "../../contexts/CollectionContext";
|
||||||
import { useCollections } from "../../contexts/CollectionsProvider";
|
import { useCollections } from "../../contexts/CollectionsProvider";
|
||||||
import CollectionMoreButton from "./CollectionMoreButton";
|
import CollectionMoreButton from "./CollectionMoreButton";
|
||||||
import OpenCollectionButton from "./OpenCollectionButton";
|
import OpenCollectionButton from "./OpenCollectionButton";
|
||||||
|
import saveTabsToCollection from "@/utils/saveTabsToCollection";
|
||||||
|
|
||||||
export default function CollectionHeader({ dragHandleRef, dragHandleProps }: CollectionHeaderProps): React.ReactElement
|
export default function CollectionHeader({ dragHandleRef, dragHandleProps }: CollectionHeaderProps): React.ReactElement
|
||||||
{
|
{
|
||||||
|
const [listLocation] = useSettings("listLocation");
|
||||||
|
const isTab: boolean = listLocation === "tab" || listLocation === "pinned";
|
||||||
const { updateCollection } = useCollections();
|
const { updateCollection } = useCollections();
|
||||||
const { tabCount, collection, collectionIndex } = useContext<CollectionContextType>(CollectionContext);
|
const { tabCount, collection, collectionIndex } = useContext<CollectionContextType>(CollectionContext);
|
||||||
const [alwaysShowToolbars] = useSettings("alwaysShowToolbars");
|
const [alwaysShowToolbars] = useSettings("alwaysShowToolbars");
|
||||||
@@ -19,7 +22,9 @@ export default function CollectionHeader({ dragHandleRef, dragHandleProps }: Col
|
|||||||
|
|
||||||
const handleAddSelected = async () =>
|
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);
|
updateCollection({ ...collection, items: [...collection.items, ...newTabs] }, collectionIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -53,7 +58,7 @@ export default function CollectionHeader({ dragHandleRef, dragHandleProps }: Col
|
|||||||
>
|
>
|
||||||
{ tabCount < 1 ?
|
{ tabCount < 1 ?
|
||||||
<Button icon={ <AddIcon /> } appearance="subtle" onClick={ handleAddSelected }>
|
<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>
|
</Button>
|
||||||
:
|
:
|
||||||
<OpenCollectionButton />
|
<OpenCollectionButton />
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import EditDialog from "../EditDialog";
|
|||||||
|
|
||||||
export default function CollectionMoreButton({ onAddSelected }: CollectionMoreButtonProps): React.ReactElement
|
export default function CollectionMoreButton({ onAddSelected }: CollectionMoreButtonProps): React.ReactElement
|
||||||
{
|
{
|
||||||
|
const [listLocation] = useSettings("listLocation");
|
||||||
|
const isTab: boolean = listLocation === "tab" || listLocation === "pinned";
|
||||||
const { removeItem, updateCollection } = useCollections();
|
const { removeItem, updateCollection } = useCollections();
|
||||||
const { tabCount, hasPinnedGroup, collection, collectionIndex } = useContext<CollectionContextType>(CollectionContext);
|
const { tabCount, hasPinnedGroup, collection, collectionIndex } = useContext<CollectionContextType>(CollectionContext);
|
||||||
const dialog = useDialog();
|
const dialog = useDialog();
|
||||||
@@ -65,7 +67,7 @@ export default function CollectionMoreButton({ onAddSelected }: CollectionMoreBu
|
|||||||
<MenuList>
|
<MenuList>
|
||||||
{ tabCount > 0 &&
|
{ tabCount > 0 &&
|
||||||
<MenuItem icon={ <AddIcon /> } onClick={ () => onAddSelected?.() }>
|
<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>
|
||||||
}
|
}
|
||||||
<MenuItem icon={ <GroupIcon /> } onClick={ handleCreateGroup }>
|
<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 * as ic from "@fluentui/react-icons";
|
||||||
import { ReactElement } from "react";
|
import { ReactElement } from "react";
|
||||||
import { openGroup } from "../../utils/opener";
|
import { openGroup } from "../../utils/opener";
|
||||||
|
import saveTabsToCollection from "@/utils/saveTabsToCollection";
|
||||||
|
|
||||||
export default function GroupMoreMenu(): ReactElement
|
export default function GroupMoreMenu(): ReactElement
|
||||||
{
|
{
|
||||||
|
const [listLocation] = useSettings("listLocation");
|
||||||
|
const isTab: boolean = listLocation === "tab" || listLocation === "pinned";
|
||||||
const { group, indices } = useContext<GroupContextType>(GroupContext);
|
const { group, indices } = useContext<GroupContextType>(GroupContext);
|
||||||
const { hasPinnedGroup } = useContext<CollectionContextType>(CollectionContext);
|
const { hasPinnedGroup } = useContext<CollectionContextType>(CollectionContext);
|
||||||
const [deletePrompt] = useSettings("deletePrompt");
|
const [deletePrompt] = useSettings("deletePrompt");
|
||||||
@@ -53,7 +56,9 @@ export default function GroupMoreMenu(): ReactElement
|
|||||||
|
|
||||||
const handleAddSelected = async () =>
|
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]);
|
updateGroup({ ...group, items: [...group.items, ...newTabs] }, indices[0], indices[1]);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -74,7 +79,7 @@ export default function GroupMoreMenu(): ReactElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
<MenuItem icon={ <AddIcon /> } onClick={ handleAddSelected }>
|
<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>
|
||||||
|
|
||||||
<MenuItem icon={ <EditIcon /> } onClick={ handleEdit }>
|
<MenuItem icon={ <EditIcon /> } onClick={ handleEdit }>
|
||||||
|
|||||||
@@ -161,6 +161,7 @@ collections:
|
|||||||
menu:
|
menu:
|
||||||
delete: "Delete collection"
|
delete: "Delete collection"
|
||||||
add_selected: "Add selected tabs"
|
add_selected: "Add selected tabs"
|
||||||
|
add_all: "Add selected tabs"
|
||||||
add_group: "Add empty group"
|
add_group: "Add empty group"
|
||||||
export_bookmarks: "Export to bookmarks"
|
export_bookmarks: "Export to bookmarks"
|
||||||
edit: "Edit collection"
|
edit: "Edit collection"
|
||||||
@@ -173,6 +174,7 @@ groups:
|
|||||||
menu:
|
menu:
|
||||||
new_window: "Open in new window"
|
new_window: "Open in new window"
|
||||||
add_selected: "Add selected tabs"
|
add_selected: "Add selected tabs"
|
||||||
|
add_all: "Add selected tabs"
|
||||||
edit: "Edit group"
|
edit: "Edit group"
|
||||||
ungroup: "Ungroup"
|
ungroup: "Ungroup"
|
||||||
delete: "Delete group"
|
delete: "Delete group"
|
||||||
|
|||||||
@@ -161,6 +161,7 @@ collections:
|
|||||||
menu:
|
menu:
|
||||||
delete: "Excluir coleção"
|
delete: "Excluir coleção"
|
||||||
add_selected: "Adicionar abas selecionadas"
|
add_selected: "Adicionar abas selecionadas"
|
||||||
|
add_all: "Adicionar todas as abas"
|
||||||
add_group: "Adicionar grupo vazio"
|
add_group: "Adicionar grupo vazio"
|
||||||
export_bookmarks: "Exportar para favoritos"
|
export_bookmarks: "Exportar para favoritos"
|
||||||
edit: "Editar coleção"
|
edit: "Editar coleção"
|
||||||
@@ -173,6 +174,7 @@ groups:
|
|||||||
menu:
|
menu:
|
||||||
new_window: "Abrir em nova janela"
|
new_window: "Abrir em nova janela"
|
||||||
add_selected: "Adicionar abas selecionadas"
|
add_selected: "Adicionar abas selecionadas"
|
||||||
|
add_all: "Adicionar todas as abas"
|
||||||
edit: "Editar grupo"
|
edit: "Editar grupo"
|
||||||
ungroup: "Desagrupar"
|
ungroup: "Desagrupar"
|
||||||
delete: "Excluir grupo"
|
delete: "Excluir grupo"
|
||||||
|
|||||||
@@ -161,6 +161,7 @@ collections:
|
|||||||
menu:
|
menu:
|
||||||
delete: "Удалить коллекцию"
|
delete: "Удалить коллекцию"
|
||||||
add_selected: "Добавить выбранные вкладки"
|
add_selected: "Добавить выбранные вкладки"
|
||||||
|
add_all: "Добавить все вкладки"
|
||||||
add_group: "Добавить пустую группу"
|
add_group: "Добавить пустую группу"
|
||||||
export_bookmarks: "Экспортировать в закладки"
|
export_bookmarks: "Экспортировать в закладки"
|
||||||
edit: "Редактировать коллекцию"
|
edit: "Редактировать коллекцию"
|
||||||
@@ -173,6 +174,7 @@ groups:
|
|||||||
menu:
|
menu:
|
||||||
new_window: "Открыть в новом окне"
|
new_window: "Открыть в новом окне"
|
||||||
add_selected: "Добавить выбранные вкладки"
|
add_selected: "Добавить выбранные вкладки"
|
||||||
|
add_all: "Добавить все вкладки"
|
||||||
edit: "Редактировать группу"
|
edit: "Редактировать группу"
|
||||||
ungroup: "Разгруппировать"
|
ungroup: "Разгруппировать"
|
||||||
delete: "Удалить группу"
|
delete: "Удалить группу"
|
||||||
|
|||||||
@@ -161,6 +161,7 @@ collections:
|
|||||||
menu:
|
menu:
|
||||||
delete: "Видалити колекцію"
|
delete: "Видалити колекцію"
|
||||||
add_selected: "Додати вибрані вкладки"
|
add_selected: "Додати вибрані вкладки"
|
||||||
|
add_all: "Додати всі вкладки"
|
||||||
add_group: "Додати порожню групу"
|
add_group: "Додати порожню групу"
|
||||||
export_bookmarks: "Експортувати в закладки"
|
export_bookmarks: "Експортувати в закладки"
|
||||||
edit: "Редагувати колекцію"
|
edit: "Редагувати колекцію"
|
||||||
@@ -173,6 +174,7 @@ groups:
|
|||||||
menu:
|
menu:
|
||||||
new_window: "Відкрити у новому вікні"
|
new_window: "Відкрити у новому вікні"
|
||||||
add_selected: "Додати вибрані вкладки"
|
add_selected: "Додати вибрані вкладки"
|
||||||
|
add_all: "Додати всі вкладки"
|
||||||
edit: "Редагувати групу"
|
edit: "Редагувати групу"
|
||||||
ungroup: "Розгрупувати"
|
ungroup: "Розгрупувати"
|
||||||
delete: "Видалити групу"
|
delete: "Видалити групу"
|
||||||
|
|||||||
Reference in New Issue
Block a user