Force update to sidebar navigation

I'm trying to implement "pinning" navigation items so that they appear at the top of a user's sidebar and are eventually draggable to sort. My PinPage action that adds/removes pages from the user table is working dynamically, so that the label immediately updates from "Pin" to "Unpin", but I currently have to refresh the browser to see the navigation update. I was hoping SPA mode would magically work, but that still requires a navigation to update. Any ideas? Is there some Livewire component I can force to refresh/re-render?
4 Replies
jonathan_77589
jonathan_77589OP2w ago
My panel provider:
$panel->navigation(
function (NavigationBuilder $builder): NavigationBuilder {
return $builder->groups([
NavigationGroup::make('Dashboard')
->items(Dashboard::getNavigationItems())
->extraSidebarAttributes(['class' => 'hidden']),
NavigationGroup::make('Pinned')
->icon('heroicon-o-map-pin')
->items(PinnedNavigationItemData::collect(
data_get(
auth()->user(),
'settings.pinnedNavigationItems',
),
Collection::class,
)->map->toNavigationItem()->toArray(),
),
]);
},
);
$panel->navigation(
function (NavigationBuilder $builder): NavigationBuilder {
return $builder->groups([
NavigationGroup::make('Dashboard')
->items(Dashboard::getNavigationItems())
->extraSidebarAttributes(['class' => 'hidden']),
NavigationGroup::make('Pinned')
->icon('heroicon-o-map-pin')
->items(PinnedNavigationItemData::collect(
data_get(
auth()->user(),
'settings.pinnedNavigationItems',
),
Collection::class,
)->map->toNavigationItem()->toArray(),
),
]);
},
);
awcodes
awcodes2w ago
Unfortunately, the sidebar / navigation isn’t a Livewire component so there’s no built in listeners. I think the only solution is to force a page reload.
jonathan_77589
jonathan_77589OP2w ago
Okay, I guess that's not surprising since I'm sure it would have magically just worked otherwise 🙂 If I'm planning on customizing the sidebar blade to add x-sortable support, I suppose an Alpine-oriented approach might work? Or, once SPA mode is working for me (https://github.com/livewire/livewire/pull/9059) a page reload could be virtually unnoticeable. Oh, it seems like Livewire Navigate may work even if the panel is NOT in spa mode. If I add $livewire->js('Livewire.navigate(window.location.href);'); to the end of my action (with injected $livewire ) it works just as intended. Cool!
awcodes
awcodes2w ago
Yea. There’s multiple ways to reload a page. Glad you got it working.

Did you find this page helpful?