Skip to content

Commit

Permalink
class 12
Browse files Browse the repository at this point in the history
  • Loading branch information
polashmahmud committed Sep 1, 2023
1 parent d7c260a commit b605fd7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/api/useAdminPosts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {ref} from "vue";
import axios from "axios";

export default function useAdminPosts(uuid) {
const posts = ref([]);
const post = ref({});

const fetchPosts = async () => {
let response = await axios.get('/api/admin/posts');

posts.value = response.data.data
}

const fetchPost = async () => {
let response = await axios.get(`/api/posts/${uuid}`);

post.value = response.data.data
}

return {
posts,
post,
fetchPosts,
fetchPost
}
}
35 changes: 33 additions & 2 deletions src/pages/admin/Post.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
<script setup></script>
<script setup>
import useAdminPosts from "../../api/useAdminPosts.js";
import { onMounted } from "vue";
const {posts, fetchPosts} = useAdminPosts()
onMounted(fetchPosts)
</script>

<template>
Admin Posts
<div class="space-y-16">
<button type="button" class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ri
focus:ring-offset-2 focus:ring-blue-500">New Post
</button>

<div v-for="post in posts" :key="post.uuid">
<div class="flex items-baseline sm:justify-between flex-wrap sm:flex-nowrap space-x-0 sm:space-x-6 space-y-3 sm:space-y-0">
<p class="text-xl font-bold tracking-tight text-gray-900">{{ post.title }}</p>
<div class="flex items-center space-x-6">
<p
class="text-base text-gray-500"
:class="{ 'bg-green-100 text-green-800' : post.published, 'bg-gray-100 text-gray-800': !post.published}"
>
{{ post.published ? 'Published' : 'Unpublished'}}
</p>
<div>
<a href="" class="text-sm font-medium">Edit</a>
</div>
<div>
<button class="text-sm font-medium">Delete</button>
</div>
</div>
</div>
</div>
</div>
</template>

0 comments on commit b605fd7

Please sign in to comment.