Skip to content

Commit

Permalink
fix: small layout issues
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelblijleven committed Jun 12, 2023
1 parent fa46329 commit af6f7ed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/app/beanconqueror/components/backlog-stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default function BacklogStats(props: BacklogStatsProps) {
<CardTitle>{props.label}</CardTitle>
</CardHeader>
<CardContent>
<BacklogTable beans={beans} usage={props.usage} />
{!beans.length && "Uh-oh, you've seem to have run out beans"}
{!!beans.length && <BacklogTable beans={beans} usage={props.usage} />}
</CardContent>
</Card>
)
Expand Down
23 changes: 21 additions & 2 deletions src/app/beanconqueror/components/card-stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Bean} from "@/types/beanconqueror";
import ProgressBar from "@/components/progress-bar";
import {Card, CardContent, CardHeader, CardTitle} from "@/components/ui/card";
import {Mapping} from "@/types";
import {cn} from "@/lib/utils";

interface Props {
averageWeight: number;
Expand All @@ -18,11 +19,12 @@ interface StatsProps {
label: string;
value: string;
progress?: number | null;
className?: string | null;
}

function Stats(props: StatsProps) {
return (
<Card>
<Card className={cn(props.className, "flex flex-col justify-between")}>
<CardHeader>
<CardTitle className={"text-sm font-medium"}>{props.label}</CardTitle>
</CardHeader>
Expand Down Expand Up @@ -58,6 +60,18 @@ function getRemainingWeight(mapping: Mapping<Bean>, usage: Mapping<number>): num
return remainingWeight;
}

function getRemainingWeightWarningClassName(remainingWeight: number): string | null {
if (remainingWeight >= 100) return null;

const baseShadow = "shadow-md"

if (remainingWeight >= 50) return cn(baseShadow, "shadow-amber-600");
if (remainingWeight >= 20) return cn(baseShadow, "shadow-orange-600");

return cn(baseShadow, "shadow-red-600");

}

export default function CardStats(props: Props) {
const averageWeight = props.averageWeight;
const averageBrewsPerDay = props.averageBrewsPerDay;
Expand All @@ -81,7 +95,12 @@ export default function CardStats(props: Props) {
{averageBrewsPerDay && <Stats label={"Avg. brews per day"} value={averageBrewsPerDay.toFixed(2)} />}
{totalBrews && <Stats label={"Total brews"} value={totalBrews} />}
{props.totalGroundBeans && <Stats label={"Total ground beans"} value={totalGroundBeansText} />}
{remainingWeight && <Stats label={"Remaining bean weight"} value={`${remainingWeight.toFixed(2)} gr`} progress={estimatedRemainingWeight} />}
<Stats
label={"Remaining bean weight"}
value={`${remainingWeight.toFixed(2)} gr`}
progress={estimatedRemainingWeight}
className={getRemainingWeightWarningClassName(remainingWeight)}
/>
{props.lastBrew && <Stats label={"Last brew"} value={timeSinceLastCoffee} />}
</div>
)
Expand Down

0 comments on commit af6f7ed

Please sign in to comment.