Feature: Add search filtering on Enter key

Users can now:
1. Type a query and press Enter (without selecting a suggestion) to filter posts on the map
2. When picking a post suggestion, it navigates AND filters by that post's title
3. When picking a city/place, it navigates but clears the filter

Changes:
- SmartSearchBar: Added onSearch prop, triggers on Enter with no active item
- MapView: Added handleSearch() to set searchQuery for filtering
- Posts are automatically filtered by usePostsEngine's matchesSearch()

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Your Name 2025-12-23 16:10:06 -05:00
parent 9d906fb4a4
commit 797859ac80
2 changed files with 20 additions and 3 deletions

View File

@ -234,8 +234,17 @@ export default function MapView({
essential: true
});
// Clear search query after navigation
// If picking a post, filter by its title; otherwise clear search
if (item.type === 'post' && item.title) {
setSearchQuery(item.title);
} else {
setSearchQuery("");
}
};
const handleSearch = (query) => {
console.log('[MapView] Search/filter by:', query);
setSearchQuery(query);
};
const handleOpenCreate = () => {
@ -449,6 +458,7 @@ export default function MapView({
<SmartSearchBar
placeholder="Search cities, places, posts..."
onPick={handlePickSuggestion}
onSearch={handleSearch}
onMySpot={handleFlyToMe}
onPlaceTourWire={handleOpenCreate}
/>

View File

@ -52,12 +52,14 @@ function IconWaves(props) {
* Props:
* - placeholder
* - onPick(item, { zoom, reason }) // call when user selects suggestion
* - onSearch(query) // call when user presses Enter to filter/search
* - onMySpot() // keep same function (center on user)
* - onPlaceTourWire() // keep same function (place/tour/wire)
*/
export default function SmartSearchBar({
placeholder = "Search places, regions, posts…",
onPick,
onSearch,
onMySpot,
onPlaceTourWire,
}) {
@ -144,9 +146,14 @@ export default function SmartSearchBar({
e.preventDefault();
setActive((i) => Math.max(i - 1, 0));
} else if (e.key === "Enter") {
if (items.length && active >= 0) {
e.preventDefault();
if (items.length && active >= 0) {
// Pick the selected suggestion
pick(items[active], "enter");
} else if (q.trim()) {
// No item selected, trigger search/filter
setOpen(false);
onSearch && onSearch(q.trim());
}
} else if (e.key === "Escape") {
setOpen(false);