|
| 1 | +"use client"; |
| 2 | + |
1 | 3 | import { useState, useEffect } from "react"; |
2 | 4 |
|
3 | 5 | const RadarReading = () => { |
4 | | - const [token, setToken] = useState(""); |
| 6 | + const [checkMovement, setCheckMovement] = useState(false); |
5 | 7 |
|
6 | 8 | useEffect(() => { |
7 | | - setToken(localStorage.getItem("token") || ""); |
8 | | - }, []); |
9 | | - |
10 | | - const getMembers = async () => { |
11 | | - if (!token) { |
12 | | - console.error("No token found in localStorage"); |
13 | | - return; |
| 9 | + if (checkMovement) { |
| 10 | + // triggerEmailAlert(); |
14 | 11 | } |
| 12 | + }, [checkMovement]); // Runs when checkMovement changes |
15 | 13 |
|
16 | | - try { |
17 | | - const response = await fetch("/api/triggerEmail", { |
18 | | - method: "GET", |
19 | | - headers: { |
20 | | - "Content-Type": "application/json", |
21 | | - "authorization": `Bearer ${token}`, |
22 | | - }, |
23 | | - }); |
| 14 | + const triggerEmailAlert = async () => { |
| 15 | + |
24 | 16 |
|
25 | | - const data = await response.json(); |
26 | | - console.log("Response from the server:", data); |
27 | | - } catch (error) { |
28 | | - console.error("Error fetching members:", error); |
29 | | - } |
30 | 17 | }; |
31 | 18 |
|
32 | 19 | return ( |
33 | 20 | <div className="flex flex-col justify-center items-center shadow-2xl rounded-3xl w-1/2 p-4 border-2 border-blue-200"> |
34 | | - <label className="block text-black font-light text-2xl">Radar Reading</label> |
35 | | - <p className="text-blue-600 text-xl">#</p> |
36 | | - |
| 21 | + <label className="block text-black font-light text-3xl">Radar Reading</label> |
| 22 | + <p className="text-blue-600 text-3xl">{checkMovement ? "1" : "0"}</p> |
| 23 | + <p className={`text-2xl p-2 rounded-lg ${checkMovement ? "bg-red-200 text-red-600" : "bg-green-100 text-green-400"}`}> |
| 24 | + {checkMovement ? "Movement Detected!" : "No Movement Detected!"} |
| 25 | + </p> |
37 | 26 | </div> |
38 | 27 | ); |
39 | 28 | }; |
|
0 commit comments