Skip to content

Commit a114115

Browse files
author
belledw
committed
basic pet info now fetched from backend on main page component
1 parent c64188b commit a114115

11 files changed

Lines changed: 59 additions & 30 deletions

client/src/components/ui/add-event-menu.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use client";
2-
31
import { Check, X } from "lucide-react";
42

53
import { Button } from "@/components/ui/button";

client/src/components/ui/add-health-event-menu.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use client";
2-
31
import { Check, X } from "lucide-react";
42

53
import { Button } from "@/components/ui/button";

client/src/components/ui/add-task-menu.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use client";
2-
31
import { Check, X } from "lucide-react";
42

53
import { Button } from "@/components/ui/button";

client/src/components/ui/date-time-picker.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
"use client";
21
import { ChevronDownIcon } from "lucide-react";
32
import * as React from "react";
43

client/src/components/ui/dob-picker.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
"use client";
21
import { ChevronDownIcon } from "lucide-react";
32
import * as React from "react";
43

client/src/components/ui/health-chart.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use client";
2-
31
import { Bar, BarChart, LabelList, XAxis, YAxis } from "recharts";
42

53
import {
@@ -9,7 +7,7 @@ import {
97
CardFooter,
108
CardHeader,
119
} from "@/components/ui/card";
12-
import { type ChartConfig,ChartContainer } from "@/components/ui/chart";
10+
import { type ChartConfig, ChartContainer } from "@/components/ui/chart";
1311

1412
export const description = "A horizontal bar chart";
1513

client/src/components/ui/pet-page-header.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use client";
2-
31
import { Dot, Plus, Settings } from "lucide-react";
42

53
import { Avatar, AvatarFallback, AvatarImage } from "./avatar";
@@ -28,22 +26,22 @@ export function PetHeader(props: PetHeaderProps) {
2826
<AvatarImage
2927
src={props.petImg}
3028
alt={props.petAlt}
31-
className="h-[75] w-[75]"
29+
className="h-[75] w-[75] rounded-full object-cover"
3230
/>
3331
<AvatarFallback className="h-[75] w-[75] text-xl">
3432
{props.petInit}
3533
</AvatarFallback>
3634
</Avatar>
3735
<div className="ml-10 flex flex-col gap-y-2 self-center">
38-
<TextTitle> {props.petName} </TextTitle>
36+
<TextTitle> {props.petName}</TextTitle>
3937
<TextBody className="flex">
4038
{props.petType} <Dot /> {props.petAge}
4139
</TextBody>
4240
</div>
4341
</div>
4442
<div className="mt-5 flex items-center gap-5 lg:mt-0">
4543
<Button
46-
className="gap-2 rounded-full bg-gray-700 font-light tracking-wider hover:bg-gray-800"
44+
className="gap-2 rounded-full bg-black font-light tracking-wider hover:bg-gray-800"
4745
onClick={props.onClickSettings}
4846
>
4947
<Settings /> Pet Settings

client/src/components/ui/pet-settings-menu.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use client";
2-
31
import { Check, X } from "lucide-react";
42

53
import { DOBPicker } from "@/components/ui/dob-picker";

client/src/components/ui/separator.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use client";
2-
31
import * as SeparatorPrimitive from "@radix-ui/react-separator";
42
import * as React from "react";
53

client/src/pages/pet.tsx

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Check, Plus } from "lucide-react";
2-
import { useState } from "react";
2+
import { useEffect, useState } from "react";
33

44
import { AddEvent } from "@/components/ui/add-event-menu";
55
import { AddHealthEvent } from "@/components/ui/add-health-event-menu";
@@ -15,24 +15,62 @@ import { TaskCarousel } from "@/components/ui/pet-task-carousel";
1515
import { TextTitle } from "@/components/ui/text-styles";
1616
import { dm_sans } from "@/lib/fonts";
1717

18+
interface petInfoResponse {
19+
name: string;
20+
dob: string;
21+
type: string;
22+
img: string;
23+
}
24+
1825
export default function Default() {
1926
const [taskMenu, setTaskMenu] = useState(false);
2027
const [settingsMenu, setSettingsMenu] = useState(false);
2128
const [eventMenu, setEventMenu] = useState(false);
2229
const [healthMenu, setHealthMenu] = useState(false);
2330

31+
const [petInfo, setPetInfo] = useState<petInfoResponse>();
32+
33+
useEffect(() => {
34+
const fetchData = async () => {
35+
const data = await fetch("http://localhost:8000/pet/");
36+
const petInfo = await data.json();
37+
setPetInfo(petInfo);
38+
};
39+
40+
fetchData();
41+
}, []);
42+
43+
const formatPetAge = () => {
44+
if (!petInfo) return null;
45+
const dob = new Date("2020-12-01");
46+
const now = Date.now();
47+
const age = now - dob.getTime();
48+
const yearsAndMonths = age / 1000 / 60 / 60 / 24 / 365.25;
49+
const years = Math.floor(yearsAndMonths);
50+
const months = Math.floor((yearsAndMonths % 1) * 12);
51+
if (years == 1 && months == 1) {
52+
return `${years} year ${months} month`;
53+
} else if (years > 1 && months == 1) {
54+
return `${years} years ${months} month`;
55+
} else if (years == 1 && months > 1) {
56+
return `${years} year ${months} months`;
57+
} else {
58+
return `${years} years ${months} months`;
59+
}
60+
};
61+
2462
return (
2563
<div className={dm_sans.className}>
2664
<h1 className="flex justify-center p-10"> Navbar </h1>
2765
<PetHeader
2866
onClickTask={() => setTaskMenu(true)}
2967
onClickSettings={() => setSettingsMenu(true)}
30-
petImg=""
68+
petImg={petInfo?.img || ""}
3169
petAlt="Spaghetti's Profile Image"
3270
petInit="S"
33-
petName="Spaghetti (example pet)"
34-
petType="Cat"
35-
petAge="5 yrs 6 months"
71+
petName={petInfo?.name || "Loading..."}
72+
petType={petInfo?.type || "Loading..."}
73+
petAge={formatPetAge() || "Loading..."}
3674
/>
3775

3876
<div className="mx-[7vw]">
@@ -42,9 +80,9 @@ export default function Default() {
4280

4381
{settingsMenu === true && (
4482
<PetSettings
45-
petName="Spaghetti"
46-
petType="Cat"
47-
petDOB="01/06/2020"
83+
petName={petInfo?.name || "Loading..."}
84+
petType={petInfo?.type || "Loading..."}
85+
petDOB={petInfo?.dob || "Loading..."}
4886
onClickClose={() => setSettingsMenu(false)}
4987
/>
5088
)}

0 commit comments

Comments
 (0)