2025-01-07 02:29:29 +08:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
import React, { PropsWithChildren } from 'react';
|
2025-01-31 07:29:06 +08:00
|
|
|
import { PopoverProps } from 'antd';
|
2025-02-20 10:53:49 +08:00
|
|
|
import { AppPopover } from '@/components/ui/tooltip/AppPopover';
|
|
|
|
import { AppTooltip } from '@/components/ui/tooltip';
|
2025-01-07 02:29:29 +08:00
|
|
|
import { useMemoizedFn } from 'ahooks';
|
2025-02-07 05:31:46 +08:00
|
|
|
import { BusterShare, ShareAssetType } from '@/api/asset_interfaces';
|
2025-01-31 07:29:06 +08:00
|
|
|
import { ShareMenuContent } from './ShareMenuContent';
|
2025-02-07 05:31:46 +08:00
|
|
|
import { isShareMenuVisible } from './publicHelpers';
|
2025-01-07 02:29:29 +08:00
|
|
|
|
|
|
|
export const ShareMenu: React.FC<
|
|
|
|
PropsWithChildren<{
|
|
|
|
placement?: PopoverProps['placement'];
|
2025-02-07 05:31:46 +08:00
|
|
|
shareAssetConfig: BusterShare | null;
|
2025-01-31 07:29:06 +08:00
|
|
|
assetId: string;
|
2025-02-01 02:04:49 +08:00
|
|
|
assetType: ShareAssetType;
|
2025-01-07 02:29:29 +08:00
|
|
|
}>
|
2025-02-01 06:21:50 +08:00
|
|
|
> = ({ children, shareAssetConfig, assetId, assetType, placement = 'bottomLeft' }) => {
|
2025-01-07 02:29:29 +08:00
|
|
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
|
|
|
|
|
|
const onOpenChange = useMemoizedFn((v: boolean) => {
|
|
|
|
setIsOpen(v);
|
|
|
|
});
|
|
|
|
|
2025-02-07 05:31:46 +08:00
|
|
|
const showShareMenu = shareAssetConfig && isShareMenuVisible(shareAssetConfig);
|
|
|
|
|
2025-01-07 02:29:29 +08:00
|
|
|
if (!showShareMenu) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2025-02-07 05:31:46 +08:00
|
|
|
const permission = shareAssetConfig?.permission;
|
|
|
|
|
2025-01-07 02:29:29 +08:00
|
|
|
return (
|
|
|
|
<AppPopover
|
2025-02-07 05:31:46 +08:00
|
|
|
trigger={['click']}
|
2025-01-07 02:29:29 +08:00
|
|
|
destroyTooltipOnHide
|
|
|
|
placement={placement}
|
|
|
|
onOpenChange={onOpenChange}
|
|
|
|
content={
|
2025-02-07 05:31:46 +08:00
|
|
|
shareAssetConfig ? (
|
|
|
|
<ShareMenuContent
|
|
|
|
shareAssetConfig={shareAssetConfig}
|
|
|
|
assetId={assetId}
|
|
|
|
assetType={assetType}
|
|
|
|
permission={permission}
|
|
|
|
/>
|
|
|
|
) : null
|
2025-01-07 02:29:29 +08:00
|
|
|
}>
|
2025-03-02 13:49:10 +08:00
|
|
|
<AppTooltip title={!isOpen ? 'Share item' : ''}>
|
2025-02-07 05:31:46 +08:00
|
|
|
<div className="flex">{children}</div>
|
|
|
|
</AppTooltip>
|
2025-01-07 02:29:29 +08:00
|
|
|
</AppPopover>
|
|
|
|
);
|
|
|
|
};
|