Skip to content

Commit

Permalink
meal cards
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorpfiz committed Jan 19, 2024
1 parent abccaed commit 035cff4
Show file tree
Hide file tree
Showing 15 changed files with 363 additions and 140 deletions.
9 changes: 9 additions & 0 deletions apps/nextjs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ const config = {
"@nourish/validators",
],

images: {
remotePatterns: [
{
protocol: "https",
hostname: "images.unsplash.com",
},
],
},

/** We already do linting and typechecking as separate tasks in CI */
eslint: { ignoreDuringBuilds: true },
typescript: { ignoreBuildErrors: true },
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"date-fns": "^3.2.0",
"geist": "^1.2.0",
"lucide-react": "^0.309.0",
"next": "^14.0.4",
"next": "^14.1.0",
"react": "18.2.0",
"react-chartjs-2": "^5.2.0",
"react-dom": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/_components/auth-showcase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function AuthShowcase() {
}

return (
<div className="flex flex-col items-center justify-center gap-4">
<div className="flex flex-col items-center justify-center gap-4 px-4">
<p className="text-center text-2xl">
{session && <span>Logged in as {session.user.name}</span>}
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AuthShowcase } from "~/app/_components/auth-showcase";
import { MacrosBar } from "~/components/dashboard/macros-bar";
import { MacrosDonut } from "~/components/dashboard/macros-donut";
import { MacrosProgress } from "~/components/dashboard/macros-progress";
import { MealCard } from "~/components/dashboard/meal-card";
import { MealCards } from "~/components/dashboard/meal-cards";
import { MicrosProgress } from "~/components/dashboard/micros-progress";
import { Tabs } from "~/components/dashboard/tabs";
import { TopNavbar } from "~/components/dashboard/top-navbar";
Expand All @@ -17,15 +17,15 @@ export default async function HomePage() {
<TopNavbar />

{/* Content */}
<main className="relative flex h-full w-full flex-1 flex-col items-center gap-2 overflow-auto px-4">
<main className="relative flex h-full w-full flex-1 flex-col items-center gap-2 overflow-y-auto overflow-x-hidden">
{/* Macros donut chart */}
<MacrosDonut />
{/* Macros progress charts */}
<MacrosProgress />
{/* Macros bar chart */}
<MacrosBar />
{/* Meal and snack cards */}
<MealCard />
<MealCards />
{/* Micros progress charts */}
<MicrosProgress />

Expand Down
3 changes: 3 additions & 0 deletions apps/nextjs/src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,8 @@
}
body {
@apply bg-background text-foreground;
/* font-feature-settings: "rlig" 1, "calt" 1; */
font-synthesis-weight: none;
text-rendering: optimizeLegibility;
}
}
2 changes: 1 addition & 1 deletion apps/nextjs/src/components/dashboard/macros-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const MacrosBar = () => {
const chartData = prepareChartData();

return (
<div className="w-full">
<div className="w-full px-4">
<BarChart
className="h-40"
data={chartData}
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/components/dashboard/macros-donut.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const valueFormatter: ValueFormatter = (number) =>
`${new Intl.NumberFormat("us").format(number)} kcal`;

const MacrosDonut = () => (
<div className="w-full">
<div className="w-full px-4">
<DonutChart
data={macros}
category="calories"
Expand Down
70 changes: 36 additions & 34 deletions apps/nextjs/src/components/dashboard/macros-progress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,42 @@
import { Card, Flex, ProgressBar, Text } from "@tremor/react";

const MacrosProgress = () => (
<Card className="flex w-full flex-col gap-2">
{/* Energy */}
<div>
<Flex>
<Text>Energy &bull; 2000.0 / 2500.0 kcal</Text>
<Text>80%</Text>
</Flex>
<ProgressBar value={80} color="slate" className="mt-1" />
</div>
{/* Protein */}
<div>
<Flex>
<Text>Protein &bull; 4.8 / 119.7 g</Text>
<Text>4%</Text>
</Flex>
<ProgressBar value={4} color="lime" className="mt-1" />
</div>
{/* Carbs */}
<div>
<Flex>
<Text>Carbs &bull; 69.2 / 215.4 g</Text>
<Text>32%</Text>
</Flex>
<ProgressBar value={32} color="violet" className="mt-1" />
</div>
{/* Fat */}
<div>
<Flex>
<Text>Fat &bull; 13.3 / 63.8 g</Text>
<Text>21%</Text>
</Flex>
<ProgressBar value={21} color="amber" className="mt-1" />
</div>
</Card>
<div className="w-full px-4">
<Card className="flex w-full flex-col gap-2">
{/* Energy */}
<div>
<Flex>
<Text>Energy &bull; 2000.0 / 2500.0 kcal</Text>
<Text>80%</Text>
</Flex>
<ProgressBar value={80} color="slate" className="mt-1" />
</div>
{/* Protein */}
<div>
<Flex>
<Text>Protein &bull; 4.8 / 119.7 g</Text>
<Text>4%</Text>
</Flex>
<ProgressBar value={4} color="lime" className="mt-1" />
</div>
{/* Carbs */}
<div>
<Flex>
<Text>Carbs &bull; 69.2 / 215.4 g</Text>
<Text>32%</Text>
</Flex>
<ProgressBar value={32} color="violet" className="mt-1" />
</div>
{/* Fat */}
<div>
<Flex>
<Text>Fat &bull; 13.3 / 63.8 g</Text>
<Text>21%</Text>
</Flex>
<ProgressBar value={21} color="amber" className="mt-1" />
</div>
</Card>
</div>
);

export { MacrosProgress };
95 changes: 48 additions & 47 deletions apps/nextjs/src/components/dashboard/meal-card.tsx
Original file line number Diff line number Diff line change
@@ -1,65 +1,66 @@
import { Check } from "lucide-react";
import { format } from "date-fns";
import { Clock } from "lucide-react";

import { cn } from "@nourish/ui";
import { Button } from "@nourish/ui/button";
import { Badge } from "@nourish/ui/badge";
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@nourish/ui/card";

const notifications = [
{
title: "Your call has been confirmed.",
description: "1 hour ago",
},
{
title: "You have a new message!",
description: "1 hour ago",
},
{
title: "Your subscription is expiring soon!",
description: "2 hours ago",
},
];

type CardProps = React.ComponentProps<typeof Card>;

export function MealCard({ className, ...props }: CardProps) {
interface MealProps extends CardProps {
meal: {
time: string;
foodItems: string[];
};
}

export function MealCard({ meal, className, ...props }: MealProps) {
const { time, foodItems } = meal;

// Format the time to a more readable format, e.g., "3:17 AM"
const formattedTime = format(new Date(time), "p");
// Determine the number of food items to display as a badge
const additionalItemsCount = foodItems.length > 2 ? foodItems.length - 2 : 0;

return (
<Card className={cn("w-[380px]", className)} {...props}>
<CardHeader>
<CardTitle>Notifications</CardTitle>
<CardDescription>You have 3 unread messages.</CardDescription>
<Card className={cn("w-36", className)} {...props}>
<CardHeader className="flex flex-row items-center justify-between gap-1 space-y-0 p-2">
<CardDescription>Meal</CardDescription>
<div className="flex flex-row items-center gap-1">
<Clock size={16} className="text-muted-foreground" />
<p className="text-sm text-muted-foreground">{formattedTime}</p>
</div>
</CardHeader>
<CardContent className="grid gap-4">
<div>
{notifications.map((notification, index) => (
<div
key={index}
className="mb-4 grid grid-cols-[25px_1fr] items-start pb-4 last:mb-0 last:pb-0"
>
<span className="flex h-2 w-2 translate-y-1 rounded-full bg-sky-500" />
<div className="space-y-1">
<p className="text-sm font-medium leading-none">
{notification.title}
<CardContent className="p-2">
<ul>
{foodItems.slice(0, 2).map(
(
foodItem,
index, // Only take the first two items
) => (
<li
key={index}
className="grid grid-cols-[25px_1fr] items-start pb-2"
>
<span className="flex h-2 w-2 translate-y-1 rounded-full bg-sky-500" />
<p className="truncate text-sm font-medium leading-none">
{foodItem}
</p>
<p className="text-sm text-muted-foreground">
{notification.description}
</p>
</div>
</div>
))}
</div>
</li>
),
)}
{additionalItemsCount > 0 && ( // Only show this if there are more than two items
<li className="pt-2">
<Badge variant="default">+{additionalItemsCount} more</Badge>
</li>
)}
</ul>
</CardContent>
<CardFooter>
<Button className="w-full">
<Check className="mr-2 h-4 w-4" /> Mark all as read
</Button>
</CardFooter>
</Card>
);
}
38 changes: 38 additions & 0 deletions apps/nextjs/src/components/dashboard/meal-cards.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as React from "react";

import { ScrollArea, ScrollBar } from "@nourish/ui/scroll-area";

import { MealCard } from "~/components/dashboard/meal-card";

export interface Meal {
time: string;
foodItems: string[];
}

export const meals: Meal[] = [
{
time: "2023-11-09T07:01:00Z",
foodItems: ["Chicken Breast", "Strawberries"],
}, // Breakfast
{
time: "2023-11-09T11:31:00Z",
foodItems: ["Cheddar Cheese", "Turkey", "Mayo", "Bread"],
}, // Lunch
{ time: "2023-11-09T14:01:00Z", foodItems: ["Chocolate Cake"] }, // Snack
{ time: "2023-11-09T18:01:00Z", foodItems: ["Honey"] }, // Dinner
];

export function MealCards() {
return (
<div className="relative w-full">
<ScrollArea className="w-full whitespace-nowrap">
<div className="flex w-max space-x-4 px-4 py-2">
{meals.map((meal, index) => (
<MealCard key={index} meal={meal} />
))}
</div>
<ScrollBar orientation="horizontal" />
</ScrollArea>
</div>
);
}
6 changes: 3 additions & 3 deletions apps/nextjs/src/components/dashboard/micros-progress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Card, Flex, ProgressBar, Text } from "@tremor/react";
const MicrosProgress = () => (
<Card className="mx-auto max-w-sm">
<Flex>
<Text>$ 9,012 &bull; 45%</Text>
<Text>$ 20,000</Text>
<Text>Energy &bull; 410.9 / 1915.0 kcal</Text>
<Text>21.45%</Text>
</Flex>
<ProgressBar value={45} color="teal" className="mt-3" />
<ProgressBar value={21.45} color="gray" className="mt-3" />
</Card>
);

Expand Down
38 changes: 0 additions & 38 deletions packages/api/src/router/post.ts

This file was deleted.

2 changes: 2 additions & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"./input": "./src/input.tsx",
"./label": "./src/label.tsx",
"./popover": "./src/popover.tsx",
"./scroll-area": "./src/scroll-area.tsx",
"./select": "./src/select.tsx",
"./skeleton": "./src/skeleton.tsx",
"./sonner": "./src/sonner.tsx",
Expand All @@ -38,6 +39,7 @@
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
"class-variance-authority": "^0.7.0",
Expand Down
Loading

0 comments on commit 035cff4

Please sign in to comment.