Skip to content

Commit

Permalink
feat: Adding presentation url (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
langecode authored Dec 10, 2024
2 parents d93354e + 739dad6 commit 53b3d2d
Showing 1 changed file with 118 additions and 89 deletions.
207 changes: 118 additions & 89 deletions src/hooks/use-sessionize.tsx
Original file line number Diff line number Diff line change
@@ -1,115 +1,144 @@
import { useEffect, useState } from "react";
import { useEffect, useState } from 'react';

const SESSIONIZE_ID = "ev751er0"; // TEST ID: jl4ktls0
const SESSIONIZE_ID = 'ev751er0'; // TEST ID: jl4ktls0

export interface Speaker {
id: string;
name: string;
firstName: string;
lastName: string;
fullName: string;
bio: string;
tagLine: string;
profilePicture: string;
isTopSpeaker: boolean;
sessions: Session[];
id: string;
name: string;
firstName: string;
lastName: string;
fullName: string;
bio: string;
tagLine: string;
profilePicture: string;
isTopSpeaker: boolean;
sessions: Session[];
}

export interface Session {
id: string;
name: string;
title: string;
description: string;
startsAt: string;
endsAt: string;
isServiceSession: boolean;
isPlenumSession: boolean;
speakers: Speaker[];
roomId: number;
room: string;
id: string;
name: string;
title: string;
description: string;
startsAt: string;
endsAt: string;
isServiceSession: boolean;
isPlenumSession: boolean;
speakers: Speaker[];
roomId: number;
room: string;
questionAnswers: QuestionAnswer[];
slideDeck: string;
}

export interface QuestionAnswer {
id: number;
answer: string;
}

export interface GridEntry {
date: string;
rooms: Room[];
timeSlots: TimeSlot[];
date: string;
rooms: Room[];
timeSlots: TimeSlot[];
}

export interface Room {
id: number;
name: string;
sessions: Session[];
session: Session;
id: number;
name: string;
sessions: Session[];
session: Session;
}

export interface TimeSlot {
slotStart: string;
rooms: Room[];
slotStart: string;
rooms: Room[];
}

export interface SessionList {
sessions: Session[];
}

export const useSessionizeSpeakers = () => {
const [speakers,setSpeakers] = useState<Speaker[]>([]);
const [speakers, setSpeakers] = useState<Speaker[]>([]);

const fetchSpeakers = async () => {
const response = await fetch(`https://sessionize.com/api/v2/${SESSIONIZE_ID}/view/Speakers`);
const data = await response.json();
setSpeakers(data);
};
const fetchSpeakers = async () => {
const response = await fetch(`https://sessionize.com/api/v2/${SESSIONIZE_ID}/view/Speakers`);
const data = await response.json();
setSpeakers(data);
};

useEffect(() => {
fetchSpeakers();
}, []);
useEffect(() => {
fetchSpeakers();
}, []);

return {speakers};
return { speakers };
};

export const useSessionizeSchedule = () => {
const [grid,setGrid] = useState<GridEntry[]>([]);
const [speakers,setSpeakers] = useState<Speaker[]>([]);
const [schedule,setSchedule] = useState<GridEntry[]>([]);

const fetchGrid = async () => {
const response = await fetch(`https://sessionize.com/api/v2/${SESSIONIZE_ID}/view/Grid`);
const data = await response.json();
setGrid(data);
}

const fetchSpeakers = async () => {
const response = await fetch(`https://sessionize.com/api/v2/${SESSIONIZE_ID}/view/Speakers`);
const data = await response.json();
setSpeakers(data);
};

useEffect(() => {
fetchGrid();
}, []);
useEffect(() => {
fetchSpeakers();
}, []);
useEffect(() => {
if (grid.length === 0 || speakers.length === 0) return;
const schedule = grid.map((entry) => {
const timeSlots = entry.timeSlots.map((timeSlot) => {
const rooms = timeSlot.rooms.map((room) => {
const sessionSpeakers = room.session.speakers.map((speaker) => {
return speakers.find((s) => s.id === speaker.id);
});
room.session.speakers = sessionSpeakers;
return room;
});
return {
...timeSlot,
rooms,
};
});
return {
...entry,
timeSlots,
};
const [grid, setGrid] = useState<GridEntry[]>([]);
const [speakers, setSpeakers] = useState<Speaker[]>([]);
const [schedule, setSchedule] = useState<GridEntry[]>([]);
const [sessions, setSessions] = useState<SessionList[]>([]);

const fetchGrid = async () => {
const response = await fetch(`https://sessionize.com/api/v2/${SESSIONIZE_ID}/view/Grid`);
const data = await response.json();
setGrid(data);
};

const fetchSpeakers = async () => {
const response = await fetch(`https://sessionize.com/api/v2/${SESSIONIZE_ID}/view/Speakers`);
const data = await response.json();
setSpeakers(data);
};

const fetchSessions = async () => {
const response = await fetch(`https://sessionize.com/api/v2/${SESSIONIZE_ID}/view/Sessions`);
const data = await response.json();
setSessions(data);
};

useEffect(() => {
fetchGrid();
}, []);
useEffect(() => {
fetchSpeakers();
}, []);
useEffect(() => {
fetchSessions();
}, []);
useEffect(() => {
if (grid.length === 0 || speakers.length === 0 || sessions.length === 0) return;
const schedule = grid.map((entry) => {
const timeSlots = entry.timeSlots.map((timeSlot) => {
const rooms = timeSlot.rooms.map((room) => {
const sessionSpeakers = room.session.speakers.map((speaker) => {
return speakers.find((s) => s.id === speaker.id);
});
room.session.speakers = sessionSpeakers;

const session = sessions[0].sessions.find((s) => room.session.id === s.id);
if (session !== undefined) {
const qa = session.questionAnswers.find((q) => q.id === 88726);
if (qa !== undefined) {
room.session.slideDeck = qa.answer;
}
}

return room;
});
setSchedule(schedule);
}, [grid,speakers]);


return {schedule};
return {
...timeSlot,
rooms,
};
});
return {
...entry,
timeSlots,
};
});
setSchedule(schedule);
}, [grid, speakers, sessions]);

return { schedule };
};

0 comments on commit 53b3d2d

Please sign in to comment.