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