Skip to content

Commit 96f39bb

Browse files
committed
fix: sorted ascending order
1 parent 327c192 commit 96f39bb

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

frontend/src/pages/scheduling.jsx

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ const parseSlotId = (iid) => {
1010
panel: panel.replace("P", ""),
1111
round: Number(round.replace("R", ""))
1212
};
13+
14+
15+
};
16+
const getStartTime = (slot) => {
17+
return slot.time_slot.split(" - ")[0];
1318
};
1419

1520
export default function Scheduling() {
@@ -116,12 +121,29 @@ export default function Scheduling() {
116121
return dateMatch && panelMatch;
117122
});
118123

119-
const groupedSlots = filteredSlots.reduce((acc, slot) => {
120-
const { date } = parseSlotId(slot.iid);
121-
if (!acc[date]) acc[date] = [];
122-
acc[date].push(slot);
123-
return acc;
124-
}, {});
124+
const groupedSlots = filteredSlots.reduce((acc, slot) => {
125+
const { date } = parseSlotId(slot.iid);
126+
if (!acc[date]) acc[date] = [];
127+
acc[date].push(slot);
128+
return acc;
129+
}, {});
130+
//sorting by time n panel for ez view
131+
Object.keys(groupedSlots).forEach((date) => {
132+
groupedSlots[date].sort((a, b) => {
133+
const timeA = getStartTime(a);
134+
const timeB = getStartTime(b);
135+
136+
if (timeA !== timeB) {
137+
return timeA.localeCompare(timeB);
138+
}
139+
140+
const panelA = Number(parseSlotId(a.iid).panel);
141+
const panelB = Number(parseSlotId(b.iid).panel);
142+
143+
return panelA - panelB;
144+
});
145+
});
146+
125147

126148
const sortedDates = Object.keys(groupedSlots).sort();
127149

0 commit comments

Comments
 (0)