Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fea: term integration #33

Merged
merged 1 commit into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 99 additions & 52 deletions src/components/home/HomePage.jsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,115 @@
import React, { useState } from "react";
import { Button, Col, Container, Row } from "react-bootstrap";
import "./HomePage.scss";
import { useTranslate } from "@tolgee/react";
import axiosInstance from "../../config/axios-config.js";
import {LANGUAGE} from "../../utils/Constants.js";
import { LANGUAGE, mapLanguageCode } from "../../utils/Constants.js";
import {useQuery} from "react-query";
import { useParams } from "react-router-dom";


const fetchTexts = async () => {
const language = localStorage.getItem(LANGUAGE) ?? "bo";
const { data } = await axiosInstance.get("api/v1/texts", {
params: { language }
});
return data;
const fetchTexts = async (parentId) => {
const storedLanguage = localStorage.getItem(LANGUAGE);
const language = (storedLanguage ? mapLanguageCode(storedLanguage) : "bo");
const { data } = await axiosInstance.get("api/v1/terms", {
params: {
language,
...(parentId && { parent_id: parentId }),
limit: 10,
skip: 0
}
});
return data;
}
const HomePage = () => {
const { t } = useTranslate();
const {data: textData, isLoading: textsIsLoading} = useQuery("texts", fetchTexts,{refetchOnWindowFocus: false,staleTime: 1000 * 60 * 20})
return (
<Container fluid className="homepage-container">
<Row className="justify-content-center">
<Col lg={7} md={8} className="left-section mb-4 mb-lg-0">
<div className="section-1 ">
<h2 className="title mt-2 browse-library-text">{ t("home.browse_text") }</h2>
<Button className="browse-button">
{ t("side_nav.explore_collections") }
</Button>
</div>
const { id } = useParams();
const { t } = useTranslate();
const [parentId, setParentId] = useState(id || "");

const { data: textData, isLoading } = useQuery(
["texts", parentId],
() => fetchTexts(parentId),
{
refetchOnWindowFocus: false,
staleTime: 1000 * 60 * 20
}
);

<div className="section-2 mt-5">
<Row className="full-width-row flex-lg-row flex-column">
<Col md={10} lg={6} className="part part-left">
<div className=" green-line mb-3"/>
<div className="subtitle part-title">{ t("content.title.words_of_buddha") } </div>
<p className=" subtitle part-subtitle"> { t("content.subtitle.words_of_buddha") }</p>
</Col>
const textsList = textData || { terms: [], total: 0, skip: 0, limit: 10 };

if (isLoading) {
return (
<Container fluid className="homepage-container">
<Row className="justify-content-center">
<Col xs={12} className="text-center py-5">
<p>Loading content...</p>
</Col>
</Row>
</Container>
);
}

<Col md={10} lg={6} className="part part-right">
<div className="red-line mb-3"/>
<p className="subtitle part-title">{ t("content.title.liturgy") }</p>
<p className="subtitle part-subtitle">{ t("content.subtitle.prayers_rutuals") }</p>
</Col>
</Row>
const renderBrowseSection = () => {
return (
<div className="section-1 ">
<h2 className="title mt-2 browse-library-text">{ t("home.browse_text") }</h2>
<Button className="browse-button">
{ t("side_nav.explore_collections") }
</Button>
</div>
);
};

<Row className="full-width-row flex-lg-row flex-column">
<Col md={10} lg={6} className="part part-left ">
<div className="red-line mb-3"/>
<div className="subtitle part-title">{ t("content.title.Buddhavacana") }</div>
<p className="subtitle part-subtitle">{ t("content.subtitle.buddhavacana") }</p>
</Col>
</Row>
</div>
</Col>
const renderContentSection = () => {
return (
<div className="section-2 mt-5">
<Row className="full-width-row flex-lg-row flex-column">
{textsList.terms.slice(0, 2).map((term, index) => (
<Col key={index} md={10} lg={6} className={`part ${index === 0 ? 'part-left' : 'part-right'}`}>
<div className={`${index === 0 ? 'green-line' : 'red-line'} mb-3`} />
<div className="listtitle part-title">{term.title}</div>
<p className="content part-subtitle">{term.description}</p>
</Col>
))}
</Row>
<Row className="full-width-row flex-lg-row flex-column">
{textsList.terms.slice(2, 3).map((term, index) => (
<Col key={index} md={10} lg={6} className="part part-left ">
<div className="red-line mb-3"/>
<div className="listtitle part-title">{term.title}</div>
<p className="content part-subtitle">{term.description}</p>
</Col>
))}
</Row>
</div>
);
};

<Col lg={5} md={4} className="right-section d-flex flex-column">
<h2 className="title right-title">{ t("side_nav.about_pecha_title") }</h2>
<hr className="right-divider"/>
<p className=" subtitle right-paragraph">
{ t("side_nav.about_pecha_description") }
<span className=" learn-more"> { t("common.learn_more") }</span>
</p>
</Col>
</Row>
</Container>
const renderAboutSection = () => {
return (
<>
<h2 className="title right-title">{ t("side_nav.about_pecha_title") }</h2>
<hr className="right-divider"/>
<p className=" content right-paragraph">
{ t("side_nav.about_pecha_description") }
<span className=" learn-more"> { t("common.learn_more") }</span>
</p>
</>
);
};

return (
<Container fluid className="homepage-container">
<Row className="justify-content-center">
<Col lg={7} md={8} className="left-section mb-4 mb-lg-0">
{renderBrowseSection()}
{renderContentSection()}
</Col>
<Col lg={5} md={4} className="right-section d-flex flex-column">
{renderAboutSection()}
</Col>
</Row>
</Container>
);
};

export default HomePage;
3 changes: 3 additions & 0 deletions src/components/home/HomePage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ $rightsection-color: #FBFBFA;
border: none;
padding: 0.5rem 1rem;
white-space: nowrap;
font-size: 17px !important;
font-family: "Monlam-bodyig-semi-bold-ttf" !important;
}
}

Expand All @@ -87,6 +89,7 @@ $rightsection-color: #FBFBFA;
}

.part-title {
font-size: 24px;
text-align: left;
margin: 0;
word-break: break-word;
Expand Down
Loading