Added delete button business

This commit is contained in:
Florian Sylvain
2023-01-19 03:05:16 +01:00
parent a4ee8f90ff
commit 9b4ad81122
2 changed files with 21 additions and 2 deletions
+9 -1
View File
@@ -32,7 +32,15 @@ export async function getArticles(id: string): Promise<GetArticle> {
.then(result => result.json()) .then(result => result.json())
} }
async function sendArticle(article: Article, method: 'POST' | 'PUT') { export async function deleteArticle(id: string) {
return await fetch(`${baseApiUrl}/articles/${id}`, {
credentials: 'include',
method: 'DELETE',
})
.then(result => result.json())
}
async function sendArticle(article: Article, method: 'POST' | 'PUT'): Promise<object> {
return await fetch(`${baseApiUrl}/articles/${article.titleID}`, { return await fetch(`${baseApiUrl}/articles/${article.titleID}`, {
credentials: 'include', credentials: 'include',
method, method,
+12 -1
View File
@@ -1,9 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref, type Ref } from 'vue' import { onMounted, ref, type Ref } from 'vue'
import { RouterLink } from 'vue-router' import { RouterLink, useRouter } from 'vue-router'
import { TabulatorFull as Tabulator } from 'tabulator-tables' import { TabulatorFull as Tabulator } from 'tabulator-tables'
import { baseApiUrl } from '@/utils/api' import { baseApiUrl } from '@/utils/api'
import { deleteArticle } from '@/utils/database'
const router = useRouter()
const table = ref<HTMLInputElement | string>('') const table = ref<HTMLInputElement | string>('')
const tabulator: Ref<Tabulator | undefined> = ref(undefined) const tabulator: Ref<Tabulator | undefined> = ref(undefined)
@@ -66,6 +68,15 @@ onMounted(async () => {
deleteButton.textContent = '🗑️' deleteButton.textContent = '🗑️'
editButton.href = `/articles/edit/${cell.getValue()}` editButton.href = `/articles/edit/${cell.getValue()}`
deleteButton.onclick = async () => {
await deleteArticle(cell.getValue())
const currentPage = tabulator.value?.getPage()
if (isNaN(currentPage as number)) {
router.go(0)
} else {
tabulator.value?.setPage(currentPage as number)
}
}
container.append(editButton, deleteButton) container.append(editButton, deleteButton)
return container return container