11import { createContext , useContext , useState , useEffect } from "react" ;
2- import { ISession , ISpeaker } from "@/types/speakers.ts" ;
2+ import { ISession , ISessionInfo , ISpeaker } from "@/types/speakers.ts" ;
33import { getAll } from "@/https/fetch.ts" ;
44import { AppStatus } from "@/types/types.ts" ;
5- import { addSessionSpeakers } from "@/lib/utils.ts" ;
5+ import { addSessionSpeakers , getCategoryNameSessions } from "@/lib/utils.ts" ;
66import { ITimeSlot } from "@/types/agenda.ts" ;
77import ErrorPage from "@/pages/ErrorPage.tsx" ;
88import Loading from "@/pages/Loading.tsx" ;
99
1010
1111interface AppContextType {
1212 speakers : ISpeaker [ ] ;
13- sessions : ISession [ ] ;
13+ sessions : ISessionInfo [ ] ;
1414 agenda : ITimeSlot [ ] ;
1515 appStatus : AppStatus ;
1616 setAgenda : ( agenda : ITimeSlot [ ] ) => void ;
@@ -27,7 +27,7 @@ export const AppProvider = ({ children }) => {
2727 const [ agenda , setAgenda ] = useState < ITimeSlot [ ] > ( [ ] ) ;
2828 const [ appStatus , setAppStatus ] = useState ( AppStatus . Loading ) ;
2929 const [ displayAll , setDisplayAll ] = useState < boolean > ( true ) ;
30- const [ sessions , setSessions ] = useState < ISession [ ] > ( [ ] ) ;
30+ const [ sessions , setSessions ] = useState < ISessionInfo [ ] > ( [ ] ) ;
3131 const [ savedSessions , setSavedSessions ] = useState < Set < number > > ( ( ) => {
3232 const raw = localStorage . getItem ( "savedSessions" ) ;
3333 return raw ? new Set < number > ( JSON . parse ( raw ) ) : new Set < number > ( ) ;
@@ -40,13 +40,14 @@ export const AppProvider = ({ children }) => {
4040 useEffect ( ( ) => {
4141 getAll ( )
4242 . then ( ( data ) => {
43+ const categories = data . categories [ 0 ] . items
4344 const getSpeakersWithSessions = addSessionSpeakers (
4445 data . sessions ,
4546 data . speakers ,
46- data . categories [ 0 ] . items
47+ categories
4748 ) ;
4849 setSpeakers ( getSpeakersWithSessions ) ;
49- setSessions ( data . sessions ) ;
50+ setSessions ( getCategoryNameSessions ( categories , data . sessions ) ) ;
5051 setAppStatus ( AppStatus . Success ) ;
5152 } )
5253 . catch ( ( ) => {
0 commit comments