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);
|
gap: var(--space-sm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
page-listing .sidebar-btn + .sidebar-btn {
|
||||||
|
margin-top: var(--space-sm);
|
||||||
|
}
|
||||||
|
|
||||||
page-listing .sidebar-actions {
|
page-listing .sidebar-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|||||||
@@ -94,10 +94,22 @@ export async function updateListing(id, data) {
|
|||||||
return response.data
|
return response.data
|
||||||
}
|
}
|
||||||
|
|
||||||
// View counting requires server-side implementation (e.g. Directus Flow)
|
export async function incrementListingViews(id) {
|
||||||
// Client-side increment is not possible with current permissions
|
try {
|
||||||
export async function incrementListingViews(_id) {
|
const listing = await getListing(id)
|
||||||
return null
|
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) {
|
export async function deleteListing(id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user