This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

fix reorder

+19 -13
+19 -13
src/components/Admin/AdminPanel.js
··· 304 304 }; 305 305 306 306 // Reorder resources (move up or down in list) 307 - const handleReorderResource = async (resourceId, direction) => { 307 + const handleReorderResource = async (resourceId, direction) => { 308 308 const resourceIndex = resources.findIndex(r => r.id === resourceId); 309 309 if (resourceIndex === -1) return; 310 310 311 - let filteredResources = resources; 311 + let filteredResources = [...resources]; // Create a copy to work with 312 312 313 313 // Filter resources based on reorder mode 314 314 if (reorderMode === 'featured') { 315 - filteredResources = resources.filter(r => r.featured); 315 + filteredResources = filteredResources.filter(r => r.featured); 316 316 } else if (reorderMode === 'category' && selectedCategoryForReorder) { 317 - filteredResources = resources.filter(r => 317 + filteredResources = filteredResources.filter(r => 318 318 r.categoryIds && r.categoryIds.includes(selectedCategoryForReorder) 319 319 ); 320 320 } 321 + 322 + // Sort by position to ensure correct order 323 + filteredResources.sort((a, b) => a.position - b.position); 321 324 322 325 const resourceToMoveIndex = filteredResources.findIndex(r => r.id === resourceId); 323 326 if (resourceToMoveIndex === -1) return; ··· 348 351 349 352 // Update local state without fetching all data again 350 353 setResources(prevResources => { 351 - return prevResources.map(resource => { 352 - if (resource.id === resourceToMove.id) { 353 - return { ...resource, position: adjacentResource.position }; 354 - } 355 - if (resource.id === adjacentResource.id) { 356 - return { ...resource, position: resourceToMove.position }; 357 - } 358 - return resource; 359 - }); 354 + const updatedResources = [...prevResources]; 355 + 356 + // Find the actual resources in the full list 357 + const resourceToMoveFullIndex = updatedResources.findIndex(r => r.id === resourceToMove.id); 358 + const adjacentResourceFullIndex = updatedResources.findIndex(r => r.id === adjacentResource.id); 359 + 360 + // Swap their positions 361 + const tempPosition = updatedResources[resourceToMoveFullIndex].position; 362 + updatedResources[resourceToMoveFullIndex].position = updatedResources[adjacentResourceFullIndex].position; 363 + updatedResources[adjacentResourceFullIndex].position = tempPosition; 364 + 365 + return updatedResources; 360 366 }); 361 367 362 368 showAlert(`Resources reordered successfully!`);