@@ -31,12 +31,20 @@ class ManageMenuItems extends Page implements HasActions, HasForms
3131
3232 public mixed $ record ;
3333
34+ public $ refreshKey = 0 ;
35+
3436 public function mount (int |string $ record ): void
3537 {
3638 $ menuModel = static ::getResource ()::getModel ();
3739 $ this ->record = $ menuModel ::findOrFail ($ record );
3840 }
3941
42+ protected function refreshTree (): void
43+ {
44+ $ this ->refreshKey ++;
45+ $ this ->dispatch ('menu-items-updated ' );
46+ }
47+
4048 public function getTitle (): string
4149 {
4250 return flexiblePagesTrans ('menu_items.manage.title ' , [
@@ -220,7 +228,7 @@ public function deleteMenuItem(int $itemId): void
220228 // Delete the item
221229 $ item ->delete ();
222230
223- $ this ->dispatch ( ' menu-items-updated ' );
231+ $ this ->refreshTree ( );
224232
225233 Notification::make ()
226234 ->title (flexiblePagesTrans ('menu_items.messages.item_deleted ' ))
@@ -246,7 +254,7 @@ public function confirmDeleteWithChildren(int $itemId): void
246254 // Delete the item and all its descendants
247255 $ item ->delete ();
248256
249- $ this ->dispatch ( ' menu-items-updated ' );
257+ $ this ->refreshTree ( );
250258
251259 Notification::make ()
252260 ->title (flexiblePagesTrans ('menu_items.messages.item_and_children_deleted ' ))
@@ -302,7 +310,7 @@ public function reorderMenuItems(array $orderedItems): void
302310 // Process the reordering with proper nested set operations
303311 $ this ->processNestedSetReorder ($ orderedItems );
304312
305- $ this ->dispatch ( ' menu-items-updated ' );
313+ $ this ->refreshTree ( );
306314
307315 Notification::make ()
308316 ->title (flexiblePagesTrans ('menu_items.messages.items_reordered ' ))
@@ -506,7 +514,7 @@ public function moveMenuItem(int $itemId, ?int $newParentId = null, ?int $afterI
506514 }
507515 }
508516
509- $ this ->dispatch ( ' menu-items-updated ' );
517+ $ this ->refreshTree ( );
510518
511519 Notification::make ()
512520 ->title (flexiblePagesTrans ('menu_items.messages.item_moved ' ))
@@ -702,7 +710,7 @@ public function createMenuItem(array $data): void
702710 ->send ();
703711
704712 // Refresh the menu items tree view
705- $ this ->dispatch ( ' menu-items-updated ' );
713+ $ this ->refreshTree ( );
706714
707715 } catch (Exception $ e ) {
708716 Notification::make ()
@@ -756,7 +764,7 @@ public function updateMenuItem(int $itemId, array $data): void
756764 ->send ();
757765
758766 // Refresh the menu items tree view
759- $ this ->dispatch ( ' menu-items-updated ' );
767+ $ this ->refreshTree ( );
760768
761769 } catch (Exception $ e ) {
762770 Notification::make ()
0 commit comments