Compare commits
2 Commits
7a347ed246
...
46feef3a48
| Author | SHA1 | Date | |
|---|---|---|---|
|
46feef3a48
|
|||
| 6e7dd7a560 |
@@ -257,6 +257,8 @@ async def handle_add_tracker(request):
|
|||||||
return web.Response(text="Tracker already exists", status=400)
|
return web.Response(text="Tracker already exists", status=400)
|
||||||
|
|
||||||
trackers[tracker_id] = TrackerData(tracker_id, *START_POSITION_INTERNAL)
|
trackers[tracker_id] = TrackerData(tracker_id, *START_POSITION_INTERNAL)
|
||||||
|
await update_all_clients(request.app)
|
||||||
|
|
||||||
return web.Response(text="OK", status=200)
|
return web.Response(text="OK", status=200)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return web.Response(text=f"Error: {e}", status=400)
|
return web.Response(text=f"Error: {e}", status=400)
|
||||||
@@ -273,6 +275,8 @@ async def handler_delete_tracker(request):
|
|||||||
return web.Response(text="Tracker does not exist", status=400)
|
return web.Response(text="Tracker does not exist", status=400)
|
||||||
|
|
||||||
del trackers[tracker_id]
|
del trackers[tracker_id]
|
||||||
|
await update_all_clients(request.app)
|
||||||
|
|
||||||
return web.Response(text="OK", status=200)
|
return web.Response(text="OK", status=200)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return web.Response(text=f"Error: {e}", status=400)
|
return web.Response(text=f"Error: {e}", status=400)
|
||||||
|
|||||||
@@ -3,32 +3,34 @@
|
|||||||
import { Button } from "$lib/components/ui/button/index.js";
|
import { Button } from "$lib/components/ui/button/index.js";
|
||||||
import TrackerSetting from "./TrackerSetting.svelte";
|
import TrackerSetting from "./TrackerSetting.svelte";
|
||||||
|
|
||||||
const addTracker = async () => {
|
const addTracker = async (arg: number) => {
|
||||||
const response = await fetch("/tracker", {
|
const response = await fetch("/tracker", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
id: 4,
|
id: arg,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(response);
|
console.log(response);
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteTracker = async () => {
|
const deleteTracker = async (arg: number) => {
|
||||||
const response = await fetch("/tracker", {
|
const response = await fetch("/tracker", {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
id: 4,
|
id: arg,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
console.log(response);
|
console.log(response);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let id = $state(0);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Drawer.Root>
|
<Drawer.Root>
|
||||||
@@ -41,8 +43,12 @@
|
|||||||
<Drawer.Description>This action cannot be undone.</Drawer.Description>
|
<Drawer.Description>This action cannot be undone.</Drawer.Description>
|
||||||
</Drawer.Header>
|
</Drawer.Header>
|
||||||
<div class="flex items-center justify-evenly">
|
<div class="flex items-center justify-evenly">
|
||||||
<TrackerSetting action={addTracker} text="Add Tracker" />
|
<TrackerSetting bind:value={id} action={addTracker} text="Add Tracker" />
|
||||||
<TrackerSetting action={deleteTracker} text="Delete Tracker" />
|
<TrackerSetting
|
||||||
|
bind:value={id}
|
||||||
|
action={deleteTracker}
|
||||||
|
text="Delete Tracker"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Drawer.Content>
|
</Drawer.Content>
|
||||||
</Drawer.Root>
|
</Drawer.Root>
|
||||||
|
|||||||
@@ -4,14 +4,15 @@
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
text: string;
|
text: string;
|
||||||
action: () => void;
|
action: (arg: number) => void;
|
||||||
|
value: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
let { action, text }: Props = $props();
|
let { action, text, value = $bindable() }: Props = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h2>{text}</h2>
|
<h2>{text}</h2>
|
||||||
<Input placeholder={"1"} type="tel" />
|
<Input placeholder={"1"} type="tel" bind:value />
|
||||||
<Button onclick={action}>Submit</Button>
|
<Button onclick={() => action(value)}>Submit</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user