Skip to content

Commit

Permalink
Implement Dynamic Likes for Service Cards (#369)
Browse files Browse the repository at this point in the history
* Toast added on service page

* enable like option on services page
  • Loading branch information
akshadgujarkar authored Oct 28, 2024
1 parent edc698d commit c8cc644
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@hookform/resolvers": "^3.8.0",
"@mui/icons-material": "^5.16.0",
"@mui/lab": "^5.0.0-alpha.171",
"@mui/material": "^5.16.7",
"@mui/material": "^6.1.5",
"@mui/system": "^6.1.2",
"@mui/x-date-pickers": "^7.9.0",
"aos": "^3.0.0-beta.6",
Expand Down
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { BlogProvider } from "../context/blogContext.jsx";
function App() {
const [mode, setMode] = useState("light");
const [textcolor, settextcolor] = useState("black");

let toggleMode = () => {
if (mode === "light") {
setMode("dark");
Expand Down
5 changes: 3 additions & 2 deletions src/components/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Modal,
} from "@mui/material";
import { Link as RouterLink } from "react-router-dom";
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faXTwitter } from "@fortawesome/free-brands-svg-icons";
import {
FaFacebookF,
Expand Down Expand Up @@ -122,7 +123,7 @@ const Footer = () => {

{/* Social Media Icons */}
<Grid item xs={12} sx={{ textAlign: "center", mt: 2 }}>
{[
{[
{ Icon: FaFacebookF, url: "https://www.facebook.com" },
{ Icon: FaTelegramPlane, url: "https://web.telegram.org" },
{ Icon: FaLinkedinIn, url: "https://www.linkedin.com" },
Expand All @@ -143,7 +144,7 @@ const Footer = () => {
"&:hover": { color: "#fff" },
}}
>
<Icon fontSize="inherit" />
<FontAwesomeIcon icon={Icon} fontSize="inherit" />
</IconButton>
))}
</Grid>
Expand Down
4 changes: 3 additions & 1 deletion src/styles/Services.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
display: flex;
align-items: center;
font-size: 0.9em;
cursor: pointer;
}

/* Modal Styles */
Expand Down Expand Up @@ -138,4 +139,5 @@
--card-bg-color: #ffffff;
--button-bg-color: #007bff;
--button-hover-bg-color: #0056b3;
}
}

4 changes: 3 additions & 1 deletion src/views/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Grid, Typography, Box } from "@mui/material";
import React from 'react';
import { Box, Grid, IconButton, Typography } from '@mui/material'; // Example MUI imports

import homeImg1 from "../assets/home/homeImg1.jpg";
import "../styles/shared.css";
import homeImg2 from "../assets/home/homeImg2.avif";
Expand Down
36 changes: 29 additions & 7 deletions src/views/Services.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@ import { toast, ToastContainer } from "react-toastify";
const Services = ({ mode, textcolor }) => {
const [modalOpen, setModalOpen] = useState(false);
const [currentService, setCurrentService] = useState("");
const [like, setLike] = useState({
PersonalTraining: false,
NutritionalCounseling: false,
OnlineVirtualTraining: false,
});

const handleOpenModal = (service) => {
setCurrentService(service);
setModalOpen(true);
};

const handleLikeClick = (serviceName) => {
setLike((prev) => ({
...prev,
[serviceName.replace(" ", "")]: !prev[serviceName.replace(" ", "")],
}));
};

const handleCloseModal = () => {
setModalOpen(false);
setCurrentService("");
Expand Down Expand Up @@ -44,7 +56,7 @@ const Services = ({ mode, textcolor }) => {
imageUrl:
"https://d2wvwvig0d1mx7.cloudfront.net/data/org/26275/media/img/source/edit/3262615_edit.webp",
views: 262,
likes: 40,
baseLikes: 40,
},
{
name: "Nutritional Counseling",
Expand All @@ -53,7 +65,7 @@ const Services = ({ mode, textcolor }) => {
imageUrl:
"https://dvm0q8ak413bh.cloudfront.net/data/org/26275/media/img/source/edit/2936524_edit.webp",
views: 205,
likes: 37,
baseLikes: 37,
},
{
name: "Online Virtual Training",
Expand All @@ -62,18 +74,21 @@ const Services = ({ mode, textcolor }) => {
imageUrl:
"https://dvm0q8ak413bh.cloudfront.net/data/org/26275/media/img/source/edit/2942210_edit.webp",
views: 237,
likes: 46,
baseLikes: 46,
},
];

return (
<>
<div className={`service-grid ${mode}`}>
{services.map((service, index) => (
<div className="service-card" key={service.name}
<div
className="service-card"
key={service.name}
data-aos="fade-up"
data-aos-delay={index * 200}
data-aos-duration="1200">
data-aos-duration="1200"
>
<img src={service.imageUrl} alt={service.name} />
<h2>{service.name}</h2>
<p>{service.description}</p>
Expand All @@ -82,7 +97,14 @@ const Services = ({ mode, textcolor }) => {
</button>
<div className="stats">
<span className="views">👁️ Views: {service.views}</span>
<span className="likes">❤️ Likes: {service.likes}</span>

<span
className={`likes ${like[service.name.replace(" ", "")] ? "liked" : ""}`}
onClick={() => handleLikeClick(service.name)}
>
❤️ {like[service.name.replace(" ", "")] ? "Liked" : "Like"}:{" "}
{like[service.name.replace(" ", "")] ? service.baseLikes + 1 : service.baseLikes}
</span>
</div>
</div>
))}
Expand All @@ -105,7 +127,7 @@ const Services = ({ mode, textcolor }) => {
<p style={styles.modalText}>
Fill out the form below, and we’ll be in touch shortly.
</p>
<form onSubmit={(e) => handleSendMessage(e)}>
<form onSubmit={handleSendMessage}>
<input
type="text"
placeholder="Your Name"
Expand Down

0 comments on commit c8cc644

Please sign in to comment.