Skip to content

Commit

Permalink
fix : share wrapper as mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
anishsapkota committed Jan 7, 2024
1 parent cf1eec1 commit 54215c6
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/management-system-v2/components/modeler-share-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ const ModelerShareModalButton: FC<ShareModalProps> = ({ onExport, onExportMobile
setActiveIndex(index);
};

const shareWrapper = async (fn: (args: any) => Promise<void>, args: any) => {
try {
if (isSharing) return;
setIsSharing(true);
await fn(args);
} catch (error) {
console.error('Sharing failed:', error);
} finally {
setIsSharing(false);
}
};

const handleShareMobile = async (sharedAs: 'public' | 'protected') => {
if (navigator.share) {
try {
Expand All @@ -79,13 +91,13 @@ const ModelerShareModalButton: FC<ShareModalProps> = ({ onExport, onExportMobile
optionIcon: <LinkOutlined style={{ fontSize: '24px' }} />,
optionName: 'Share Process with Public Link',
optionTitle: 'Share Process with Public Link',
optionOnClick: () => handleShareMobile('public'),
optionOnClick: () => shareWrapper(handleShareMobile, 'public'),
},
{
optionIcon: <LinkOutlined style={{ fontSize: '24px' }} />,
optionName: 'Share Process for Registered Users',
optionTitle: 'Share Process for Registered Users',
optionOnClick: () => handleShareMobile('protected'),
optionOnClick: () => shareWrapper(handleShareMobile, 'protected'),
},
{
optionIcon: <FilePdfOutlined style={{ fontSize: '24px' }} />,
Expand All @@ -97,16 +109,11 @@ const ModelerShareModalButton: FC<ShareModalProps> = ({ onExport, onExportMobile
optionIcon: <FileImageOutlined style={{ fontSize: '24px' }} />,
optionName: 'Share Process as Image',
optionTitle: 'Share Process as Image',
optionOnClick: async () => {
if (isSharing) return;
setIsSharing(true);
await shareProcessImage(modeler);
setIsSharing(false);
},
optionOnClick: () => shareWrapper(shareProcessImage, modeler),
},
{
optionIcon: (
<Image priority src="/proceed-icon.png" height={24} width={40} alt="Follow us on Twitter" />
<Image priority src="/proceed-icon.png" height={24} width={40} alt="proceed logo" />
),
optionName: 'Share Process as BPMN File',
optionTitle: 'Share Process as BPMN File',
Expand Down

0 comments on commit 54215c6

Please sign in to comment.