-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
463d5e3
commit d94ee7b
Showing
7 changed files
with
221 additions
and
40 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
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,23 @@ | ||
import { Share } from '@mui/icons-material' | ||
import { IconButton } from '@mui/material' | ||
import { useState } from 'react' | ||
import { SharePostDialog } from './dialogues' | ||
|
||
const ShareButton = ({ url }) => { | ||
const [showDialog, setShowDialog] = useState(false) | ||
|
||
return ( | ||
<> | ||
<IconButton onClick={() => setShowDialog(true)} color="primary"> | ||
<Share /> | ||
</IconButton> | ||
<SharePostDialog | ||
url={url} | ||
open={showDialog} | ||
setOpen={setShowDialog} | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
export default ShareButton |
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,116 @@ | ||
import { | ||
Button, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogContentText, | ||
DialogTitle, | ||
IconButton, | ||
Stack, | ||
TextField | ||
} from '@mui/material' | ||
import { | ||
ContentCopy, | ||
Facebook, | ||
LinkedIn, | ||
X, | ||
} from '@mui/icons-material' | ||
import { useStore } from '@/store' | ||
|
||
const SharePostDialog = ({ url, open, setOpen }) => { | ||
const handleClose = () => setOpen(false) | ||
|
||
const shareUrls = { | ||
facebook: `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(url)}`, | ||
twitter: `https://twitter.com/intent/tweet?url=${encodeURIComponent(url)}`, | ||
linkedin: `https://www.linkedin.com/shareArticle?mini=true&url=${encodeURIComponent(url)}`, | ||
whatsapp: `https://api.whatsapp.com/send?text=${encodeURIComponent(url)}` | ||
} | ||
const { openSnackbar } = useStore() | ||
const handleCopy = () => | ||
navigator.clipboard.writeText(url).then(() => { | ||
openSnackbar('Link copied to clipboard', 'info') | ||
}) | ||
|
||
return ( | ||
<Dialog | ||
open={open} | ||
onClose={handleClose} | ||
aria-labelledby="share-post-dialog-title" | ||
fullWidth | ||
aria-describedby="share-post-dialog-description" | ||
PaperProps={{ elevation: 0 }} | ||
> | ||
<DialogTitle id="share-dialog-title">Share this post</DialogTitle> | ||
|
||
<DialogContent> | ||
<DialogContentText | ||
id="share-post-dialog-description" | ||
color="textDisabled" | ||
gutterBottom | ||
> | ||
Share this post to your favourite social media platforms | ||
</DialogContentText> | ||
<Stack gap={1}> | ||
<TextField | ||
fullWidth | ||
value={url} | ||
slotProps={{ | ||
input: { | ||
readOnly: true, | ||
endAdornment: ( | ||
<IconButton | ||
onClick={handleCopy} | ||
aria-label="Copy link" | ||
> | ||
<ContentCopy /> | ||
</IconButton> | ||
) | ||
} | ||
}} | ||
/> | ||
<Stack direction="row" spacing={2} justifyContent="center"> | ||
<IconButton | ||
onClick={() => | ||
window.open(shareUrls.facebook, '_blank') | ||
} | ||
aria-label="Share on Facebook" | ||
> | ||
<Facebook color="primary" /> | ||
</IconButton> | ||
<IconButton | ||
onClick={() => | ||
window.open(shareUrls.twitter, '_blank') | ||
} | ||
aria-label="Share on Twitter" | ||
> | ||
<X /> | ||
</IconButton> | ||
<IconButton | ||
onClick={() => | ||
window.open(shareUrls.linkedin, '_blank') | ||
} | ||
aria-label="Share on LinkedIn" | ||
> | ||
<LinkedIn color="info" /> | ||
</IconButton> | ||
<IconButton | ||
onClick={() => | ||
window.open(shareUrls.whatsapp, '_blank') | ||
} | ||
aria-label="Share on WhatsApp" | ||
> | ||
<WhatsApp color="success" /> | ||
</IconButton> | ||
</Stack> | ||
</Stack> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={handleClose}>Close</Button> | ||
</DialogActions> | ||
</Dialog> | ||
) | ||
} | ||
|
||
export default SharePostDialog |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as DeleteCommentDialogue } from './DeleteComment' | ||
export { default as CreatePostDialog } from './CreatePost' | ||
export { default as DeletePostDialog } from './DeletePost' | ||
export { default as SharePostDialog } from './SharePost' |
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