In this episode, we're hooking up our mention system so users can search for other users as they type, just like you see in chat apps when you use '@' to mention someone. We've already got our mentionable component and user data indexed in MeiliSearch, so now it's time to connect the dots.
First, we listen for a search event that fires as users type. We create a mentionSearch
function to handle this event, which for now just logs what the user is typing. Then, to keep the code clean and reusable (since we'll use this functionality in other parts of our app, like the reply form), we build a composable called useMentionSearch
.
We set up a reactive array to store search results, and test that everything's wired up by returning a fake user. Once that's working, we install the MeiliSearch JavaScript client, set up our client config using environment variables (so everything's safe and centralized), and wire it all up to actually perform realtime user searches against the MeiliSearch index as you type.
After calming some minor issues, we see that our search is returning results live! Usernames pop up as expected, proving that our setup is working. We finish off by making sure everything looks good and does a final clean-up. At the end of the episode, user mentions are fully searchable and ready to use in your app.