11'use client' ;
2+
23import DOMPurify from 'dompurify' ;
34import Link from 'next/link' ;
45import React from 'react' ;
56
7+ import Loading from '@/components/loading' ;
68import { Divider } from '@/components/ui' ;
7- import { useSelector } from '@/hooks/reduxHooks' ;
9+ import { NoData } from '@/components/ui' ;
10+ import { useForumData } from '@/context/ForumDataContext' ;
11+ import { ForumEvent } from '@/types/forum' ;
812import { isValidGlossaryContent } from '@/utils/glossaryValidator' ;
913import { renderContent } from '@/utils/quillUtils' ;
1014import SectionDisplay from '@/views/Forum/SectionDisplay' ;
1115
12- const Page : React . FC = ( ) => {
13- // Retrieve forum events and the selected event index from Redux .
14- const { events , selectedEventIndex } = useSelector ( ( state ) => state . forum ) ;
16+ const GlossaryPage : React . FC = ( ) => {
17+ // Access data from the context .
18+ const { selectedEvent , eventTitles } = useForumData ( ) ;
1519
16- if ( events . length === 0 ) {
17- return null ;
20+ // If either is not available, show a loading state.
21+ if ( ! selectedEvent || ! eventTitles ) {
22+ return < Loading /> ;
1823 }
1924
20- const selectedEvent = events [ selectedEventIndex ] ;
25+ // Extract the events list from eventTitles.
26+ // If eventTitles is an array, use it directly; otherwise, assume it's a ForumTitlesResponse.
27+ const eventsList : ForumEvent [ ] = Array . isArray ( eventTitles )
28+ ? eventTitles
29+ : eventTitles . forum_events ;
2130
22- // Utility function to create a slug from the event title.
23- const createSlug = ( title : string ) => {
24- return title . split ( ',' ) [ 0 ] . trim ( ) . toLowerCase ( ) . replace ( / \s + / g, '-' ) ;
25- } ;
31+ if ( eventsList . length === 0 ) {
32+ return < NoData message = "No events found" /> ;
33+ }
2634
27- // Render the main glossary content.
35+ // Render the main glossary content using the selected event .
2836 const glossaryHTML = renderContent ( selectedEvent . glossary_details ) ;
2937 const showGlossaryMain = isValidGlossaryContent ( glossaryHTML ) ;
3038
31- // Filter extra sections assigned to the "glossary" page.
32- const glossarySections = selectedEvent . sections ?. filter ( ( section : any ) => {
33- if ( ! section . pages . includes ( 'glossary' ) ) return false ;
34- const sectionHTML = renderContent ( section . content ) ;
35- return isValidGlossaryContent ( sectionHTML ) ;
36- } ) ;
37-
3839 return (
3940 < div className = "px-4 lg:px-0 prose max-w-none flex flex-col gap-6" >
4041 < Divider className = "bg-black p-0 m-0 h-[1px] w-full" />
4142
42- { /* Clean Air Forum Events Section */ }
43+ { /* Clean Air Forum Events Section (Sidebar) */ }
4344 < div className = "flex flex-col md:flex-row py-6 md:space-x-8" >
4445 { /* Left column: Heading */ }
4546 < div className = "md:w-1/3 mb-4 md:mb-0" >
46- < h3 className = "text-xl font-semibold" > Clean Air Forum Events</ h3 >
47+ < h1 className = "text-2xl mt-4 font-semibold" >
48+ Clean Air Forum Events
49+ </ h1 >
4750 </ div >
48- { /* Right column: List of events */ }
51+ { /* Right column: List of event links */ }
4952 < div className = "md:w-2/3" >
5053 < ul className = "space-y-2" >
51- { events . map ( ( event , index ) => {
52- const slug = createSlug ( event . title ) ;
53- const href = `/clean-air-forum/about?slug=${ encodeURIComponent ( slug ) } ` ;
54+ { eventsList . map ( ( event ) => {
55+ // Use the unique_title directly in the link.
56+ const href = `/clean-air-forum/about?slug=${ encodeURIComponent (
57+ event . unique_title ,
58+ ) } `;
5459 return (
5560 < li key = { event . id } >
5661 < Link
5762 href = { href }
5863 target = "_blank"
59- onClick = { ( e ) => {
60- e . preventDefault ( ) ;
61- // Open the event page in a new tab.
62- window . open ( href , '_blank' ) ;
63- } }
64- className = { `text-blue-600 hover:underline ${
65- selectedEventIndex === index ? 'font-bold' : ''
66- } `}
64+ className = "text-blue-600 hover:underline"
6765 >
6866 { event . title }
6967 </ Link >
@@ -81,9 +79,9 @@ const Page: React.FC = () => {
8179 < div className = "flex flex-col py-6 md:flex-row md:space-x-8" >
8280 { /* Left column: Heading */ }
8381 < div className = "md:w-1/3 mb-4 md:mb-0" >
84- < h2 className = "text-2xl font-bold text-gray-900" >
82+ < h1 className = "text-2xl mt-4 font-bold text-gray-900" >
8583 Clean Air Glossary
86- </ h2 >
84+ </ h1 >
8785 </ div >
8886 { /* Right column: Glossary content */ }
8987 < div
@@ -97,10 +95,9 @@ const Page: React.FC = () => {
9795 ) }
9896
9997 { /* Additional Glossary Sections (if any) */ }
100- { glossarySections && glossarySections . length > 0 && (
98+ { selectedEvent . sections && selectedEvent . sections . length > 0 && (
10199 < >
102- < Divider className = "bg-black p-0 m-0 h-[1px] w-full" />
103- { glossarySections . map ( ( section : any ) => (
100+ { selectedEvent . sections . map ( ( section : any ) => (
104101 < SectionDisplay key = { section . id } section = { section } />
105102 ) ) }
106103 </ >
@@ -109,4 +106,4 @@ const Page: React.FC = () => {
109106 ) ;
110107} ;
111108
112- export default Page ;
109+ export default GlossaryPage ;
0 commit comments