Start/Stop charge
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { scale } from 'svelte/transition';
|
||||
import { goto } from "$app/navigation";
|
||||
import { goto, invalidate } from "$app/navigation";
|
||||
import BSlideOverlay from "$lib/BSlideOverlay.svelte";
|
||||
import { addToast } from '$lib/ToastSystem/Toaster.svelte';
|
||||
|
||||
@@ -13,15 +13,33 @@
|
||||
if (startingCharge) return;
|
||||
startingCharge = true;
|
||||
try {
|
||||
// TODO: StartCharge fetch request
|
||||
// const response = await fetch(`/api/public/1/chargecontroller/${data.qrcode}/start_charge/`, {
|
||||
// method: 'POST',
|
||||
// headers: {
|
||||
// 'Accept': 'application/json',
|
||||
// }
|
||||
// });
|
||||
console.log("nop");
|
||||
const response = await fetch(`/api/public/1/chargecontroller/${data.qrcode}/start_charge/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
});
|
||||
if (response.ok) {
|
||||
addToast({
|
||||
closeDelay: 5000,
|
||||
data: {
|
||||
title: 'Charge Started',
|
||||
description: '',
|
||||
type: 'success',
|
||||
}
|
||||
});
|
||||
await invalidate('app:chargecontroller');
|
||||
await goto(`/${data.qrcode}/status`);
|
||||
} else {
|
||||
addToast({
|
||||
closeDelay: 5000,
|
||||
data: {
|
||||
title: 'Error',
|
||||
description: response.statusText ?? 'unknown',
|
||||
type: 'error',
|
||||
}
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
startingCharge = false;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { onMount } from "svelte";
|
||||
import { goto, invalidate } from "$app/navigation";
|
||||
import { scale } from 'svelte/transition';
|
||||
import { addToast } from '$lib/ToastSystem/Toaster.svelte';
|
||||
import BatteryIcon from "$lib/icons/BatteryIcon.svelte";
|
||||
import BSlideOverlay from "$lib/BSlideOverlay.svelte";
|
||||
|
||||
@@ -32,9 +33,33 @@
|
||||
if (stoppingCharge) return;
|
||||
stoppingCharge = true;
|
||||
try {
|
||||
// TODO: StopCharge fetch request
|
||||
console.log("nop");
|
||||
const response = await fetch(`/api/public/1/chargecontroller/${data.qrcode}/stop_charge/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
});
|
||||
if (response.ok) {
|
||||
addToast({
|
||||
closeDelay: 5000,
|
||||
data: {
|
||||
title: 'Charge Stopped',
|
||||
description: '',
|
||||
type: 'success',
|
||||
}
|
||||
});
|
||||
await invalidate('app:chargecontroller');
|
||||
await goto(`/${data.qrcode}`);
|
||||
} else {
|
||||
addToast({
|
||||
closeDelay: 5000,
|
||||
data: {
|
||||
title: 'Error',
|
||||
description: response.statusText ?? 'unknown',
|
||||
type: 'error',
|
||||
}
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
stoppingCharge = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user