Skip to content

Commit

Permalink
feat(Sats): use waitlist count for class popularity
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Apr 1, 2024
1 parent 5a1af72 commit a0878fd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/schedule/class/ClassCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ const ClassCard = ({
</Badge>
</Tooltip>
) : (
_class.totalSlots !== null && (
(_class.totalSlots !== null || (_class.isBookable && _class.waitingListCount !== null)) && (
<ClassPopularityMeter _class={_class} historicPopularity={popularity} />
)
)}
Expand Down
4 changes: 3 additions & 1 deletion src/components/schedule/class/ClassPopularityMeter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ const ClassPopularityMeter = ({
if (_class.isBookable) {
return (
<Tooltip
title={"Påmelding for denne timen har åpnet. " + stringifyClassPopularity(_class, historicPopularity)}
title={
"Påmelding for denne timen har åpnet. " + stringifyClassPopularity(_class, historicPopularity) ?? ""
}
>
<RippleBadge
invisible={isClassInThePast(_class)}
Expand Down
15 changes: 13 additions & 2 deletions src/lib/helpers/popularity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import { RezervoClass, RezervoWeekSchedule } from "@/types/chain";
import { ClassPopularity, ClassPopularityIndex } from "@/types/popularity";

export function determineClassPopularity(_class: RezervoClass) {
if (!_class || _class.availableSlots === undefined) return ClassPopularity.Unknown;
if (!_class || _class.availableSlots === null || _class.totalSlots === null) {
if (_class.waitingListCount != null) {
if (_class.waitingListCount == 0) {
return ClassPopularity.Low;
}
return ClassPopularity.High;
}
return ClassPopularity.Unknown;
}
if (_class.availableSlots <= 0) return ClassPopularity.High;
if (_class.availableSlots / _class.totalSlots <= 0.2) return ClassPopularity.Medium;
return ClassPopularity.Low;
Expand All @@ -23,9 +31,12 @@ export function createClassPopularityIndex(previousWeekSchedule: RezervoWeekSche
);
}

export function stringifyClassPopularity(_class: RezervoClass, historicPopularity: ClassPopularity): string {
export function stringifyClassPopularity(_class: RezervoClass, historicPopularity: ClassPopularity): string | null {
let classPopularityInfo: string;
const isInThePast = isClassInThePast(_class);
if (_class.availableSlots === null || _class.totalSlots === null) {
return null;
}
const numberOfAttendees = _class.totalSlots - Math.max(_class.availableSlots, 0);

if (isInThePast) {
Expand Down
4 changes: 2 additions & 2 deletions src/types/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export type RezervoClassBase = {
isBookable: boolean;
isCancelled: boolean;
cancelText: string | null;
totalSlots: number;
availableSlots: number;
totalSlots: number | null;
availableSlots: number | null;
waitingListCount: number | null;
activity: RezervoActivity;
instructors: RezervoInstructor[];
Expand Down

0 comments on commit a0878fd

Please sign in to comment.