mirror of
https://github.com/mroxso/zelo-news.git
synced 2026-06-05 18:11:10 +02:00
Enhance search functionality to support hashtag queries and update UI for search results display
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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(
|
||||
[
|
||||
{
|
||||
|
||||
@@ -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>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user