Skip to content

Commit b45de9f

Browse files
authored
Merge pull request #240 from posadev/add-sala
feat: add sala name
2 parents 0a3e381 + 45dc26b commit b45de9f

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

src/components/session/SessionCard.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import {ISessionInfo} from "@/types/sessions.ts";
66

77
interface SessionCardProps {
88
session: ISessionInfo
9+
room?: string
910
}
1011

11-
const SessionCard: React.FC<SessionCardProps> = ({session}) => {
12+
const SessionCard: React.FC<SessionCardProps> = ({session, room}) => {
1213
const category = session.category
1314
const startTime = new Date(session.startsAt).toLocaleTimeString(["en-US"], {hour: '2-digit', minute:'2-digit'})
1415
const endTime = new Date(session.endsAt).toLocaleTimeString(["en-US"], {hour: '2-digit', minute:'2-digit'})
@@ -20,9 +21,12 @@ const SessionCard: React.FC<SessionCardProps> = ({session}) => {
2021
<h3 className="text-2xl text-gray-700 font-semibold">
2122
{session.title}
2223
</h3>
23-
{ startTime && endTime &&
24-
<h1 className="text-lg font-bold text-alternative-700"><time dateTime={startTime}>{startTime}</time> <span aria-label="a">-</span> <time dateTime={endTime}>{endTime}</time></h1>
25-
}
24+
<aside className="flex flex-col gap-2" aria-label="Sala y hora" role="group">
25+
<h1 className="text-lg font-bold text-alternative-700">Sala: {room}</h1>
26+
{ startTime && endTime &&
27+
<h1 className="text-lg font-bold text-alternative-700"><time dateTime={startTime}>{startTime}</time> <span aria-label="a">-</span> <time dateTime={endTime}>{endTime}</time></h1>
28+
}
29+
</aside>
2630
<span className="text-lg text-primary-600 font-semibold">Descripción</span>
2731
<p className="text-lg text-gray-700">{session.description}</p>
2832
<CardFooter className="p-0">

src/components/session/SessionTracks.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,30 @@ import {Speech} from "lucide-react";
55
import {Badge} from "@/components/ui/badge.tsx";
66
import {formatTiemstamp} from "@/lib/utils.ts";
77
import {ISessionInfo} from "@/types/sessions.ts";
8+
import {IRoom} from "@/types/speakers.ts";
89

910
interface SessionTracksProps {
1011
currentSession?: ISessionInfo
1112
sessions: ISessionInfo[]
1213
category: string
14+
rooms: IRoom[]
1315
}
1416

15-
const SessionTracks: React.FC<SessionTracksProps> = ({sessions, category, currentSession}) => {
17+
const SessionTracks: React.FC<SessionTracksProps> = ({sessions, category, currentSession, rooms}) => {
1618
const tracks = sessions.filter(session => session.category === category && session.id !== currentSession.id);
19+
20+
const findRoomName = (id: string) => {
21+
return rooms.find(room => room.id === Number(id)).name
22+
}
23+
1724
return (
1825
<Card className="py-8 px-6 flex flex-col gap-6 md:gap-8">
1926
<Badge variant="alternative" className="flex gap-2"><Speech/> Charlas de {category}</Badge>
2027
<div className="grid md:grid-cols-[repeat(auto-fit,minmax(300px,1fr))] gap-6 w-full h-full">
2128
{
2229
tracks.map(session => (
2330
<article className="flex flex-col gap-y-2 h-full" key={`track-${session.id}`}>
31+
<h3 className="text-xl font-bold text-alternative-700 px-2">Sala: {findRoomName(session.roomId)}</h3>
2432
<h3 className="text-xl font-bold text-alternative-700 px-2 flex gap-2">
2533
<time>{formatTiemstamp(session.startsAt)}</time>
2634
<span aria-label="a">-</span>

src/components/speakers/SpeakerInfo.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ import Shared from "@/components/Shared.tsx";
1111
import Loading from "@/pages/Loading.tsx";
1212
import SessionCard from "@/components/session/SessionCard.tsx";
1313
import SessionTracks from "@/components/session/SessionTracks.tsx";
14+
import {ISession} from "@/types/sessions.ts";
1415

1516
const SpeakerInfo = () => {
1617
const navigate = useNavigate()
1718
const location = useLocation();
1819
const { speakerId } = useParams();
19-
const { speakers, sessions } = useAppContext();
20+
const { speakers, sessions, rooms } = useAppContext();
2021
const speaker = location.state?.speaker as ISpeaker;
2122
const [currentSpeaker, setCurrentSpeaker] = useState<ISpeaker>()
2223
const fullUrl = `${window.location.origin}${location.pathname}${location.search}${location.hash}`;
24+
const getRoomName = (session: ISession) => rooms.find(room => room.id == Number(session.roomId)).name;
2325

2426
useEffect(() => {
2527
scrollToTop()
@@ -78,12 +80,12 @@ const SpeakerInfo = () => {
7880

7981
{
8082
currentSpeaker.sessions.map(session => (
81-
<SessionCard key={session.id} session={session}/>
83+
<SessionCard key={session.id} session={session} room={getRoomName(session)}/>
8284
))
8385
}
8486
</article>
8587
{ currentSpeaker.sessions.length == 1 &&
86-
<SessionTracks currentSession={currentSpeaker.sessions[0]} sessions={sessions} category={currentSpeaker.sessions[0].category} />
88+
<SessionTracks currentSession={currentSpeaker.sessions[0]} sessions={sessions} category={currentSpeaker.sessions[0].category} rooms={rooms} />
8789
}
8890
</Gradient>
8991
)

src/context/AppContext.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createContext, useContext, useState, useEffect } from "react";
2-
import { ISpeaker} from "@/types/speakers.ts";
2+
import {IRoom, ISpeaker} from "@/types/speakers.ts";
33
import {getAll} from "@/https/fetch.ts";
44
import {AppStatus} from "@/types/types.ts";
55
import {addInformationToSession, addSessionSpeakers} from "@/lib/utils.ts";
@@ -20,6 +20,7 @@ interface AppContextType {
2020
setSavedSessions: (sessions: Set<number>) => void;
2121
displayAll: boolean;
2222
setDisplayAll: (displayAll: boolean) => void;
23+
rooms: IRoom[];
2324
}
2425

2526
const AppContext = createContext(null);
@@ -30,6 +31,7 @@ export const AppProvider = ({ children }) => {
3031
const [appStatus, setAppStatus] = useState(AppStatus.Loading);
3132
const [displayAll, setDisplayAll] = useState<boolean>(true);
3233
const [sessions, setSessions] = useState<ISessionInfo[]>([]);
34+
const [rooms, setRooms] = useState<IRoom[]>([]);
3335
const [error, setError] = useState<Error>(null)
3436
const [savedSessions, setSavedSessions] = useState<Set<number>>(() => {
3537
const raw = localStorage.getItem("savedSessions");
@@ -49,6 +51,7 @@ export const AppProvider = ({ children }) => {
4951
sessionsInfo,
5052
speakers
5153
);
54+
setRooms(rooms);
5255
setSpeakers(getSpeakersWithSessions);
5356
setSessions(sessionsInfo);
5457
setAppStatus(AppStatus.Success);
@@ -69,7 +72,8 @@ export const AppProvider = ({ children }) => {
6972
speakers,
7073
agenda,
7174
appStatus,
72-
setAppStatus
75+
setAppStatus,
76+
rooms
7377
};
7478

7579
return (

src/pages/SessionPage.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import SessionTracks from "@/components/session/SessionTracks.tsx";
99

1010
const SessionPage = () => {
1111
const navigate = useNavigate()
12-
const {sessions} = useAppContext()
12+
const {sessions, rooms} = useAppContext()
1313
const { sessionId } = useParams();
1414
const session = sessions.find(session => session.id == Number(sessionId))
15+
const getRoom = rooms.find(room => room.id === Number(session?.roomId)).name
1516

1617
const handleGoBack = () => {
1718
if (window.history.length > 1){
@@ -48,8 +49,8 @@ const SessionPage = () => {
4849
{window.history.length > 1 ? "Volver atras" : "Volver a la agenda"}
4950
</span>
5051
</button>
51-
<SessionCard session={session} />
52-
<SessionTracks sessions={sessions} category={session.category} currentSession={session}/>
52+
<SessionCard session={session} room={getRoom} />
53+
<SessionTracks sessions={sessions} category={session.category} currentSession={session} rooms={rooms}/>
5354
</Gradient>
5455
)
5556
}

0 commit comments

Comments
 (0)