import classNames from "classnames"; import copy from "copy-to-clipboard"; import { useState } from "react"; import toast from "react-hot-toast"; import { useTranslation } from "react-i18next"; import { Link } from "react-router-dom"; import { absolutifyLink } from "@/helpers/utils"; import useNavigateTo from "@/hooks/useNavigateTo"; import useResponsiveWidth from "@/hooks/useResponsiveWidth"; import useCollectionStore from "@/stores/v1/collection"; import useShortcutStore from "@/stores/v1/shortcut"; import useUserStore from "@/stores/v1/user"; import { Collection } from "@/types/proto/api/v2/collection_service"; import { Shortcut } from "@/types/proto/api/v2/shortcut_service"; import { showCommonDialog } from "./Alert"; import CreateCollectionDialog from "./CreateCollectionDrawer"; import Icon from "./Icon"; import ShortcutView from "./ShortcutView"; import Dropdown from "./common/Dropdown"; interface Props { collection: Collection; } const CollectionView = (props: Props) => { const { collection } = props; const { t } = useTranslation(); const { sm } = useResponsiveWidth(); const navigateTo = useNavigateTo(); const currentUser = useUserStore().getCurrentUser(); const collectionStore = useCollectionStore(); const shortcutList = useShortcutStore().getShortcutList(); const [showEditDialog, setShowEditDialog] = useState(false); const shortcuts = collection.shortcutIds .map((shortcutId) => shortcutList.find((shortcut) => shortcut?.id === shortcutId)) .filter(Boolean) as any as Shortcut[]; const showAdminActions = currentUser.id === collection.creatorId; const handleCopyCollectionLink = () => { copy(absolutifyLink(`/c/${collection.name}`)); toast.success("Collection link copied to clipboard."); }; 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} (c/{collection.name})

{collection.description}

{showAdminActions && ( } actionsClassName="!w-28 dark:text-gray-500" actions={ <> } > )}
{shortcuts.map((shortcut) => { return ( handleShortcutClick(shortcut)} /> ); })}
{showEditDialog && ( setShowEditDialog(false)} onConfirm={() => setShowEditDialog(false)} /> )} ); }; export default CollectionView;