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 essential: true
}); });
// Clear search query after navigation // If picking a post, filter by its title; otherwise clear search
setSearchQuery(""); 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 = () => { const handleOpenCreate = () => {
@ -449,6 +458,7 @@ export default function MapView({
<SmartSearchBar <SmartSearchBar
placeholder="Search cities, places, posts..." placeholder="Search cities, places, posts..."
onPick={handlePickSuggestion} onPick={handlePickSuggestion}
onSearch={handleSearch}
onMySpot={handleFlyToMe} onMySpot={handleFlyToMe}
onPlaceTourWire={handleOpenCreate} onPlaceTourWire={handleOpenCreate}
/> />

View File

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