In this episode, we focus on storing and displaying the online users in our chat application. We start by creating a new Pinia store dedicated to handling the currently online users. Instead of cluttering our existing store, we keep things organized by having a separate store for user state.
We follow familiar patterns: creating the store file, defining its state (an array for users), adding a getter for getting all users, and then wiring up an action to set the list of online users whenever we receive them from an event (like a push from Echo). Once that's sorted, we move over to our components and set up a simple Vue component (ChatUsers.vue
) that just dumps out the user list from our store onto the page.
After getting the bare functionality, we quickly style up the component to look a bit nicer: adding a header, displaying the count of online users, and showing each username in a styled list. We also show two approaches to count the online users: either by checking the array's length directly or by adding a computed getter in the store. This sets us up nicely for more advanced filtering later if needed.
By the end of this episode, we've got a clean, reactive display of who is online, complete with some polish and options for future expansion!