Skip to content

Commit

Permalink
Share recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
guzmanalejandro committed Dec 14, 2023
1 parent 02f2cc0 commit 9a9dacb
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/components/RecipeDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import defaultProfile from "../assets/defaultProfile.png";
import { CSSTransition } from "react-transition-group";
import gyozas from '../assets/gyozas.jpg';
import "bootstrap/dist/css/bootstrap.min.css";
import { FaWhatsapp, FaLinkedin, FaTwitter, FaCopy } from 'react-icons/fa';
import {
Container,
Row,
Expand All @@ -29,6 +30,7 @@ import {
FolderSymlinkFill,
Heart,
HeartFill,
Share
} from "react-bootstrap-icons";
import ImageModal from "./ImageModal";
import Reviews from "./Reviews";
Expand Down Expand Up @@ -301,6 +303,34 @@ function RecipeDetail() {
setShowUnfollowModal(false);
};

const recipeUrl = `www.kasula.live/RecipeDetail/${id}`;
const message = encodeURIComponent('Check this amazing recipe that I found in Kasulà! ' + recipeUrl);

const shareOnWhatsApp = () => {
window.open(`https://wa.me/?text=${message}`, '_blank');
};

const shareOnLinkedIn = () => {
window.open(`https://www.linkedin.com/shareArticle?mini=true&url=${recipeUrl}&title=${encodeURIComponent('Mira esta receta que chula!')}`, '_blank');
};

const shareOnTwitter = () => {
window.open(`https://twitter.com/intent/tweet?text=${message}`, '_blank');
};

const copyToClipboard = () => {
const url = window.location.href;
navigator.clipboard.writeText(url).then(() => {
setToastData({
message: "Link copied to clipboard!",
variant: "success",
show: true,
});
}, (err) => {
console.error('Could not copy text: ', err);
});
};

return (
<Container fluid className="min-vh-100">
<ImageModal
Expand Down Expand Up @@ -487,6 +517,26 @@ function RecipeDetail() {
)}
</span>
</div>
<Dropdown>
<Dropdown.Toggle variant="" id="dropdown-basic">
<Share />
</Dropdown.Toggle>

<Dropdown.Menu>
<Dropdown.Item onClick={shareOnWhatsApp}>
<FaWhatsapp /> WhatsApp
</Dropdown.Item>
<Dropdown.Item onClick={shareOnLinkedIn}>
<FaLinkedin /> LinkedIn
</Dropdown.Item>
<Dropdown.Item onClick={shareOnTwitter}>
<FaTwitter /> Twitter
</Dropdown.Item>
<Dropdown.Item onClick={copyToClipboard}>
<FaCopy /> Copy
</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
</div>
</Col>
<Col xs={12}>
Expand Down

0 comments on commit 9a9dacb

Please sign in to comment.