fix(search): cleanup review findings — dead code, FQN refs, naming

- Remove unused `key` param from ExpandableSection
- Replace FQN references with imports in AdvancedSearchPanel and SearchScreen
- Use MetadataEvent.KIND instead of magic `0`
- Remove dead `relayStatuses` collection (only `connectedRelays` used)
- Remove CachedUserResult sealed variant (never constructed)
- Rename SearchHint `identifier` param to `example`

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
nrobi144
2026-03-11 07:28:04 +02:00
parent e8e2650fa9
commit a702dcc0ee
4 changed files with 15 additions and 34 deletions
@@ -20,8 +20,6 @@
*/
package com.vitorpamplona.amethyst.commons.search
import com.vitorpamplona.amethyst.commons.model.User
/**
* Represents a parsed search result from Bech32/hex input.
* Shared between Android and Desktop for consistent search behavior.
@@ -35,13 +33,6 @@ sealed class SearchResult {
val displayId: String,
) : SearchResult()
/**
* User from local cache with full metadata.
*/
data class CachedUserResult(
val user: User,
) : SearchResult()
/**
* Note lookup from note1 or nevent.
*/
@@ -81,6 +81,8 @@ import androidx.compose.ui.unit.dp
import com.vitorpamplona.amethyst.commons.model.User
import com.vitorpamplona.amethyst.commons.search.AdvancedSearchBarState
import com.vitorpamplona.amethyst.commons.search.QuerySerializer
import com.vitorpamplona.amethyst.commons.search.SavedSearch
import com.vitorpamplona.amethyst.commons.search.SearchQuery
import com.vitorpamplona.amethyst.commons.search.SearchResult
import com.vitorpamplona.amethyst.commons.search.SearchResultFilter
import com.vitorpamplona.amethyst.commons.search.parseSearchInput
@@ -121,7 +123,6 @@ fun SearchScreen(
}
}
val relayStatuses by relayManager.relayStatuses.collectAsState()
val connectedRelays by relayManager.connectedRelays.collectAsState()
val displayText by state.displayText.collectAsState()
val query by state.query.collectAsState()
@@ -149,8 +150,7 @@ fun SearchScreen(
relays = connectedRelays,
searchQuery =
debouncedQuery.text.ifBlank {
com.vitorpamplona.amethyst.commons.search.QuerySerializer
.serialize(debouncedQuery)
QuerySerializer.serialize(debouncedQuery)
},
limit = 20,
onEvent = { event, _, _, _ ->
@@ -185,7 +185,7 @@ fun SearchScreen(
relays = connectedRelays,
onEvent = { event, _, _, _ ->
// Skip metadata events (handled by people search)
if (event.kind == 0) return@SubscriptionConfig
if (event.kind == MetadataEvent.KIND) return@SubscriptionConfig
val filtered = SearchResultFilter.filter(listOf(event), debouncedQuery)
if (filtered.isNotEmpty()) {
state.addNoteResults(filtered)
@@ -407,9 +407,9 @@ fun SearchScreen(
@Composable
private fun SearchEmptyState(
historyItems: List<com.vitorpamplona.amethyst.commons.search.SearchQuery>,
savedSearches: List<com.vitorpamplona.amethyst.commons.search.SavedSearch>,
onLoadQuery: (com.vitorpamplona.amethyst.commons.search.SearchQuery) -> Unit,
historyItems: List<SearchQuery>,
savedSearches: List<SavedSearch>,
onLoadQuery: (SearchQuery) -> Unit,
onDeleteSaved: (String) -> Unit,
onClearHistory: () -> Unit,
) {
@@ -542,7 +542,7 @@ private fun SearchEmptyState(
@Composable
private fun SearchHint(
identifier: String,
example: String,
description: String,
) {
Row(
@@ -550,7 +550,7 @@ private fun SearchHint(
horizontalArrangement = Arrangement.SpaceBetween,
) {
Text(
identifier,
example,
style = MaterialTheme.typography.bodySmall,
fontFamily = FontFamily.Monospace,
color = MaterialTheme.colorScheme.primary,
@@ -578,7 +578,6 @@ private fun SearchResultCard(
.clickable {
when (result) {
is SearchResult.UserResult -> onNavigateToProfile(result.pubKeyHex)
is SearchResult.CachedUserResult -> onNavigateToProfile(result.user.pubkeyHex)
is SearchResult.NoteResult -> onNavigateToThread(result.noteIdHex)
is SearchResult.AddressResult -> onNavigateToThread("${result.kind}:${result.pubKeyHex}:${result.dTag}")
is SearchResult.HashtagResult -> onNavigateToHashtag(result.hashtag)
@@ -598,7 +597,6 @@ private fun SearchResultCard(
imageVector =
when (result) {
is SearchResult.UserResult -> Icons.Default.Person
is SearchResult.CachedUserResult -> Icons.Default.Person
is SearchResult.NoteResult -> Icons.Default.Description
is SearchResult.AddressResult -> Icons.Default.Description
is SearchResult.HashtagResult -> Icons.Default.Tag
@@ -612,7 +610,6 @@ private fun SearchResultCard(
Text(
when (result) {
is SearchResult.UserResult -> "User Profile"
is SearchResult.CachedUserResult -> result.user.toBestDisplayName()
is SearchResult.NoteResult -> "Note"
is SearchResult.AddressResult -> "Event (kind ${result.kind})"
is SearchResult.HashtagResult -> "#${result.hashtag}"
@@ -623,7 +620,6 @@ private fun SearchResultCard(
Text(
when (result) {
is SearchResult.UserResult -> result.displayId
is SearchResult.CachedUserResult -> result.user.pubkeyDisplayHex()
is SearchResult.NoteResult -> result.displayId
is SearchResult.AddressResult -> result.displayId
is SearchResult.HashtagResult -> "Search posts with this hashtag"
@@ -56,7 +56,9 @@ import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onKeyEvent
import androidx.compose.ui.unit.dp
import com.vitorpamplona.amethyst.commons.search.DateUtils
import com.vitorpamplona.amethyst.commons.search.KindRegistry
import com.vitorpamplona.amethyst.commons.search.QueryParser
import com.vitorpamplona.amethyst.commons.search.SearchQuery
@OptIn(ExperimentalLayoutApi::class)
@@ -243,16 +245,14 @@ private fun DateRangeFields(
var sinceText by remember(since) {
mutableStateOf(
since?.let {
com.vitorpamplona.amethyst.commons.search.QuerySerializer
.timestampToDate(it)
DateUtils.timestampToDate(it)
} ?: "",
)
}
var untilText by remember(until) {
mutableStateOf(
until?.let {
com.vitorpamplona.amethyst.commons.search.QuerySerializer
.timestampToDate(it)
DateUtils.timestampToDate(it)
} ?: "",
)
}
@@ -272,8 +272,7 @@ private fun DateRangeFields(
onValueChange = {
sinceText = it
val ts =
com.vitorpamplona.amethyst.commons.search.QueryParser
.parseDateToTimestamp(it)
QueryParser.parseDateToTimestamp(it)
onChanged(ts, until)
},
modifier = Modifier.fillMaxWidth(),
@@ -292,8 +291,7 @@ private fun DateRangeFields(
onValueChange = {
untilText = it
val ts =
com.vitorpamplona.amethyst.commons.search.QueryParser
.parseDateToTimestamp(it)
QueryParser.parseDateToTimestamp(it)
onChanged(since, ts)
},
modifier = Modifier.fillMaxWidth(),
@@ -118,7 +118,6 @@ fun SearchResultsList(
item(key = "people-expand") {
ExpandableSection(
remaining = people.drop(5),
key = { "person-more-${it.pubkeyHex}" },
) { user ->
UserSearchCard(
user = user,
@@ -145,7 +144,6 @@ fun SearchResultsList(
item(key = "notes-expand") {
ExpandableSection(
remaining = textNotes.drop(5),
key = { "note-more-${it.id}" },
) { event ->
NotePreviewCard(event = event, onClick = { onNavigateToThread(event.id) })
}
@@ -168,7 +166,6 @@ fun SearchResultsList(
item(key = "articles-expand") {
ExpandableSection(
remaining = articles.drop(5),
key = { "article-more-${it.id}" },
) { event ->
NotePreviewCard(event = event, onClick = { onNavigateToThread(event.id) })
}
@@ -277,7 +274,6 @@ private fun NotePreviewCard(
@Composable
private fun <T> ExpandableSection(
remaining: List<T>,
key: (T) -> String,
content: @Composable (T) -> Unit,
) {
var expanded by remember { mutableStateOf(false) }