Can you rerender parts of a persistent layout? #349
-
First of all, I love the persistent layout feature and I don't wanna remove it. The scenario: I have unread notifications in shared data and a notification dropdown in a persistent layout. When I click on any link inside the notification dropdown I send and additional After the successful response the unread notifications are updated in shared data, but is there a way I could rerender that part of the layout as well? It stays the same until unless I go to a page with a different layout and than go back or I hit refresh. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
One possible solution would be to add a global event listener like: import { createApp, ref } from '@inertiajs/inertia'
import { Inertia } from '@inertiajs/inertia'
const app = createApp(/*...*/);
app.config.globalProperties.notification_count = ref(0)
Inertia.on('success', (event) => {
this.notification_count = event.detail.page.props.notification_count
}) And then in your It does seem like it should just update though. |
Beta Was this translation helpful? Give feedback.
-
Hi, The Inertia Way™ to do this, is to simply share the list of (unread) notifications on every single request (you can cache them server-side if needed, as to not continuously re-query the database). Then, as you mark a notification as read (by making an Inertia visit when clicking the 'mark as read' button), the database updates the notification, and the request redirects you back to the page you were already on. Because the 'source' and 'target' pages are the same / use the same Page Component, Inertia will essentially only update the page's props, which should now be a fresh notification list, without the notification we just marked as read. Then, through Vue's reactive re-rendering 'magic', the read notification will disappear from your (shared) layout, especially if you're accessing it using the Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
It's kind of late but if all the notifications are read from the Shared Data ($page in Vue and userPage() in React) then you just can simply call |
Beta Was this translation helpful? Give feedback.
Hi,
The Inertia Way™ to do this, is to simply share the list of (unread) notifications on every single request (you can cache them server-side if needed, as to not continuously re-query the database).
Then, as you mark a notification as read (by making an Inertia visit when clicking the 'mark as read' button), the database updates the notification, and the request redirects you back to the page you were already on.
Because the 'source' and 'target' pages are the same / use the same Page Component, Inertia will essentially only update the page's props, which should now be a fresh notification list, without the notification we just marked as read.
Then, through Vue's reactive re-rendering '…