-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #406 from ericsanner/feature/38-speakers-list
Add Speakers component to read data from Sessionize
- Loading branch information
Showing
21 changed files
with
4,348 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3,143 changes: 3,143 additions & 0 deletions
3,143
src/Project/Sugcon2024/Sugcon/public/speakers.html
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
src/Project/Sugcon2024/Sugcon/src/components/List Components/SpeakersGrid.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { Box, Heading, SimpleGrid } from '@chakra-ui/react'; | ||
import { Field, TextField, Text as JssText } from '@sitecore-jss/sitecore-jss-nextjs'; | ||
import { PersonFields, PersonProps, Default as Person } from '../Basic Components/Person'; | ||
import { isEditorActive } from '@sitecore-jss/sitecore-jss-nextjs/utils'; | ||
import * as cheerio from 'cheerio'; | ||
|
||
// Define the type of props that People Grid will accept | ||
interface Fields { | ||
/** Headline */ | ||
Headline: TextField; | ||
|
||
/** Sessions List Title */ | ||
SessionsListTitle: Field<string>; | ||
|
||
/** Url for sessionize speaker data */ | ||
SessionizeSpeakerUrl: Field<string>; | ||
} | ||
|
||
// Define the type of props for an Person | ||
interface PersonItem { | ||
/** Display name of the person item */ | ||
displayName: string; | ||
|
||
/** The details of a person */ | ||
fields: PersonFields; | ||
|
||
/** The item id of the person item */ | ||
id: string; | ||
|
||
/** Name of the person item */ | ||
name: string; | ||
|
||
/** Url of the person item */ | ||
url: string; | ||
} | ||
|
||
export type PeopleGridProps = { | ||
params: { [key: string]: string }; | ||
fields: Fields; | ||
}; | ||
|
||
function getPeople(sessionTitle: string, body: string) { | ||
const people: Array<PersonItem> = []; | ||
const $ = cheerio.load(body); | ||
|
||
const speakers = $('.sz-speaker--full'); | ||
for (let i = 0; i < speakers.length; i++) { | ||
const image = $('.sz-speaker__photo img', speakers[i])[0]; | ||
const name = $('.sz-speaker__name', speakers[i]).text(); | ||
const tagline = $('.sz-speaker__tagline', speakers[i]).text().trim(); | ||
let bio = $('.sz-speaker__bio', speakers[i]).text(); | ||
const sessions = $('.sz-speaker__sessions li a', speakers[i]); | ||
|
||
if (sessions.length > 0) { | ||
bio = bio.concat('<h4>' + sessionTitle + '</h4>'); | ||
bio = bio.concat('<ul>'); | ||
|
||
sessions.each((_i, el) => { | ||
bio = bio.concat('<li>' + $(el).text() + '</li>'); | ||
}); | ||
|
||
bio = bio.concat('</ul>'); | ||
} | ||
|
||
const prsn: PersonItem = { | ||
displayName: name, | ||
fields: { | ||
Twitter: { value: {} }, | ||
Company: { | ||
value: '', | ||
}, | ||
Name: { | ||
value: name, | ||
}, | ||
JobRole: { | ||
value: tagline, | ||
}, | ||
Biography: { | ||
value: bio, | ||
}, | ||
Linkedin: { value: {} }, | ||
Image: { | ||
value: { | ||
src: image.attribs.src, | ||
alt: image.attribs.alt, | ||
width: '400', | ||
height: '400', | ||
}, | ||
}, | ||
}, | ||
id: '', | ||
name: name, | ||
url: '', | ||
}; | ||
|
||
people.push(prsn); | ||
} | ||
|
||
return people; | ||
} | ||
|
||
export const Default = (props: PeopleGridProps): JSX.Element => { | ||
const styles = props.params && props.params.Styles ? props.params.Styles : ''; | ||
const cols = props.params && props.params.Columns ? parseInt(props.params.Columns) : 4; | ||
|
||
const [people, setPeople] = useState(Array<PersonItem>); | ||
|
||
useEffect(() => { | ||
fetch(props.fields.SessionizeSpeakerUrl?.value) | ||
.then((response) => { | ||
if (response.ok) { | ||
return response.text(); | ||
} else { | ||
throw response; | ||
} | ||
}) | ||
.then((data) => { | ||
setPeople(getPeople(props.fields.SessionsListTitle?.value, data)); | ||
}) | ||
.catch((error) => { | ||
console.log('Error fetching data: ' + error); | ||
}); | ||
}); | ||
|
||
if (props.params && props.params.Alphabetize == '1') { | ||
people.sort((a, b) => (a.fields?.Name?.value + '' > b.fields?.Name?.value + '' ? 1 : -1)); | ||
} | ||
|
||
return ( | ||
<Box w="100%" mt={20} className={styles}> | ||
<Box w="80%" pt={10} m="auto"> | ||
{(isEditorActive() || props.fields?.Headline?.value !== '') && ( | ||
<Heading as="h2" size="lg"> | ||
<JssText field={props.fields.Headline} /> | ||
</Heading> | ||
)} | ||
<SimpleGrid columns={{ base: 1, md: cols }} mt={10}> | ||
{people.map((person, idx) => { | ||
const pp: PersonProps = { | ||
params: props.params, | ||
fields: person.fields, | ||
}; | ||
return <Person key={idx} {...pp}></Person>; | ||
})} | ||
</SimpleGrid> | ||
</Box> | ||
</Box> | ||
); | ||
}; |
37 changes: 37 additions & 0 deletions
37
src/Project/Sugcon2024/Sugcon/src/stories/components/List Components/SpeakerGrid.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { Default as SpeakersGrid } from '../../../components/List Components/SpeakersGrid'; | ||
import '../../../assets/sass/components/people-grid/index.scss'; | ||
const meta = { | ||
title: 'Components/SpeakersGrid', | ||
component: SpeakersGrid, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['autodocs'], | ||
argTypes: {}, | ||
} satisfies Meta<typeof SpeakersGrid>; | ||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
export const Teaser: Story = { | ||
name: 'Speakers Grid', | ||
args: { | ||
params: { | ||
Columns: '4', | ||
Alphabetize: '1', | ||
LinkToBio: '1', | ||
DisplaySocialLinks: '0', | ||
Styles: '', | ||
}, | ||
fields: { | ||
Headline: { | ||
value: 'Speakers', | ||
}, | ||
SessionsListTitle: { | ||
value: 'Sessions', | ||
}, | ||
SessionizeSpeakerUrl: { | ||
value: '/speakers.html', | ||
}, | ||
}, | ||
}, | ||
}; |
31 changes: 31 additions & 0 deletions
31
src/Project/Sugcon2024/items/SiteEU/EU/Data/Speakers Grid.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
ID: "7025d00d-feca-479b-8458-e28b3e7e5943" | ||
Parent: "968dab46-6eda-4775-8a0f-85037e2d92f2" | ||
Template: "cfa6fba3-8317-4494-8e61-2f7f2c19e369" | ||
Path: /sitecore/content/Sugcon2024/EU/Data/Speakers Grid | ||
Languages: | ||
- Language: en | ||
Versions: | ||
- Version: 1 | ||
Fields: | ||
- ID: "25bed78c-4957-4165-998a-ca1b52f67497" | ||
Hint: __Created | ||
Value: 20240314T134853Z | ||
- ID: "52807595-0f8f-4b20-8d2a-cb71d28c6103" | ||
Hint: __Owner | ||
Value: | | ||
sitecore\UOUBIWQRx7 | ||
- ID: "5dd74568-4d4b-44c1-b513-0af5f4cda34f" | ||
Hint: __Created by | ||
Value: | | ||
sitecore\UOUBIWQRx7 | ||
- ID: "8cdc337e-a112-42fb-bbb4-4143751e123f" | ||
Hint: __Revision | ||
Value: "6746a675-9d3f-41c0-bf66-59ef73cc886e" | ||
- ID: "badd9cf9-53e0-4d0c-bcc0-2d784c282f6a" | ||
Hint: __Updated by | ||
Value: | | ||
sitecore\UOUBIWQRx7 | ||
- ID: "d9cf14b1-fa16-4ba6-9288-e8a174d4d522" | ||
Hint: __Updated | ||
Value: 20240314T134853Z |
31 changes: 31 additions & 0 deletions
31
src/Project/Sugcon2024/items/SiteShared/Shared/Data/Speakers Grid.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
ID: "ed2f5f2f-88d6-4b45-a8b4-85456d32c9b1" | ||
Parent: "0c5c8db1-5dc6-4a54-a232-750f004bfb84" | ||
Template: "cfa6fba3-8317-4494-8e61-2f7f2c19e369" | ||
Path: /sitecore/content/Sugcon2024/Shared/Data/Speakers Grid | ||
Languages: | ||
- Language: en | ||
Versions: | ||
- Version: 1 | ||
Fields: | ||
- ID: "25bed78c-4957-4165-998a-ca1b52f67497" | ||
Hint: __Created | ||
Value: 20240314T134829Z | ||
- ID: "52807595-0f8f-4b20-8d2a-cb71d28c6103" | ||
Hint: __Owner | ||
Value: | | ||
sitecore\UOUBIWQRx7 | ||
- ID: "5dd74568-4d4b-44c1-b513-0af5f4cda34f" | ||
Hint: __Created by | ||
Value: | | ||
sitecore\UOUBIWQRx7 | ||
- ID: "8cdc337e-a112-42fb-bbb4-4143751e123f" | ||
Hint: __Revision | ||
Value: "9ebd26ef-b707-4edd-a26a-4c76010132e0" | ||
- ID: "badd9cf9-53e0-4d0c-bcc0-2d784c282f6a" | ||
Hint: __Updated by | ||
Value: | | ||
sitecore\UOUBIWQRx7 | ||
- ID: "d9cf14b1-fa16-4ba6-9288-e8a174d4d522" | ||
Hint: __Updated | ||
Value: 20240314T134829Z |
Oops, something went wrong.