Skip to content

Commit b98f50b

Browse files
committed
feat: add car info
1 parent 0905a3a commit b98f50b

2 files changed

Lines changed: 50 additions & 3 deletions

File tree

frontend/api/status.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export enum PlannerEnum {
2+
RRT_STAR = "RRT_STAR",
3+
HYBRID_A_STAR = "HYBRID_A_STAR",
4+
PARKING = "PARKING",
5+
LEAVE_PARKING = "LEAVE_PARKING",
6+
IDLE = "IDLE",
7+
SUMMON_DRIVING = "SUMMON_DRIVING",
8+
PARALLEL_PARKING = "PARALLEL_PARKING",
9+
}
10+
11+
interface StatusResponse {
12+
status: PlannerEnum;
13+
}
14+
15+
16+
const getCarStatus = async (): Promise<PlannerEnum | null> => {
17+
const res = await fetch("http://localhost:8000/api/status", {
18+
method: "GET",
19+
headers: {
20+
"Content-Type": "application/json",
21+
Accept: "application/json",
22+
}
23+
});
24+
25+
26+
if (!res.ok) {
27+
console.error("Failed to fetch status:", res.statusText);
28+
return null;
29+
}
30+
31+
const body: StatusResponse = await res.json();
32+
return body.status;
33+
};
34+
35+
export { getCarStatus };

frontend/components/car-info.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { Progress } from "@/components/ui/progress"
77
import { cn } from "@/lib/utils"
88
import { motion, AnimatePresence } from "framer-motion"
99
import { toast } from "sonner"
10+
import { getCarStatus } from "@/api/status";
1011

1112
export function CarInfo() {
1213
const [batteryLevel, setBatteryLevel] = useState(80)
13-
const [temperature, setTemperature] = useState(72)
1414
const [isLocked, setIsLocked] = useState(true)
1515
const [isAcOn, setIsAcOn] = useState(false)
1616
const [isCharging, setIsCharging] = useState(false)
@@ -29,6 +29,18 @@ export function CarInfo() {
2929
return () => clearInterval(interval)
3030
}, [isCharging, batteryLevel])
3131

32+
useEffect(() => {
33+
getCarStatus().then(data => {
34+
if (data) {
35+
setIsConnected(true)
36+
} else {
37+
setIsConnected(false)
38+
}
39+
}).catch(() => {
40+
setIsConnected(false)
41+
})
42+
}, [])
43+
3244
const getBatteryColor = () => {
3345
if (batteryLevel > 50) return "bg-green-500"
3446
if (batteryLevel > 20) return "bg-yellow-500"
@@ -128,12 +140,12 @@ export function CarInfo() {
128140
<div className="flex items-center gap-2">
129141
<motion.span
130142
className="font-medium"
131-
key={temperature}
143+
key={72}
132144
initial={{ opacity: 0, y: -10 }}
133145
animate={{ opacity: 1, y: 0 }}
134146
transition={{ duration: 0.3 }}
135147
>
136-
{temperature}°F
148+
{72}°F
137149
</motion.span>
138150
<Button
139151
variant="outline"

0 commit comments

Comments
 (0)