1- import React from 'react' ;
1+ import React , { useState , useEffect , useContext } from 'react' ;
22import { motion } from 'framer-motion' ;
33import '../../styles/dnd.css' ;
44import useSeo from "../../hooks/useSeo" ;
5+ import piml from 'piml' ; // Import piml
6+ import { DndContext } from '../../context/DndContext' ; // Import DndContext
7+ import DndAuthorCard from '../../components/dnd/DndAuthorCard' ; // Import DndAuthorCard
8+ import { parseWallpaperName } from '../../utils/dndUtils' ; // Import parseWallpaperName
9+ import dndWallpapers from '../../utils/dndWallpapers' ; // Import dndWallpapers
510
611const pageVariants = {
712 initial : {
@@ -22,6 +27,11 @@ const pageTransition = {
2227} ;
2328
2429function DndAuthorsPage ( ) {
30+ const { setBreadcrumbs, setBgImageName } = useContext ( DndContext ) ;
31+ const [ authors , setAuthors ] = useState ( [ ] ) ;
32+ const [ books , setBooks ] = useState ( [ ] ) ;
33+ const [ bgImage , setBgImage ] = useState ( '' ) ; // State for background image
34+
2535 useSeo ( {
2636 title : 'Authors | From Serfs and Frauds' ,
2737 description : 'Meet the authors behind the Dungeons & Dragons campaign, From Serfs and Frauds.' ,
@@ -35,6 +45,50 @@ function DndAuthorsPage() {
3545 twitterImage : 'https://fezcode.github.io/logo512.png'
3646 } ) ;
3747
48+ useEffect ( ( ) => {
49+ setBreadcrumbs ( [
50+ { label : 'S&F' , path : '/stories' } ,
51+ { label : 'Authors' } ,
52+ ] ) ;
53+
54+ const images = dndWallpapers ;
55+ const randomImage = images [ Math . floor ( Math . random ( ) * images . length ) ] ;
56+ setBgImage ( randomImage ) ;
57+ setBgImageName ( parseWallpaperName ( randomImage . split ( '/' ) . pop ( ) ) ) ;
58+
59+ const fetchAuthorData = async ( ) => {
60+ try {
61+ const response = await fetch ( `${ process . env . PUBLIC_URL } /stories/books.piml` ) ;
62+ if ( ! response . ok ) {
63+ throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
64+ }
65+ const pimlText = await response . text ( ) ;
66+ const data = piml . parse ( pimlText ) ;
67+ setAuthors ( data . authors ) ;
68+ setBooks ( data . books ) ;
69+ } catch ( error ) {
70+ console . error ( "Failed to fetch author data:" , error ) ;
71+ }
72+ } ;
73+
74+ fetchAuthorData ( ) ;
75+ } , [ setBreadcrumbs , setBgImageName ] ) ;
76+
77+ const getBooksByAuthor = ( authorName , authorAlias ) => {
78+ const authorBooks = [ ] ;
79+ books . forEach ( book => {
80+ book . episodes . forEach ( episode => {
81+ if ( ( episode . author === authorName || episode . author === authorAlias ) && ! authorBooks . some ( b => b . bookTitle === book . bookTitle ) ) {
82+ authorBooks . push ( {
83+ bookId : book . bookId ,
84+ bookTitle : book . bookTitle ,
85+ } ) ;
86+ }
87+ } ) ;
88+ } ) ;
89+ return authorBooks ;
90+ } ;
91+
3892 return (
3993 < motion . div
4094 initial = "initial"
@@ -44,12 +98,21 @@ function DndAuthorsPage() {
4498 transition = { pageTransition }
4599 className = "dnd-page-container"
46100 >
47- < div className = "dnd-hero" style = { { backgroundImage : `url(${ process . env . PUBLIC_URL } /images/stories/border-large.jpg )` } } >
101+ < div className = "dnd-hero" style = { { backgroundImage : `url(${ process . env . PUBLIC_URL } ${ bgImage } )` } } >
48102 < h1 className = "dnd-title-box" >
49103 < span className = "dnd-hero-title-white" > Authors</ span >
50104 </ h1 >
51- < div className = "dnd-content-box" style = { { zIndex : 1 } } >
52- < p > This is the Authors page. Details about authors will be displayed here.</ p >
105+ < div className = "dnd-cards-container" style = { { zIndex : 1 } } >
106+ { authors . map ( ( author , index ) => (
107+ < DndAuthorCard
108+ key = { index }
109+ authorName = { author . name }
110+ authorWebsite = { author . website }
111+ authorImage = { author . image }
112+ authorAlias = { author . alias } // Pass the alias
113+ booksWritten = { getBooksByAuthor ( author . name , author . alias ) }
114+ />
115+ ) ) }
53116 </ div >
54117 </ div >
55118 </ motion . div >
0 commit comments