Enhance search functionality to support hashtag queries and update UI for search results display

This commit is contained in:
2025-10-05 16:18:25 +02:00
parent 5c8b80e40c
commit 2a92b84f4c
3 changed files with 28 additions and 4 deletions

View File

@@ -65,7 +65,7 @@ export function SearchBar({ className }: { className?: string }) {
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
<Input
type="search"
placeholder="Search users, articles..."
placeholder="Search users, articles, #tags..."
value={searchTerm}
onChange={(e) => handleInputChange(e.target.value)}
onKeyDown={handleKeyDown}

View File

@@ -20,7 +20,27 @@ export function useSearch(searchTerm: string, enabled = true) {
return [];
}
// Query both profiles (kind 0) and articles (kind 30023) in one request
// Check if the search term is a hashtag
const isHashtagSearch = term.startsWith('#');
const tagValue = isHashtagSearch ? term.slice(1) : term;
// If hashtag search, query specifically for articles with that tag
if (isHashtagSearch && tagValue) {
const events = await nostr.query(
[
{
kinds: [30023],
'#t': [tagValue],
limit: 100,
},
],
{ signal }
);
return events.map((event) => ({ type: 'article' as const, event }));
}
// Regular search: Query both profiles (kind 0) and articles (kind 30023) in one request
const events = await nostr.query(
[
{

View File

@@ -72,10 +72,14 @@ export default function SearchResultsPage() {
{searchTerm && (
<div>
<h1 className="text-3xl font-bold">
Search Results for "{searchTerm}"
{searchTerm.startsWith('#') ? (
<>Articles tagged with "{searchTerm}"</>
) : (
<>Search Results for "{searchTerm}"</>
)}
</h1>
<p className="text-muted-foreground mt-2">
Found {results?.length || 0} results
Found {results?.length || 0} {searchTerm.startsWith('#') ? 'articles' : 'results'}
</p>
</div>
)}