fix: implement views counter increment via public role, add spacing between sidebar buttons
This commit is contained in:
@@ -949,6 +949,10 @@ style.textContent = /* css */`
|
||||
gap: var(--space-sm);
|
||||
}
|
||||
|
||||
page-listing .sidebar-btn + .sidebar-btn {
|
||||
margin-top: var(--space-sm);
|
||||
}
|
||||
|
||||
page-listing .sidebar-actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -94,10 +94,22 @@ export async function updateListing(id, data) {
|
||||
return response.data
|
||||
}
|
||||
|
||||
// View counting requires server-side implementation (e.g. Directus Flow)
|
||||
// Client-side increment is not possible with current permissions
|
||||
export async function incrementListingViews(_id) {
|
||||
export async function incrementListingViews(id) {
|
||||
try {
|
||||
const listing = await getListing(id)
|
||||
if (!listing) return null
|
||||
const newViews = (listing.views || 0) + 1
|
||||
const response = await fetch(`${client.baseUrl}/items/listings/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ views: newViews })
|
||||
})
|
||||
if (!response.ok) return null
|
||||
return newViews
|
||||
} catch (e) {
|
||||
console.warn('Failed to increment views:', e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteListing(id) {
|
||||
|
||||
Reference in New Issue
Block a user