-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add share functionality (#618)
Co-authored-by: Khuda Dad Nomani <[email protected]>%0ACo-authored-by: samz <[email protected]>
- Loading branch information
1 parent
cbdd067
commit 31a972e
Showing
4 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react'; | ||
import { FaShareAlt } from 'react-icons/fa'; | ||
import { useServices } from '../../services'; | ||
import { toast } from 'react-hot-toast'; | ||
import { Tooltip } from '../common'; | ||
|
||
interface ShareButtonProps {} | ||
|
||
export const ShareButton: React.FunctionComponent<ShareButtonProps> = () => { | ||
const { editorSvc } = useServices(); | ||
|
||
const handleShare = () => { | ||
toast.promise( | ||
(async function () { | ||
const base64 = await editorSvc.exportAsBase64(); | ||
const url = `${window.location.origin}/?base64=${encodeURIComponent( | ||
base64 | ||
)}`; | ||
await navigator.clipboard.writeText(url); | ||
}()), | ||
{ | ||
loading: 'Copying URL to clipboard...', | ||
success: 'URL copied to clipboard!', | ||
error: 'Failed to copy URL to clipboard.', | ||
} | ||
); | ||
}; | ||
|
||
return ( | ||
<Tooltip content={'Share link'} placement="top" hideOnClick={true}> | ||
<button className="bg-inherit" onClick={handleShare}> | ||
<FaShareAlt className="text-gray-500 hover:text-white" /> | ||
</button> | ||
</Tooltip> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters