ourapproach language updated
This commit is contained in:
commit
924c72a6c6
@ -1,21 +1,38 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { TabContent, TabPane, Nav, NavItem, NavLink, Row } from "reactstrap";
|
import { TabContent, TabPane, Nav, NavItem, NavLink, Row } from "reactstrap";
|
||||||
import classnames from "classnames";
|
import classnames from "classnames";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { TabServices } from "../../utils/constant.utils"; // JSON array
|
import { useTranslation } from "next-i18next";
|
||||||
import Campaign from "../../api/campaign";
|
|
||||||
|
|
||||||
const ClickHandler = () => {
|
const ClickHandler = () => {
|
||||||
window.scrollTo(10, 0);
|
window.scrollTo(0, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Extract unique categories from the JSON dynamically
|
|
||||||
const categories = [...new Set(Campaign.map((service) => service.category))];
|
|
||||||
|
|
||||||
const ServiceSectionS2 = () => {
|
const ServiceSectionS2 = () => {
|
||||||
|
const { t, i18n } = useTranslation("services");
|
||||||
|
|
||||||
|
// Get campaigns array from the translation JSON
|
||||||
|
const campaigns = t("campaigns", { returnObjects: true });
|
||||||
|
|
||||||
|
// Extract unique categories from the campaigns dynamically
|
||||||
|
const categories = [...new Set(campaigns.map((service) => service.category))];
|
||||||
|
|
||||||
|
// Default active tab is the first category, but we will set it dynamically based on the language
|
||||||
const [activeTab, setActiveTab] = useState(categories[0]);
|
const [activeTab, setActiveTab] = useState(categories[0]);
|
||||||
|
|
||||||
|
// Function to change the active tab based on the selected language
|
||||||
|
const changeActiveTabOnLanguageChange = () => {
|
||||||
|
// Set the active tab to the first category whenever the language changes
|
||||||
|
setActiveTab(categories[0]);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Track language changes using the `useEffect` hook
|
||||||
|
useEffect(() => {
|
||||||
|
// Whenever the language changes, reset the active tab
|
||||||
|
changeActiveTabOnLanguageChange();
|
||||||
|
}, [i18n.language]); // `i18n.language` triggers the effect when the language changes
|
||||||
|
|
||||||
const toggle = (tab) => {
|
const toggle = (tab) => {
|
||||||
if (activeTab !== tab) setActiveTab(tab);
|
if (activeTab !== tab) setActiveTab(tab);
|
||||||
};
|
};
|
||||||
@ -26,7 +43,7 @@ const ServiceSectionS2 = () => {
|
|||||||
<div className="wpo-campaign-wrap">
|
<div className="wpo-campaign-wrap">
|
||||||
{/* Tab Navigation */}
|
{/* Tab Navigation */}
|
||||||
<Nav tabs>
|
<Nav tabs>
|
||||||
{categories.map((cat, idx) => (
|
{categories.slice(0, 5).map((cat, idx) => (
|
||||||
<NavItem key={idx}>
|
<NavItem key={idx}>
|
||||||
<NavLink
|
<NavLink
|
||||||
className={classnames({ active: activeTab === cat })}
|
className={classnames({ active: activeTab === cat })}
|
||||||
@ -43,15 +60,18 @@ const ServiceSectionS2 = () => {
|
|||||||
{categories.map((cat, idx) => (
|
{categories.map((cat, idx) => (
|
||||||
<TabPane tabId={cat} key={idx}>
|
<TabPane tabId={cat} key={idx}>
|
||||||
<Row>
|
<Row>
|
||||||
{Campaign.filter((srv) => srv.category === cat).slice(0,3).map(
|
{/* Filter campaigns based on category */}
|
||||||
(service, srvIdx) => (
|
{campaigns
|
||||||
|
.filter((srv) => srv.category === cat)
|
||||||
|
.slice(0, 3) // Limit to 3 services per category
|
||||||
|
.map((service, srvIdx) => (
|
||||||
<div className="col-lg-4 col-md-6 col-12" key={srvIdx}>
|
<div className="col-lg-4 col-md-6 col-12" key={srvIdx}>
|
||||||
<div className="wpo-campaign-single">
|
<div className="wpo-campaign-single">
|
||||||
<div className="wpo-campaign-item">
|
<div className="wpo-campaign-item">
|
||||||
<div className="wpo-campaign-img">
|
<div className="wpo-campaign-img">
|
||||||
<Image
|
<Image
|
||||||
src={service.sImgS}
|
src={service.sImgS} // Service Image
|
||||||
alt={service.sTitle}
|
alt={service.sTitle} // Service Title for Alt text
|
||||||
width={400}
|
width={400}
|
||||||
height={250}
|
height={250}
|
||||||
/>
|
/>
|
||||||
@ -62,19 +82,25 @@ const ServiceSectionS2 = () => {
|
|||||||
<Link
|
<Link
|
||||||
onClick={ClickHandler}
|
onClick={ClickHandler}
|
||||||
href={`/service-single/[slug]`}
|
href={`/service-single/[slug]`}
|
||||||
as={`/service-single/${service.slug}`}
|
as={`/service-single/${service.slug}`} // Dynamic slug
|
||||||
>
|
>
|
||||||
{service.sTitle}
|
{service.sTitle} {/* Service Title */}
|
||||||
</Link>
|
</Link>
|
||||||
</h2>
|
</h2>
|
||||||
<p>{service.description}</p>
|
<p
|
||||||
|
dangerouslySetInnerHTML={{
|
||||||
|
__html:
|
||||||
|
service.description.length > 100
|
||||||
|
? service.description.substring(0, 100) + "..."
|
||||||
|
: service.description,
|
||||||
|
}}
|
||||||
|
></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
))}
|
||||||
)}
|
|
||||||
</Row>
|
</Row>
|
||||||
</TabPane>
|
</TabPane>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@ -83,7 +83,7 @@ const Header2 = (props) => {
|
|||||||
<div className="header-right d-flex align-items-center justify-content-end">
|
<div className="header-right d-flex align-items-center justify-content-end">
|
||||||
<div className="language me-4">
|
<div className="language me-4">
|
||||||
<select onChange={handleLanguageChange} value={router.locale}>
|
<select onChange={handleLanguageChange} value={router.locale}>
|
||||||
<option value="es">Español</option>
|
<option value="es">Spanish</option>
|
||||||
<option value="en">English</option>
|
<option value="en">English</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -5,7 +5,7 @@ module.exports = {
|
|||||||
locales: ['en', 'es'],
|
locales: ['en', 'es'],
|
||||||
localeDetection: false,
|
localeDetection: false,
|
||||||
},
|
},
|
||||||
ns: ['common', 'menu', 'homeHero', 'home4Card', '(home)/homeAbout', '(home)/homeFeature', '(home)/testimonial', '(home)/homeCalltoAction', 'blog', 'footer', 'ourMission', 'racialJustice', 'services', 'ourStory', 'aboutService', 'aboutMission', 'aboutRacial', 'aboutDonor'],
|
ns: ['common', 'menu', 'homeHero', 'home4Card', '(home)/homeAbout', '(home)/homeFeature', '(home)/testimonial', '(home)/homeCalltoAction', 'blog', 'footer', 'ourMission', 'racialJustice', 'services', 'ourStory', 'aboutService', 'aboutMission', 'aboutRacial', 'aboutDonor', 'OurApproach', 'contact'],
|
||||||
defaultNS: 'common',
|
defaultNS: 'common',
|
||||||
// localePath: './public/locales',
|
// localePath: './public/locales',
|
||||||
};
|
};
|
||||||
|
|||||||
@ -40,7 +40,7 @@ export default HomePage;
|
|||||||
export async function getStaticProps({ locale }) {
|
export async function getStaticProps({ locale }) {
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
...(await serverSideTranslations(locale, ['common', 'menu', 'homeHero', 'home4Card', '(home)/homeAbout', '(home)/homeFeature', '(home)/testimonial', '(home)/homeCalltoAction', 'blog', 'footer'])), // Add 'home', 'footer', etc. if needed
|
...(await serverSideTranslations(locale, ['common', 'menu', 'homeHero', 'home4Card', '(home)/homeAbout', '(home)/homeFeature', '(home)/testimonial', '(home)/homeCalltoAction', 'blog', 'footer', 'services'])), // Add 'home', 'footer', etc. if needed
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user