Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | 610x 1104x 7395x 7395x 1104x 610x 1976x 1976x 610x 420x 80x 420x 610x 26x 26x 1x 25x 610x 1016x 990x 26x 26x 1x 25x 610x 425x 75x 425x 610x 425x 7x 425x | import { addHours, isAfter } from "date-fns";
import { config } from "shared/config";
import { ProgramItem } from "shared/types/models/programItem";
import {
getDirectSignupEndTime,
getProgramItemStartTime,
} from "shared/utils/signupTimes";
import { isSameOrAfter } from "shared/utils/timeComparison";
import { GroupMemberWithLotteryProgramItem } from "client/views/group/groupSlice";
import {
DirectSignupWithProgramItem,
LotterySignupWithProgramItem,
} from "client/views/my-program-items/myProgramItemsSlice";
export const getUpcomingProgramItems = (
programItems: readonly ProgramItem[],
timeNow: Date,
): readonly ProgramItem[] => {
const upcomingProgramItems = programItems.filter((programItem) => {
const directSignupEndTime = getDirectSignupEndTime(programItem);
return isSameOrAfter(directSignupEndTime, timeNow);
});
return upcomingProgramItems;
};
// Before this time only pre-convention week program is shown in the program list
export const isMainEventProgramVisible = (timeNow: Date): boolean => {
const { mainEventProgramVisibleTime } = config.event();
return (
!mainEventProgramVisibleTime ||
isSameOrAfter(timeNow, new Date(mainEventProgramVisibleTime))
);
};
// A lottery sign-up belongs to the run it was entered into, so a batched one stops being upcoming
// an hour after the batch was lotteried rather than an hour after its own program item
const getUpcomingLotterySignups = (
lotterySignups: readonly LotterySignupWithProgramItem[],
timeNow: Date,
): readonly LotterySignupWithProgramItem[] => {
const upcomingLotterySignups = lotterySignups.filter((lotterySignup) => {
return isAfter(
addHours(new Date(getProgramItemStartTime(lotterySignup.programItem)), 1),
timeNow,
);
});
return upcomingLotterySignups;
};
const getGroupCreator = (
groupMembers: readonly GroupMemberWithLotteryProgramItem[],
): GroupMemberWithLotteryProgramItem | null => {
const groupCreator = groupMembers.find((member) => member.isGroupCreator);
if (!groupCreator) {
return null;
}
return groupCreator;
};
interface GetLotterySignupsParams {
lotterySignups: readonly LotterySignupWithProgramItem[];
isGroupCreator: boolean;
groupMembers: readonly GroupMemberWithLotteryProgramItem[];
isInGroup: boolean;
showAllProgramItems: boolean;
timeNow: Date;
}
export const getLotterySignups = ({
lotterySignups,
isGroupCreator,
groupMembers,
isInGroup,
showAllProgramItems,
timeNow,
}: GetLotterySignupsParams): readonly LotterySignupWithProgramItem[] => {
if (isGroupCreator || !isInGroup) {
return showAllProgramItems
? lotterySignups
: getUpcomingLotterySignups(lotterySignups, timeNow);
}
// A group member sees the creator's lottery sign-ups, which are the ones the lottery acts on
const groupCreator = getGroupCreator(groupMembers);
if (!groupCreator) {
return [];
}
return showAllProgramItems
? groupCreator.lotterySignups
: getUpcomingLotterySignups(groupCreator.lotterySignups, timeNow);
};
export const getUpcomingDirectSignups = (
directSignups: readonly DirectSignupWithProgramItem[],
timeNow: Date,
): readonly DirectSignupWithProgramItem[] => {
const upcomingProgramItems = directSignups.filter((directSignup) =>
isAfter(addHours(new Date(directSignup.programItem.startTime), 1), timeNow),
);
return upcomingProgramItems;
};
// A favorite marks a program item the attendee means to be at, so it follows the item's own hour
// rather than the one a batched lottery ran at
export const getUpcomingFavorites = (
favoriteProgramItems: readonly ProgramItem[],
timeNow: Date,
): readonly ProgramItem[] => {
const upcomingProgramItems = favoriteProgramItems.filter(
(favoriteProgramItem) => {
return isAfter(
addHours(new Date(favoriteProgramItem.startTime), 1),
timeNow,
);
},
);
return upcomingProgramItems;
};
|