Skip to content

Commit

Permalink
feat: connect rating with backend
Browse files Browse the repository at this point in the history
  • Loading branch information
qamarq authored Jan 6, 2025
1 parent 9cbbe34 commit 5628eec
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions frontend/src/app/plans/edit/[id]/page.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ export function CreateNewPlanPage({
.join(":"),
spotsOccupied: g.spotsOccupied,
spotsTotal: g.spotsTotal,
averageRating: g.averageRating,
}) satisfies ExtendedGroup,
),
}))
Expand Down
20 changes: 12 additions & 8 deletions frontend/src/components/class-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function ClassBlock({
isDisabled,
spotsOccupied,
spotsTotal,
averageRating,
onClick,
isReadonly = false,
}: {
Expand All @@ -49,14 +50,14 @@ export function ClassBlock({
courseType: "C" | "L" | "P" | "S" | "W";
isChecked: boolean;
isDisabled: boolean;
isReadonly?: boolean;
spotsOccupied: number;
spotsTotal: number;
averageRating: number;
onClick: () => void;
isReadonly?: boolean;
}) {
const position = calculatePosition(startTime, endTime);
const [startGrid, durationSpan] = position;
const randomRating = Math.random() * 5;
return (
<button
suppressHydrationWarning={true}
Expand All @@ -81,23 +82,26 @@ export function ClassBlock({
<div className="flex w-full justify-between">
<div className="flex gap-1">
<p>{`${courseType} ${week === "" ? "" : `|${week}`}`}</p>
<StarsRating rating={randomRating} />
<StarsRating rating={averageRating} />
</div>
<p>{`Grupa ${groupNumber}`}</p>
</div>
<p className="truncate font-bold">{courseName}</p>
<p className="truncate font-semibold">{lecturer}</p>
<p className="mt-2 flex w-full justify-between truncate">
Miejsca:
<span className="font-bold">
Dostępne miejsca:
<span
className={cn(
"font-bold",
spotsOccupied >= spotsTotal ? "text-red-500" : null,
)}
>
{spotsOccupied}/{spotsTotal}
</span>
</p>
<p className="flex w-full justify-between truncate">
Średnia ocena:
<span className="font-bold">
{randomRating.toFixed(1)} (1200 opinii)
</span>
<span className="font-bold">{averageRating}</span>
</p>
</button>
);
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/class-schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ function ClassSchedule({
g.courseId === block.courseId &&
g.courseType === block.courseType,
);

return (
<ClassBlock
isReadonly={isReadonly}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ClassBlockProps {
registrationId: string;
spotsOccupied: number;
spotsTotal: number;
averageRating: number;
}

export interface Registration {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/utils/update-local-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const updateLocalPlan = async (
startTime: g.startTime.split(":").slice(0, 2).join(":"),
spotsOccupied: g.spotsOccupied,
spotsTotal: g.spotsTotal,
averageRating: g.averageRating,
}));
return {
id: c.id,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export type CourseType = {
courseId: string;
spotsOccupied: number;
spotsTotal: number;
averageRating: number;
createdAt: string;
updatedAt: string;
}[];
Expand Down

0 comments on commit 5628eec

Please sign in to comment.