import classNames from "classnames"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { Link } from "react-router-dom"; import useNavigateTo from "@/hooks/useNavigateTo"; import { useAppSelector } from "@/stores"; import useCollectionStore from "@/stores/v1/collection"; import { Collection } from "@/types/proto/api/v2/collection_service"; import { Visibility } from "@/types/proto/api/v2/common"; import { showCommonDialog } from "./Alert"; import CreateCollectionDialog, { ShortcutItem } from "./CreateCollectionDialog"; import Icon from "./Icon"; import Dropdown from "./common/Dropdown"; interface Props { collection: Collection; } const CollectionView = (props: Props) => { const { collection } = props; const { t } = useTranslation(); const navigateTo = useNavigateTo(); const collectionStore = useCollectionStore(); const { shortcutList } = useAppSelector((state) => state.shortcut); const [showEditDialog, setShowEditDialog] = useState(false); const shortcuts = collection.shortcutIds .map((shortcutId) => shortcutList.find((shortcut) => shortcut?.id === shortcutId)) .filter(Boolean) as any as Shortcut[]; const handleDeleteCollectionButtonClick = () => { showCommonDialog({ title: "Delete Collection", content: `Are you sure to delete collection \`${collection.name}\`? You cannot undo this action.`, style: "danger", onConfirm: async () => { await collectionStore.deleteCollection(collection.id); }, }); }; const handleShortcutClick = (shortcut: Shortcut) => { navigateTo(`/shortcut/${shortcut.id}`); }; return ( <>
{collection.title}
{collection.visibility !== Visibility.PRIVATE && ( )} } >
{shortcuts.map((shortcut) => { return handleShortcutClick(shortcut)} />; })}
{showEditDialog && ( setShowEditDialog(false)} onConfirm={() => setShowEditDialog(false)} /> )} ); }; export default CollectionView;