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