Skip to content

Commit 9d0fb4b

Browse files
authored
Select rooms by slug (#15)
1 parent 4bea4ca commit 9d0fb4b

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/components/schedule/EventList.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface IGroupHeaderProps {
1818
index: number;
1919
}
2020

21-
const getRoomName = () => {
21+
const getRoomSlug = () => {
2222
const urlParams = new URLSearchParams(window.location.search);
2323
return urlParams.get('room');
2424
};
@@ -40,10 +40,11 @@ const EventList = () => {
4040
const error = useSelector(selectError);
4141
const schedule = useSelector(selectSchedule);
4242
const dispatch = useDispatch();
43+
// Room slug
4344
const [room, setRoom] = useState<string | null>(null);
4445

4546
const fetchData = useCallback(async () => {
46-
const selectedRoom = getRoomName();
47+
const selectedRoom = getRoomSlug();
4748
setRoom(selectedRoom);
4849
dispatch(getScheduleAsync(selectedRoom));
4950
}, [dispatch]);

src/reducer/schedulesSlice.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export const scheduleSlice = createSlice({
122122
}
123123
});
124124

125-
export const getScheduleAsync = debounceAction((roomName: string): AppThunk => {
125+
export const getScheduleAsync = debounceAction((roomSlug: string): AppThunk => {
126126
return async (dispatch: any) => {
127127
dispatch(scheduleSlice.actions.setIsLoading(true));
128128
try {
@@ -140,7 +140,7 @@ export const getScheduleAsync = debounceAction((roomName: string): AppThunk => {
140140
// Build up a map of events by day
141141
for (const dayElement of dom.querySelectorAll('day').values()) {
142142
const dateOfDay = dayElement.attributes.getNamedItem('date')?.nodeValue as string;
143-
const eventsOfDay = mapEvents(dayElement.querySelectorAll(`room${roomName ? `[name='${roomName}']` : ''} event`), dateOfDay);
143+
const eventsOfDay = mapEvents(dayElement.querySelectorAll(`room${roomSlug ? `[slug='${roomSlug}']` : ''} event`), dateOfDay);
144144
events[dateOfDay] = eventsOfDay;
145145
}
146146

0 commit comments

Comments
 (0)