Adds fetching and toggling alerts
All checks were successful
Gitea Build Action / build-go (push) Successful in 28s
Gitea Build Action / build-nuxt (push) Successful in 10m8s

This commit is contained in:
Daniel Svitan
2025-06-07 08:59:34 +02:00
parent ae7db8290c
commit 000c12845c
6 changed files with 159 additions and 105 deletions

View File

@@ -13,8 +13,8 @@ FROM oven/bun:1
WORKDIR /app
COPY --from=build /app/.output .
ENV PORT 3000
ENV HOST 0.0.0.0
ENV PORT=3000
ENV HOST=0.0.0.0
EXPOSE 3000
CMD ["bun", "/app/server/index.mjs"]

View File

@@ -77,7 +77,7 @@
:color="alert ? 'primary' : 'secondary'"
variant="solid"
class="flex items-center justify-center w-full h-10"
@click="() => (alert = !alert)"
@click="toggleAlert"
>
{{ alert ? "Turn off" : "Turn on" }}
</UButton>
@@ -119,6 +119,21 @@ async function toggleLock() {
.catch(handleRequestError)
}
async function toggleAlert() {
const desired = !alert.value
axios
.post(useAPI("/alert"), { alert: desired }, { headers: useHeaders() })
.then((res) => {
handleResponse(res, () => {
toast.add({
title: `Alerts were turned ${desired ? "on" : "off"}`,
})
alert.value = desired
})
})
.catch(handleRequestError)
}
onMounted(() => {
if (!token.value) {
return navigateTo("/token")
@@ -134,5 +149,16 @@ onMounted(() => {
})
})
.catch(handleRequestError)
axios
.get<boolean>(useAPI("/alert"), {
headers: useHeaders(),
})
.then((res) => {
handleResponse(res, (response) => {
alert.value = response.data
})
})
.catch(handleRequestError)
})
</script>