disable navigate when fermentation not started yet

This commit is contained in:
Muhammad Izza Alfiansyah 2024-05-11 09:31:01 +07:00
parent f91379ae5f
commit 2c7677a0c3
1 changed files with 8 additions and 4 deletions

View File

@ -33,6 +33,7 @@ export default function (props: JSX.HTMLAttributes<HTMLDivElement>) {
]; ];
const [lastHistori, setLastHistori] = createSignal<Histori | null>(null); const [lastHistori, setLastHistori] = createSignal<Histori | null>(null);
const [canNavigate, setCanNavigate] = createSignal<boolean>(false);
const location = useLocation(); const location = useLocation();
const navigate = useNavigate(); const navigate = useNavigate();
@ -51,6 +52,7 @@ export default function (props: JSX.HTMLAttributes<HTMLDivElement>) {
}; };
const deleteAllData = async () => { const deleteAllData = async () => {
await supabase.from("pengaturan").update({ running: false }).eq("id", 1);
await supabase.from("kondisi_tapai").delete().neq("id", "0"); await supabase.from("kondisi_tapai").delete().neq("id", "0");
setLastHistori(null); setLastHistori(null);
@ -80,7 +82,7 @@ export default function (props: JSX.HTMLAttributes<HTMLDivElement>) {
}; };
const checkStatusDevice = async () => { const checkStatusDevice = async () => {
const lastData1: any = await new Promise(async (res, rej) => { const lastData1: any = await new Promise(async (res) => {
const { data } = await supabase const { data } = await supabase
.from("kondisi_tapai") .from("kondisi_tapai")
.select("created_time") .select("created_time")
@ -115,6 +117,8 @@ export default function (props: JSX.HTMLAttributes<HTMLDivElement>) {
if (location.pathname != "/") { if (location.pathname != "/") {
navigate("/"); navigate("/");
} }
} else {
setCanNavigate(true);
} }
} }
}; };
@ -122,7 +126,7 @@ export default function (props: JSX.HTMLAttributes<HTMLDivElement>) {
onMount(async () => { onMount(async () => {
await checkPengaturan(); await checkPengaturan();
await getLastHistori(); await getLastHistori();
// await checkStatusDevice(); await checkStatusDevice();
}); });
return ( return (
@ -131,7 +135,7 @@ export default function (props: JSX.HTMLAttributes<HTMLDivElement>) {
<div class="text-xl font-medium uppercase"> <div class="text-xl font-medium uppercase">
<span class="text-primary">Ferm</span>onitor <span class="text-primary">Ferm</span>onitor
</div> </div>
<A href="/pengaturan"> <A href={canNavigate() ? "/pengaturan" : "/"}>
<SettingIcon class="w-6 h-6" /> <SettingIcon class="w-6 h-6" />
</A> </A>
</nav> </nav>
@ -141,7 +145,7 @@ export default function (props: JSX.HTMLAttributes<HTMLDivElement>) {
<For each={menus}> <For each={menus}>
{(item) => ( {(item) => (
<A <A
href={item.path} href={canNavigate() ? item.path : "/"}
class={ class={
"flex mb-5 items-center transition " + "flex mb-5 items-center transition " +
(location.pathname == item.path ? "text-primary" : "") (location.pathname == item.path ? "text-primary" : "")