Skip to content

Commit 473e712

Browse files
committed
Save re-ordering
1 parent 7316ed8 commit 473e712

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

resources/views/filament/resources/menu-resource/pages/manage-menu-items.blade.php

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ class="space-y-6"
2727
<!-- Tree Items -->
2828
<div class="space-y-2" id="menu-items-container" wire:key="tree-{{ $refreshKey }}">
2929
@foreach($this->record->menuItems()->with(['children', 'linkable'])->whereNull('parent_id')->orderBy('_lft')->get() as $item)
30-
<div data-item-id="{{ $item->id }}">
31-
@livewire('filament-flexible-content-block-pages::menu-tree-item', [
32-
'item' => $item,
33-
'maxDepth' => $this->getMaxDepth()
34-
], key("item-{$item->id}-{$refreshKey}"))
35-
</div>
30+
@livewire('filament-flexible-content-block-pages::menu-tree-item', [
31+
'item' => $item,
32+
'maxDepth' => $this->getMaxDepth()
33+
], key("item-{$item->id}-{$refreshKey}"))
3634
@endforeach
3735
</div>
3836
@endif
@@ -72,11 +70,6 @@ function menuItemsManager(config) {
7270
this.$wire.on('menu-items-updated', () => {
7371
this.refreshMenuItems();
7472
});
75-
76-
// Listen for reorder completion (no need to refresh, just hide loading)
77-
this.$wire.on('menu-items-reordered', () => {
78-
this.loading = false;
79-
});
8073
},
8174
8275
refreshMenuItems() {
@@ -125,15 +118,7 @@ function menuItemsManager(config) {
125118
});
126119
127120
// Call the Livewire method to save the new order
128-
this.$wire.reorderMenuItems(items).then(() => {
129-
this.loading = false;
130-
// Don't manually refresh - the server-side refreshTree() will handle it
131-
}).catch((error) => {
132-
console.error('Reorder failed:', error);
133-
this.loading = false;
134-
// Only refresh on error to revert changes
135-
this.refreshMenuItems();
136-
});
121+
this.$wire.reorderMenuItems(items);
137122
},
138123
139124
extractItemId(element) {

src/Resources/MenuResource/Pages/ManageMenuItems.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,8 @@ public function reorderMenuItems(array $orderedItems): void
325325
// Process the reordering with proper nested set operations
326326
$this->processNestedSetReorder($orderedItems);
327327

328-
// Don't refresh tree for reordering - the visual order is already correct
329-
// Only dispatch event for JavaScript to hide loading state
330-
$this->dispatch('menu-items-reordered');
328+
// Refresh tree to sync with database state
329+
$this->refreshTree();
331330

332331
Notification::make()
333332
->title(flexiblePagesTrans('menu_items.messages.items_reordered'))

0 commit comments

Comments
 (0)