Update and display talk teasers
One last thing to make the event page complete. The teasers on the page need to show talk teasers and link to associated talks.
Create the talk-lib file
Create the talk-lib.ts file so you have a dedicated function to query talk data.
To create the talk-lib file:
-
In Visual Studio Code, open the starter kit repository and go to the /lib/Events folder.
-
Create a copy of the event-lib.ts file and name it talk-lib.ts.
-
Open this file and modify it as shown in the following table and code sample.
Search for
Change from
Change to
Functions that use
Eventin the title.EventTalkimport Event statementimport Event, {EventResults} from "../../types/Events/event-type";(import Talk, { TalkResults } from "../../types/Events/talk-type";)import EventstatementN/A
import ALL_AGENDA_QUERY, {AGENDA_QUERY} from "../../graphQl/Events/agenda-query";).getAllTalkfunctionPromise Event[]Promise Talk[].getAllTalkfunctionALL_EVENT_QUERYALL_AGENDA_QUERYto pass into the functiongetTalkByIdfunctionPromise EventPromise TalkgetTalkByIdfunctionconst queryEventconst queryTalkgetTalkByIdfunctionawait fetchAPI(queryEvent)await fetchAPI(queryTalk)getAllEventsWithIdsfunctionPromise EventPromise Talk.getAllEventsWithIdsfunctiondata:allEventdata:allTalkgetAllTalksWithIdsfunctionEVENT_QUERYAGENDA_QUERYextractPostsfunctiondata:Eventdata:TalkextractPostsfunctiondata:EventResultsdata:TalkResultsextractPostfunctiondata:Eventdata:Talk -
Remove unused imports for events.
-
Save the file. The final code looks like this.
Create the talkTeaser component file
To create the talkTeaser component file:
-
In Visual Studio Code, open the starter kit repository, make a copy of the /components/Recipe folder and name it Events.
-
Open the Events folder and rename the recipeTeaser-component.tsx file talkTeaser-component.tsx.
-
Open the talkTeaser-component.tsx file and change all mentions of recipe to equivalent mentions of talk.
-
Save the file. The final code looks like this.
Create the talk details page
Create the talk details pages so the talk IDs are passed through the URL and query for data.
To create the talk details page:
-
In Visual Studio Code, open the starter kit repository and go to the /pages folder.
-
Create a copy of the recipes folder and name it talk.
-
Open the /pages/talk/[slug].tsx file.
-
Modify it as follows to create the talk detail pages, changing all instances of recipe to equivalent instances of talk.
Search for
Change from
Change to
import Recipeimport Recipe, {RecipeResults} from "../../types/Recipe/recipe-type";import Talk, {TalkResults} from "../../types/Events/talk-type";import {getRecipeByIdimport {getRecipeById,getAllRecipeWithIds} from "../../lib/Recipe/recipe-lib";import {getTalkById,getAllTalksWithIds} from "../../lib/Events/talk-lib";getStaticPropsfunctionconst recipeconst talkgetStaticPropsfunctionget recidpeByIdgetTalkByIdgetStaticPropsfunctionprops: {recipe,homepage}props: {talk,homepage}getStaticPathsfunctionconst allRecipePostconst allTalksPostgetStaticPathsfunctiongetAllRecipesWithIdsgetAllTalksWithIdsgetStaticPathsfunctionallRecipePosts.map(({ id }) =/recipes/${id})allTalkPosts.map(({ id }) =/talk/${id})propsdefinitionrecipe: Recipetalk: TalkPostpropertyrecipetalktitletagsrecipe?.Titletalk?.talkTitleHeroBannerrecipeImage (recipe?.image?.results[0].fileUrl)talkImage (talk?.image?.results[0].fileUrl)h1tagh1 {recipe?.Title} /h1h1 {talk?.talkTitle} /h1strong Duration: /strong{recipe?.Duration}{talk?.time}strong Ingredients: /strongp strong Ingredients: /strong {recipe?.Ingredients}/pRemove or comment out.
-
Remove
Output DurationandIngredientsas these are not needed. -
Remove the
RichText Componentas this is not needed becausetalkDescriptionis not rich text. -
Add
Talk Data. The final code looks like this.
Update the event.tsx file
To update the event.tsx file:
-
In Visual Studio Code, open the starter kit repository and go to the /pages folder.
-
Open the event.tsx file.
-
Add the line
import TalkTeaserComponent from '../components/Talk/talkTeaser-component';after theimport FooterComponentstatement. -
Add the following lines before the FooterComponent.
RequestResponseTalkTeaserComponent allTalks={event.agenda} / -
Save the file.
-
If the website is not still running locally, run
npm run dev. -
Navigate to
http://localhost:3000/eventto open the event page and see your changes.
The final code should look like this.
Your first foray into Content Hub ONE development is complete! You're now ready to continue your developer journey to build and deliver great applications.