Implement collection item reordering with bulk operations and persistent HTML attributes
- Add bulk reorder API endpoint (PUT /api/collections/{id}/reorder) with atomic transactions
- Replace individual position updates with efficient bulk operations in frontend
- Implement unified ID generation and proper data-item-id injection during enhancement
- Fix collection item position persistence through content edit cycles
- Add optimistic UI with rollback capability for better user experience
- Update sqlc queries to include last_edited_by fields in position updates
- Remove obsolete data-content-type attributes and unify naming conventions
This commit is contained in:
@@ -243,21 +243,19 @@ export class ApiClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* Update collection item position (for reordering)
|
||||
* Reorder collection items in bulk
|
||||
* @param {string} collectionId - Collection ID
|
||||
* @param {string} itemId - Item ID to update
|
||||
* @param {number} newPosition - New position index
|
||||
* @param {Array} itemOrder - Array of {itemId, position} objects
|
||||
* @returns {Promise<boolean>} Success status
|
||||
*/
|
||||
async updateCollectionItemPosition(collectionId, itemId, newPosition) {
|
||||
async reorderCollection(collectionId, itemOrder) {
|
||||
try {
|
||||
const collectionsUrl = this.getCollectionsUrl();
|
||||
const payload = {
|
||||
site_id: this.siteId,
|
||||
position: newPosition
|
||||
items: itemOrder
|
||||
};
|
||||
|
||||
const response = await fetch(`${collectionsUrl}/${collectionId}/items/${itemId}`, {
|
||||
const response = await fetch(`${collectionsUrl}/${collectionId}/reorder?site_id=${this.siteId}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -270,11 +268,11 @@ export class ApiClient {
|
||||
return true;
|
||||
} else {
|
||||
const errorText = await response.text();
|
||||
console.error(`❌ Failed to update collection item position (${response.status}): ${errorText}`);
|
||||
console.error(`❌ Failed to reorder collection (${response.status}): ${errorText}`);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ Error updating collection item position:', error);
|
||||
console.error('❌ Error reordering collection:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user