fix community page incorporate events from json

This commit is contained in:
akcodez
2024-12-03 12:59:22 -08:00
parent 75f87bbc95
commit ee410de46c
2 changed files with 60 additions and 44 deletions

View File

@@ -54,7 +54,7 @@ jobs:
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
head: process.env.BRANCH_NAME, head: process.env.BRANCH_NAME,
base: 'events-json-contentful-gh-actions', base: 'master',
title: 'Update data from Contentful', title: 'Update data from Contentful',
body: 'Automated update of data from Contentful.', body: 'Automated update of data from Contentful.',
}); });

View File

@@ -1,19 +1,13 @@
import React, { useState } from "react"; import React, { useState, useEffect } from "react";
import { useThemeHooks } from "@redocly/theme/core/hooks";
import moment from "moment"; import moment from "moment";
import { useThemeHooks } from "@redocly/theme/core/hooks";
import allEvents from "../static/JSON/events.json";
import { Link } from "@redocly/theme/components/Link/Link"; import { Link } from "@redocly/theme/components/Link/Link";
import events from "../static/JSON/events.json"
export const frontmatter = {
seo: {
title: "Community",
description:
"The XRP Ledger (XRPL) is a community-driven public blockchain. Heres how you can get involved.",
},
};
const findNearestUpcomingEvent = (events) => { const findNearestUpcomingEvent = (events) => {
let nearestEvent = null; let nearestEvent = null;
let nearestDateDiff = Infinity; let nearestDateDiff = Infinity;
let index; let index = 0;
events.forEach((event, i) => { events.forEach((event, i) => {
const eventStartDate = moment(event.start_date, "MMMM DD, YYYY"); const eventStartDate = moment(event.start_date, "MMMM DD, YYYY");
const currentDate = moment(); const currentDate = moment();
@@ -22,19 +16,33 @@ const findNearestUpcomingEvent = (events) => {
if (diff >= 0 && diff < nearestDateDiff) { if (diff >= 0 && diff < nearestDateDiff) {
nearestEvent = event; nearestEvent = event;
nearestDateDiff = diff; nearestDateDiff = diff;
index = i index = i;
} }
}); });
return { nearestEvent, nearestDateDiff, index }; return { nearestEvent, nearestDateDiff, index };
}; };
const { nearestDateDiff, nearestEvent, index } = findNearestUpcomingEvent(events);
const XrplEventsAndCarouselSection = ({ events }) => { const XrplEventsAndCarouselSection = ({ events }) => {
const { useTranslate } = useThemeHooks(); const { useTranslate } = useThemeHooks();
const { translate } = useTranslate(); const { translate } = useTranslate();
const [currentIndex, setCurrentIndex] = useState(index); // use nearest event's index as init state // State variables for the nearest event
const [nearestEventInfo, setNearestEventInfo] = useState({
nearestEvent: null,
nearestDateDiff: null,
index: 0,
});
// State for the current index in the carousel
const [currentIndex, setCurrentIndex] = useState(0);
useEffect(() => {
const { nearestEvent, nearestDateDiff, index } =
findNearestUpcomingEvent(events);
setNearestEventInfo({ nearestEvent, nearestDateDiff, index });
setCurrentIndex(index);
}, [events]);
const updateCarousel = () => { const updateCarousel = () => {
const prevEvent = events[currentIndex - 1] || null; const prevEvent = events[currentIndex - 1] || null;
const currentEvent = events[currentIndex]; const currentEvent = events[currentIndex];
@@ -49,17 +57,18 @@ const XrplEventsAndCarouselSection = ({ events }) => {
const handlePrev = () => { const handlePrev = () => {
if (currentIndex > 0) { if (currentIndex > 0) {
setCurrentIndex(currentIndex - 1); setCurrentIndex((prevIndex) => prevIndex - 1);
} }
}; };
const handleNext = () => { const handleNext = () => {
if (currentIndex < events.length - 1) { if (currentIndex < events.length - 1) {
setCurrentIndex(currentIndex + 1); setCurrentIndex((prevIndex) => prevIndex + 1);
} }
}; };
const { prevEvent, currentEvent, nextEvent } = updateCarousel(); const { prevEvent, currentEvent, nextEvent } = updateCarousel();
return ( return (
<> <>
<section className="xrpl-events-section"> <section className="xrpl-events-section">
@@ -91,24 +100,28 @@ const XrplEventsAndCarouselSection = ({ events }) => {
{translate("View All Events")} {translate("View All Events")}
</Link> </Link>
</div> </div>
{!!nearestEvent && ( {!!nearestEventInfo.nearestEvent && (
<div className="upcoming-event" id="upcoming-events-section"> <div className="upcoming-event" id="upcoming-events-section">
<p className="upcoming-label">{translate("UPCOMING EVENT")}</p> <p className="upcoming-label">{translate("UPCOMING EVENT")}</p>
<div id="days-count" className="days-count"> <div id="days-count" className="days-count">
{nearestDateDiff} {nearestEventInfo.nearestDateDiff}
</div> </div>
<div className="days-word">{translate("days")}</div> <div className="days-word">{translate("days")}</div>
<div className="num-separator"></div> <div className="num-separator"></div>
<h5 id="upcoming-event-name" className="event-name"> <h5 id="upcoming-event-name" className="event-name">
{translate(nearestEvent?.name)} {translate(nearestEventInfo.nearestEvent?.name)}
</h5> </h5>
<p className="mb-2 event-details d-flex icon"> <p className="mb-2 event-details d-flex icon">
<span className="icon-location"></span> <span className="icon-location"></span>
<span id="upcoming-event-date">{nearestEvent?.date}</span> <span id="upcoming-event-date">
{nearestEventInfo.nearestEvent?.date}
</span>
</p> </p>
<p className="event-location d-flex icon"> <p className="event-location d-flex icon">
<span className="icon-date" id="upcoming-event-location"></span> <span className="icon-date" id="upcoming-event-location"></span>
<span id="location-tag">{nearestEvent?.location}</span> <span id="location-tag">
{nearestEventInfo.nearestEvent?.location}
</span>
</p> </p>
</div> </div>
)} )}
@@ -126,14 +139,14 @@ const XrplEventsAndCarouselSection = ({ events }) => {
<img <img
id="left-image" id="left-image"
alt="Left Event Image" alt="Left Event Image"
src={prevEvent ? prevEvent.image : ""} src={prevEvent ? `/img/events/${prevEvent.image}` : ""}
style={{ visibility: prevEvent ? "visible" : "hidden" }} style={{ visibility: prevEvent ? "visible" : "hidden" }}
/> />
<div className="center-image-wrapper"> <div className="center-image-wrapper">
<img <img
id="center-image" id="center-image"
alt="Featured Event Image" alt="Featured Event Image"
src={currentEvent ? currentEvent.image : ""} src={currentEvent ? `/img/events/${currentEvent.image}` : ""}
onClick={() => onClick={() =>
currentEvent && window.open(currentEvent.link, "_blank") currentEvent && window.open(currentEvent.link, "_blank")
} }
@@ -155,7 +168,7 @@ const XrplEventsAndCarouselSection = ({ events }) => {
<img <img
id="right-image" id="right-image"
alt="Right Event Image" alt="Right Event Image"
src={nextEvent ? nextEvent.image : ""} src={nextEvent ? `/img/events/${nextEvent.image}` : ""}
style={{ visibility: nextEvent ? "visible" : "hidden" }} style={{ visibility: nextEvent ? "visible" : "hidden" }}
/> />
</div> </div>
@@ -174,6 +187,7 @@ const XrplEventsAndCarouselSection = ({ events }) => {
}; };
const CommunityPage: React.FC = () => { const CommunityPage: React.FC = () => {
const events = allEvents.filter((event) => event.community)
const { useTranslate } = useThemeHooks(); const { useTranslate } = useThemeHooks();
const { translate } = useTranslate(); const { translate } = useTranslate();
return ( return (
@@ -469,16 +483,17 @@ const CommunityPage: React.FC = () => {
{/* Bottom Cards Section 2 cards */} {/* Bottom Cards Section 2 cards */}
<section className="bottom-cards-section bug-bounty"> <section className="bottom-cards-section bug-bounty">
<div className="com-card"> <div className="com-card">
<img className="top-right-img bug-bounty-card-bg" alt="Top Right Image" /> <img
className="top-right-img bug-bounty-card-bg"
alt="Top Right Image"
/>
<div className="card-content"> <div className="card-content">
<h6 className="card-title"> <h6 className="card-title">
{translate("RippleX Bug Bounty Program")} {translate("RippleX Bug Bounty Program")}
</h6> </h6>
<h6 className="card-subtitle"> <h6 className="card-subtitle">
{translate( {translate("Contribute to the XRP Ledger's")}
"Contribute to the XRP Ledger's" <br />
)}
<br/>
Security Security
</h6> </h6>
<p className="card-description"> <p className="card-description">
@@ -486,14 +501,14 @@ const CommunityPage: React.FC = () => {
"RippleXs Bug Bounty, part of Ripple's 1 Billion XRP pledge, strengthens XRP Ledger security and supports its ecosystem." "RippleXs Bug Bounty, part of Ripple's 1 Billion XRP pledge, strengthens XRP Ledger security and supports its ecosystem."
)} )}
<p className="card-description"> <p className="card-description">
{ {translate(
translate("Use this program to report bugs in RippleX/rippled. Send a detailed report of a qualifying bug to ") "Use this program to report bugs in RippleX/rippled. Send a detailed report of a qualifying bug to "
} )}
<a href="mailto:bugs@ripple.com">bugs@ripple.com</a> <a href="mailto:bugs@ripple.com">bugs@ripple.com</a>
{ {translate(" and use the ")}
translate(" and use the ") <a href="https://ripple.com/files/bug-bounty.asc">
} Public Key.
<a href="https://ripple.com/files/bug-bounty.asc">Public Key.</a> </a>
</p> </p>
</p> </p>
<div className="card-links"> <div className="card-links">
@@ -508,13 +523,14 @@ const CommunityPage: React.FC = () => {
</div> </div>
</div> </div>
<div className="com-card"> <div className="com-card">
<img className="bottom-right-img bug-bounty-card-bg-2" alt="Bottom Right Image" /> <img
className="bottom-right-img bug-bounty-card-bg-2"
alt="Bottom Right Image"
/>
<div className="card-content"> <div className="card-content">
<h6 className="card-title">{translate("Report a Scam")}</h6> <h6 className="card-title">{translate("Report a Scam")}</h6>
<h6 className="card-subtitle pr-bt28"> <h6 className="card-subtitle pr-bt28">
{translate( {translate("Report Scams to Safeguard Our Community")}
"Report Scams to Safeguard Our Community"
)}
</h6> </h6>
<p className="card-description"> <p className="card-description">
{translate( {translate(