From ee410de46c8fe7913c4720687e98ef74e0709745 Mon Sep 17 00:00:00 2001 From: akcodez Date: Tue, 3 Dec 2024 12:59:22 -0800 Subject: [PATCH] fix community page incorporate events from json --- .github/workflows/update-contentful-data.yml | 2 +- community/index.page.tsx | 102 +++++++++++-------- 2 files changed, 60 insertions(+), 44 deletions(-) diff --git a/.github/workflows/update-contentful-data.yml b/.github/workflows/update-contentful-data.yml index ea971ed8e5..16d4aa02dc 100644 --- a/.github/workflows/update-contentful-data.yml +++ b/.github/workflows/update-contentful-data.yml @@ -54,7 +54,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, head: process.env.BRANCH_NAME, - base: 'events-json-contentful-gh-actions', + base: 'master', title: 'Update data from Contentful', body: 'Automated update of data from Contentful.', }); diff --git a/community/index.page.tsx b/community/index.page.tsx index 8831634906..8510e6cd40 100644 --- a/community/index.page.tsx +++ b/community/index.page.tsx @@ -1,19 +1,13 @@ -import React, { useState } from "react"; -import { useThemeHooks } from "@redocly/theme/core/hooks"; +import React, { useState, useEffect } from "react"; 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 events from "../static/JSON/events.json" -export const frontmatter = { - seo: { - title: "Community", - description: - "The XRP Ledger (XRPL) is a community-driven public blockchain. Here’s how you can get involved.", - }, -}; + const findNearestUpcomingEvent = (events) => { let nearestEvent = null; let nearestDateDiff = Infinity; - let index; + let index = 0; events.forEach((event, i) => { const eventStartDate = moment(event.start_date, "MMMM DD, YYYY"); const currentDate = moment(); @@ -22,19 +16,33 @@ const findNearestUpcomingEvent = (events) => { if (diff >= 0 && diff < nearestDateDiff) { nearestEvent = event; nearestDateDiff = diff; - index = i + index = i; } }); return { nearestEvent, nearestDateDiff, index }; }; - -const { nearestDateDiff, nearestEvent, index } = findNearestUpcomingEvent(events); const XrplEventsAndCarouselSection = ({ events }) => { const { useTranslate } = useThemeHooks(); - const { translate } = useTranslate(); - const [currentIndex, setCurrentIndex] = useState(index); // use nearest event's index as init state + const { translate } = useTranslate(); + // 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 prevEvent = events[currentIndex - 1] || null; const currentEvent = events[currentIndex]; @@ -49,17 +57,18 @@ const XrplEventsAndCarouselSection = ({ events }) => { const handlePrev = () => { if (currentIndex > 0) { - setCurrentIndex(currentIndex - 1); + setCurrentIndex((prevIndex) => prevIndex - 1); } }; const handleNext = () => { if (currentIndex < events.length - 1) { - setCurrentIndex(currentIndex + 1); + setCurrentIndex((prevIndex) => prevIndex + 1); } }; const { prevEvent, currentEvent, nextEvent } = updateCarousel(); + return ( <>
@@ -91,24 +100,28 @@ const XrplEventsAndCarouselSection = ({ events }) => { {translate("View All Events")} - {!!nearestEvent && ( + {!!nearestEventInfo.nearestEvent && (

{translate("UPCOMING EVENT")}

- {nearestDateDiff} + {nearestEventInfo.nearestDateDiff}
{translate("days")}
- {translate(nearestEvent?.name)} + {translate(nearestEventInfo.nearestEvent?.name)}

- {nearestEvent?.date} + + {nearestEventInfo.nearestEvent?.date} +

- {nearestEvent?.location} + + {nearestEventInfo.nearestEvent?.location} +

)} @@ -126,14 +139,14 @@ const XrplEventsAndCarouselSection = ({ events }) => { Left Event Image
Featured Event Image currentEvent && window.open(currentEvent.link, "_blank") } @@ -155,7 +168,7 @@ const XrplEventsAndCarouselSection = ({ events }) => { Right Event Image
@@ -174,6 +187,7 @@ const XrplEventsAndCarouselSection = ({ events }) => { }; const CommunityPage: React.FC = () => { + const events = allEvents.filter((event) => event.community) const { useTranslate } = useThemeHooks(); const { translate } = useTranslate(); return ( @@ -469,16 +483,17 @@ const CommunityPage: React.FC = () => { {/* Bottom Cards Section 2 cards */}
- Top Right Image + Top Right Image
{translate("RippleX Bug Bounty Program")}
- {translate( - "Contribute to the XRP Ledger's" - )} -
+ {translate("Contribute to the XRP Ledger's")} +
Security

@@ -486,14 +501,14 @@ const CommunityPage: React.FC = () => { "RippleX’s Bug Bounty, part of Ripple's 1 Billion XRP pledge, strengthens XRP Ledger security and supports its ecosystem." )}

- { - translate("Use this program to report bugs in RippleX/rippled. Send a detailed report of a qualifying bug to ") - } - bugs@ripple.com - { - translate(" and use the ") - } - Public Key. + {translate( + "Use this program to report bugs in RippleX/rippled. Send a detailed report of a qualifying bug to " + )} + bugs@ripple.com + {translate(" and use the ")} + + Public Key. +

@@ -508,13 +523,14 @@ const CommunityPage: React.FC = () => {
- Bottom Right Image + Bottom Right Image
{translate("Report a Scam")}
- {translate( - "Report Scams to Safeguard Our Community" - )} + {translate("Report Scams to Safeguard Our Community")}

{translate(