mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
Added delete button business
This commit is contained in:
@@ -32,7 +32,15 @@ export async function getArticles(id: string): Promise<GetArticle> {
|
||||
.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}`, {
|
||||
credentials: 'include',
|
||||
method,
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
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 { baseApiUrl } from '@/utils/api'
|
||||
import { deleteArticle } from '@/utils/database'
|
||||
|
||||
const router = useRouter()
|
||||
const table = ref<HTMLInputElement | string>('')
|
||||
const tabulator: Ref<Tabulator | undefined> = ref(undefined)
|
||||
|
||||
@@ -66,6 +68,15 @@ onMounted(async () => {
|
||||
deleteButton.textContent = '🗑️'
|
||||
|
||||
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)
|
||||
return container
|
||||
|
||||
Reference in New Issue
Block a user