Skip to content

Commit

Permalink
Reorder recent schedule list to put most recent on top
Browse files Browse the repository at this point in the history
  • Loading branch information
sjkneisler committed Aug 20, 2024
1 parent 45d3cad commit 0da796a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/src/contexts/ScheduleContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ export const ScheduleContainer: React.FC = () => {
>('recentSchedules', { defaultValue: [] });

useEffect(() => {
if (schedule === null) {
return;
}
if (
schedule !== null &&
!recentScheduleData.some(
([recentScheduleInviteCode]) =>
recentScheduleInviteCode === schedule.inviteCode,
Expand All @@ -85,6 +87,16 @@ export const ScheduleContainer: React.FC = () => {
[schedule.inviteCode, schedule.name],
...recentScheduleData,
];
setRecentScheduleData(newData);
} else {
const newData: [string, string][] = [
[schedule.inviteCode, schedule.name],
...recentScheduleData.filter(
([recentScheduleInviteCode]) =>
recentScheduleInviteCode !== schedule.inviteCode,
),
];

setRecentScheduleData(newData);
}
}, [schedule, recentScheduleData, setRecentScheduleData]);
Expand Down

0 comments on commit 0da796a

Please sign in to comment.