From e2c931faa6d11f06a258da88f35614797ea719a3 Mon Sep 17 00:00:00 2001 From: Muhammad Izza Alfiansyah Date: Wed, 12 Jun 2024 16:01:48 +0700 Subject: [PATCH] add control automatic and manual --- website/src/App.tsx | 8 +- website/src/Router.tsx | 2 + website/src/icons/AdjusmentIcon.tsx | 21 ++++ website/src/pages/Kontrol.tsx | 163 ++++++++++++++++++++++++++++ website/src/types/Pengaturan.ts | 3 + 5 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 website/src/icons/AdjusmentIcon.tsx create mode 100644 website/src/pages/Kontrol.tsx diff --git a/website/src/App.tsx b/website/src/App.tsx index 13bfa06..3d4dcbb 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -8,6 +8,7 @@ import supabase from "./utils/supabase"; import { Histori } from "./types/Histori"; import { Pengaturan } from "./types/Pengaturan"; import BarsIcon from "./icons/BarsIcon"; +import AdjusmentIcon from "./icons/AdjusmentIcon"; export default function (props: JSX.HTMLAttributes) { const menus = [ @@ -26,6 +27,11 @@ export default function (props: JSX.HTMLAttributes) { title: "Histori", icon: ClockIcon, }, + { + path: "/kontrol", + title: "Kontrol", + icon: AdjusmentIcon, + }, { path: "/pengaturan", title: "Pengaturan", @@ -125,7 +131,7 @@ export default function (props: JSX.HTMLAttributes) { } } else { setCanNavigate(true); - await checkStatusDevice(); + // await checkStatusDevice(); } } }; diff --git a/website/src/Router.tsx b/website/src/Router.tsx index ed1e0b5..8a76d94 100644 --- a/website/src/Router.tsx +++ b/website/src/Router.tsx @@ -3,6 +3,7 @@ import Index from "./pages/Index"; import Pengujian from "./pages/Pengujian"; import Histori from "./pages/Histori"; import Pengaturan from "./pages/Pengaturan"; +import Kontrol from "./pages/Kontrol"; interface Props { root: any; @@ -14,6 +15,7 @@ export default function (props: Props) { + ); diff --git a/website/src/icons/AdjusmentIcon.tsx b/website/src/icons/AdjusmentIcon.tsx new file mode 100644 index 0000000..da82276 --- /dev/null +++ b/website/src/icons/AdjusmentIcon.tsx @@ -0,0 +1,21 @@ +import IconProps from "./type"; + +export default function (props: IconProps) { + return ( + + + + ); +} diff --git a/website/src/pages/Kontrol.tsx b/website/src/pages/Kontrol.tsx new file mode 100644 index 0000000..1c425d1 --- /dev/null +++ b/website/src/pages/Kontrol.tsx @@ -0,0 +1,163 @@ +import { createSignal, onMount } from "solid-js"; +import supabase from "../utils/supabase"; +import { Pengaturan } from "../types/Pengaturan"; +import { Show } from "solid-js"; + +export default function () { + const [req, setReq] = createSignal(); + + const getData = async () => { + const { data } = await supabase.from("pengaturan").select("*").eq("id", 1); + + if (!!data) { + setReq(data[0]); + } + }; + + const handleReqChange = (key: keyof Pengaturan, value: any) => { + setReq((val) => { + (val as any)[key] = value; + return val; + }); + }; + + const handleSubmit = async (e: SubmitEvent | null = null) => { + e?.preventDefault(); + + const suhu_min = parseInt(req()?.suhu_min as any); + const suhu_max = parseInt(req()?.suhu_max as any); + + if (suhu_min >= suhu_max) { + alert("suhu maximal harus lebih besar dari suhu minimal"); + } else { + await supabase.from("pengaturan").update(req()).eq("id", 1); + + if (e) { + alert("data berhasil disimpan"); + } + } + + await getData(); + }; + + onMount(async () => { + await getData(); + }); + + return ( +
+
+
Kontrol Alat
+

+ Pemilik bisa mengatur environment untuk pengendalian suhu secara + otomatis atau secara manual +

+
+ +
+
+ +
+
+
+
+
Lampu
+ +
+
+
Kipas
+ +
+
+
+
+
+ } + > +
+
+
+
+
+
Suhu Min
+ +
+
+
Suhu Max
+ +
+
+
+
+
+ + + ); +} diff --git a/website/src/types/Pengaturan.ts b/website/src/types/Pengaturan.ts index ff0a5b4..211f72e 100644 --- a/website/src/types/Pengaturan.ts +++ b/website/src/types/Pengaturan.ts @@ -5,4 +5,7 @@ export interface Pengaturan { suhu_min: number; suhu_max: number; running: boolean; + auto: boolean; + fan_on: boolean; + lamp_on: boolean; } \ No newline at end of file