makin look nice

This commit is contained in:
2025-12-11 11:24:30 +00:00
parent 132a231b82
commit 72cbf25122

View File

@@ -1,6 +1,10 @@
<script setup> <script setup>
import { ref, onMounted } from "vue"; import { ref, onMounted } from "vue";
import axios from "axios"; import axios from "axios";
import { useAuthStore } from "@/stores/auth";
const auth = useAuthStore();
const userOwnsPost = ref(false);
const post = ref(null); const post = ref(null);
const fetched = ref(false); const fetched = ref(false);
@@ -14,10 +18,13 @@ async function fetchPosts() {
try { try {
const res = await axios.get("/api/posts"); const res = await axios.get("/api/posts");
posts = res.data; posts = res.data;
len = posts.length;
fetched.value = true; fetched.value = true;
post.value = posts[0]; post.value = posts[0];
userOwnsPost.value = post.value.author.username == auth.user.username;
leftCap.value = true; leftCap.value = true;
len = posts.length;
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} }
@@ -41,6 +48,18 @@ function prevPost() {
} }
} }
async function deletePost() {
try {
const res = await axios.delete(
`/api/post/${encodeURIComponent(post.value.ID)}`,
);
console.log("Deleted:", res.data);
fetchPosts();
} catch (err) {
console.error("Delete failed:", err);
}
}
onMounted(() => { onMounted(() => {
fetchPosts(); fetchPosts();
}); });
@@ -56,6 +75,7 @@ onMounted(() => {
> >
<button v-if="!leftCap" @click="prevPost">Prev</button> <button v-if="!leftCap" @click="prevPost">Prev</button>
<button v-if="!rightCap" @click="nextPost">Next</button> <button v-if="!rightCap" @click="nextPost">Next</button>
<button v-if="userOwnsPost" @click="deletePost">Delete</button>
</div> </div>
<div v-else> <div v-else>
<h2>Can't fetch from the db yo</h2> <h2>Can't fetch from the db yo</h2>