import { useDialog } from "@/contexts/DialogProvider"; import EditDialog from "@/entrypoints/sidepanel/components/EditDialog"; import CollectionContext, { CollectionContextType } from "@/entrypoints/sidepanel/contexts/CollectionContext"; import { useCollections } from "@/entrypoints/sidepanel/contexts/CollectionsProvider"; import GroupContext, { GroupContextType } from "@/entrypoints/sidepanel/contexts/GroupContext"; import { useDangerStyles } from "@/hooks/useDangerStyles"; import useSettings from "@/hooks/useSettings"; import { TabItem } from "@/models/CollectionModels"; import { sendMessage } from "@/utils/messaging"; import { Button, Menu, MenuItem, MenuList, MenuPopover, MenuTrigger, Tooltip } from "@fluentui/react-components"; import * as ic from "@fluentui/react-icons"; import { ReactElement } from "react"; import { openGroup } from "../../utils/opener"; import { getTabsToSaveAsync } from "@/utils/getTabsToSaveAsync"; import sendPartialSaveNotification from "@/utils/sendPartialSaveNotification"; export default function GroupMoreMenu(): ReactElement { const [listLocation] = useSettings("listLocation"); const isTabView: boolean = listLocation === "tab" || listLocation === "pinned"; const { group, indices } = useContext(GroupContext); const { hasPinnedGroup, collection } = useContext(CollectionContext); const [deletePrompt] = useSettings("deletePrompt"); const dialog = useDialog(); const { updateGroup, removeItem, ungroup } = useCollections(); const dangerCls = useDangerStyles(); const AddIcon = ic.bundleIcon(ic.Add20Filled, ic.Add20Regular); const UngroupIcon = ic.bundleIcon(ic.FullScreenMaximize20Filled, ic.FullScreenMaximize20Regular); const EditIcon = ic.bundleIcon(ic.Edit20Filled, ic.Edit20Regular); const NewWindowIcon = ic.bundleIcon(ic.WindowNew20Filled, ic.WindowNew20Regular); const DeleteIcon = ic.bundleIcon(ic.Delete20Filled, ic.Delete20Regular); const handleDelete = () => { const removeIndex: number[] = [collection.timestamp, ...indices.slice(1)]; if (deletePrompt) dialog.pushPrompt({ title: i18n.t("groups.menu.delete"), content: i18n.t("common.delete_prompt"), confirmText: i18n.t("common.actions.delete"), destructive: true, onConfirm: () => removeItem(...removeIndex) }); else removeItem(...removeIndex); }; const handleEdit = () => dialog.pushCustom( updateGroup(item, collection.timestamp, indices[1]) } /> ); const openGroupInNewWindow = () => { if (import.meta.env.FIREFOX && listLocation === "popup") sendMessage("openGroup", { group, newWindow: true }); else openGroup(group, true); }; const handleAddSelected = async () => { const [newTabs, skipCount] = await getTabsToSaveAsync(); if (newTabs.length > 0) await updateGroup({ ...group, items: [...group.items, ...newTabs.map(i => ({ type: "tab", url: i.url!, title: i.title }))] }, collection.timestamp, indices[1]); if (skipCount > 0) await sendPartialSaveNotification(); }; return ( ); }