refactor(search): extract shared code to commons, remove dead code
- Extract DateUtils (isLeapYear, dateToUnix, timestampToDate) to deduplicate identical implementations in QueryParser and QuerySerializer - Move SavedSearch data class from desktopApp to commons/search - Replace local formatTimestamp with existing toTimeAgo from commons/util - Remove dead code: resolveAuthorName, _authorSuggestions (never called) - Remove dead code: createOrFilters (never wired into SearchScreen) - Remove unused ICacheProvider dependency from AdvancedSearchBarState Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+1
-7
@@ -22,6 +22,7 @@ package com.vitorpamplona.amethyst.desktop
|
||||
|
||||
import com.vitorpamplona.amethyst.commons.search.QueryParser
|
||||
import com.vitorpamplona.amethyst.commons.search.QuerySerializer
|
||||
import com.vitorpamplona.amethyst.commons.search.SavedSearch
|
||||
import com.vitorpamplona.amethyst.commons.search.SearchQuery
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
@@ -134,10 +135,3 @@ object SearchHistoryStore {
|
||||
prefs.put(KEY_SAVED, raw)
|
||||
}
|
||||
}
|
||||
|
||||
data class SavedSearch(
|
||||
val id: String,
|
||||
val label: String,
|
||||
val query: SearchQuery,
|
||||
val createdAt: Long,
|
||||
)
|
||||
|
||||
-13
@@ -128,19 +128,6 @@ object SearchFilterFactory {
|
||||
}
|
||||
}
|
||||
|
||||
fun createOrFilters(
|
||||
query: SearchQuery,
|
||||
limit: Int = 100,
|
||||
): List<List<Filter>> {
|
||||
if (query.orTerms.isEmpty()) return listOf(createFilters(query, limit))
|
||||
|
||||
// Each OR term gets its own set of filters
|
||||
return query.orTerms.take(3).map { term ->
|
||||
val termQuery = query.copy(text = term, orTerms = kotlinx.collections.immutable.persistentListOf())
|
||||
createFilters(termQuery, limit)
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildSearchString(query: SearchQuery): String? {
|
||||
val parts = mutableListOf<String>()
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ fun SearchScreen(
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
val state = remember { AdvancedSearchBarState(localCache, scope) }
|
||||
val state = remember { AdvancedSearchBarState(scope) }
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
|
||||
// Pre-fill initial query
|
||||
@@ -408,7 +408,7 @@ fun SearchScreen(
|
||||
@Composable
|
||||
private fun SearchEmptyState(
|
||||
historyItems: List<com.vitorpamplona.amethyst.commons.search.SearchQuery>,
|
||||
savedSearches: List<com.vitorpamplona.amethyst.desktop.SavedSearch>,
|
||||
savedSearches: List<com.vitorpamplona.amethyst.commons.search.SavedSearch>,
|
||||
onLoadQuery: (com.vitorpamplona.amethyst.commons.search.SearchQuery) -> Unit,
|
||||
onDeleteSaved: (String) -> Unit,
|
||||
onClearHistory: () -> Unit,
|
||||
|
||||
+2
-30
@@ -62,6 +62,7 @@ import androidx.compose.ui.unit.dp
|
||||
import com.vitorpamplona.amethyst.commons.search.AdvancedSearchBarState
|
||||
import com.vitorpamplona.amethyst.commons.search.KindRegistry
|
||||
import com.vitorpamplona.amethyst.commons.ui.components.UserSearchCard
|
||||
import com.vitorpamplona.amethyst.commons.util.toTimeAgo
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip23LongContent.LongTextNoteEvent
|
||||
|
||||
@@ -255,7 +256,7 @@ private fun NotePreviewCard(
|
||||
Spacer(Modifier.weight(1f))
|
||||
// Timestamp
|
||||
Text(
|
||||
formatTimestamp(event.createdAt),
|
||||
event.createdAt.toTimeAgo(withDot = false),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
@@ -296,32 +297,3 @@ private fun <T> ExpandableSection(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatTimestamp(ts: Long): String {
|
||||
val now = System.currentTimeMillis() / 1000
|
||||
val diff = now - ts
|
||||
return when {
|
||||
diff < 60 -> {
|
||||
"just now"
|
||||
}
|
||||
|
||||
diff < 3600 -> {
|
||||
"${diff / 60}m ago"
|
||||
}
|
||||
|
||||
diff < 86400 -> {
|
||||
"${diff / 3600}h ago"
|
||||
}
|
||||
|
||||
diff < 604800 -> {
|
||||
"${diff / 86400}d ago"
|
||||
}
|
||||
|
||||
else -> {
|
||||
// Simple date format
|
||||
val days = ts / 86400
|
||||
val year = 1970 + (days / 365).toInt()
|
||||
"$year"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user