implement create rowing component
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 1m39s

This commit is contained in:
2026-03-04 14:45:50 +00:00
parent 5bcc65668e
commit e25fc5f1d1

View File

@@ -1,13 +1,46 @@
<script setup> <script setup>
import Button from "@/components/input/Button.vue";
import { ref } from "vue";
import axios from "axios";
const image = ref(null);
const status = ref("");
const error = ref("");
function onFileChange(e) {
image.value = e.target.files[0] || null;
}
async function submit() {
if (!image.value) {
error.value = "Please select an image";
return;
}
error.value = "";
status.value = "Uploading...";
const formData = new FormData();
formData.append("image", image.value);
try {
const res = await axios.post("/api/rowing", formData, {
headers: { "Content-Type": "multipart/form-data" },
});
status.value = `Saved: ${res.data.Distance}m in ${Math.floor(res.data.Time / 1e9 / 60)}:${String(Math.floor((res.data.Time / 1e9) % 60)).padStart(2, "0")}`;
image.value = null;
} catch (err) {
status.value = "";
error.value = err.response?.data?.error || "Upload failed";
}
}
</script> </script>
<template> <template>
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">
<h1>Create Rowing</h1> <h1>Create Rowing</h1>
<input type="file" accept="image/jpeg,image/png,image/gif,image/webp" @change="onFileChange" />
<Button @click="submit">Upload</Button>
<p v-if="status">{{ status }}</p>
<p v-if="error" class="text-red-500">{{ error }}</p>
</div> </div>
</template> </template>
<style scoped>
</style>