From 3e0f5e863fdf019cbf8186fd753e830758036fc2 Mon Sep 17 00:00:00 2001 From: esummins Date: Thu, 23 May 2024 12:35:58 -0700 Subject: [PATCH] Add CC Room progress indicators --- src/components/ui/accordion.tsx | 17 +++++++++--- src/components/ui/progress.tsx | 47 +++++++++++++++++++-------------- src/pages/bundles.tsx | 32 ++++++++++++++++++---- 3 files changed, 67 insertions(+), 29 deletions(-) diff --git a/src/components/ui/accordion.tsx b/src/components/ui/accordion.tsx index 53619342..925872de 100644 --- a/src/components/ui/accordion.tsx +++ b/src/components/ui/accordion.tsx @@ -20,20 +20,29 @@ AccordionItem.displayName = "AccordionItem"; const AccordionTrigger = React.forwardRef< React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, children, ...props }, ref) => ( + React.ComponentPropsWithoutRef & { + pullRight?: React.ReactNode; + } +>(({ className, children, pullRight, ...props }, ref) => ( svg]:rotate-180", + "flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all [&[data-state=open]>*>svg]:rotate-180 [&[data-state=open]>svg]:rotate-180", className, )} {...props} > {children} - + {pullRight ? ( +
+ {pullRight} + +
+ ) : ( + + )}
)); diff --git a/src/components/ui/progress.tsx b/src/components/ui/progress.tsx index c2b867ac..4910fccb 100644 --- a/src/components/ui/progress.tsx +++ b/src/components/ui/progress.tsx @@ -1,26 +1,33 @@ -import * as React from "react" -import * as ProgressPrimitive from "@radix-ui/react-progress" +import * as React from "react"; +import * as ProgressPrimitive from "@radix-ui/react-progress"; -import { cn } from "@/lib/utils" +import { cn } from "@/lib/utils"; const Progress = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef ->(({ className, value, ...props }, ref) => ( - - - -)) -Progress.displayName = ProgressPrimitive.Root.displayName +>(({ className, value, max, ...props }, ref) => ( +
+ + + + + {value && max ? `${value} / ${max}` : ``} + +
+)); +Progress.displayName = ProgressPrimitive.Root.displayName; -export { Progress } +export { Progress }; diff --git a/src/pages/bundles.tsx b/src/pages/bundles.tsx index c547545a..408d0bc3 100644 --- a/src/pages/bundles.tsx +++ b/src/pages/bundles.tsx @@ -70,6 +70,7 @@ type BundleAccordionProps = { type AccordionSectionProps = { title: string; children: JSX.Element | JSX.Element[]; + completedCount?: number; }; const CommunityCenterRooms: CommunityCenterRoomName[] = [ @@ -83,11 +84,26 @@ const CommunityCenterRooms: CommunityCenterRoomName[] = [ ]; function AccordionSection(props: AccordionSectionProps): JSX.Element { + let progressIndicator = + props.completedCount && + Array.isArray(props.children) && + props.completedCount < props.children.length ? ( + + ) : ( + `` + ); return (
- + {props.title} @@ -193,9 +209,6 @@ function BundleAccordion(props: BundleAccordionProps): JSX.Element { max={requiredItems} className="w-32" /> - - {requiredItems - remainingCount} / {requiredItems} - )} @@ -551,6 +564,7 @@ export default function Bundles() { {CommunityCenterRooms.map((roomName: CommunityCenterRoomName) => { let roomBundles: BundleWithStatus[] = []; + let completedCount = 0; if (activePlayer && Array.isArray(activePlayer.bundles)) { roomBundles = activePlayer.bundles.filter((bundleWithStatus) => { if (bundleWithStatus?.bundle) { @@ -559,6 +573,10 @@ export default function Bundles() { return false; } }); + completedCount = roomBundles.reduce((acc, curBundelRet) => { + if (BundleCompleted(curBundelRet)) return acc + 1; + return acc; + }, 0); } else { roomBundles = bundles.filter( (bundleWithStatus) => @@ -566,7 +584,11 @@ export default function Bundles() { ); } return ( - + {roomBundles.map((bundleWithStatus: BundleWithStatus) => { return (