feat: show which search results are already in the target mood
This commit is contained in:
1 parent
375bcc9c37
commit
6bfa12d673
4 files changed
+23
-4
No files matched your search
@@ -179,8 +179,10 @@ class ApiClient(private val http: HttpClient) {
|
||||
suspend fun preview(moodId: String, limit: Int = 20): List<Song> =
|
||||
get<TracksResponse>("/moods/$moodId/preview?limit=$limit").songs
|
||||
|
||||
suspend fun search(query: String, limit: Int = 20): List<SearchResult> =
|
||||
get<SearchResponse>("/search?q=${query.encodeURLParameter()}&limit=$limit").results
|
||||
suspend fun search(query: String, limit: Int = 20, moodId: String? = null): List<SearchResult> {
|
||||
val mood = moodId?.let { "&moodId=${it.encodeURLParameter()}" }.orEmpty()
|
||||
return get<SearchResponse>("/search?q=${query.encodeURLParameter()}&limit=$limit$mood").results
|
||||
}
|
||||
|
||||
suspend fun startSession(moodId: String, limit: Int = 12): Session =
|
||||
parse(
|
||||
|
||||
@@ -129,6 +129,7 @@ data class SearchResult(
|
||||
val thumbnail: String? = null,
|
||||
val songId: String? = null,
|
||||
val downloaded: Boolean = false,
|
||||
val inMood: Boolean = false,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
|
||||
@@ -345,6 +345,7 @@ class AppStore(
|
||||
|
||||
fun selectSearchMood(moodId: String) {
|
||||
_state.update { it.copy(searchTargetMoodId = moodId) }
|
||||
if (_state.value.searchQuery.isNotBlank()) search(_state.value.searchQuery)
|
||||
}
|
||||
|
||||
fun setSearchQuery(query: String) {
|
||||
@@ -362,7 +363,7 @@ class AppStore(
|
||||
delay(SEARCH_DEBOUNCE_MS)
|
||||
_state.update { it.copy(searching = true) }
|
||||
try {
|
||||
val results = api.search(query, 20)
|
||||
val results = api.search(query, 20, _state.value.searchTargetMoodId)
|
||||
_state.update { it.copy(searchResults = results) }
|
||||
} catch (t: CancellationException) {
|
||||
throw t
|
||||
|
||||
@@ -186,7 +186,22 @@ private fun SearchRow(result: SearchResult, store: AppStore) {
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
if (result.downloaded) {
|
||||
if (result.inMood) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(
|
||||
Icons.Rounded.Check,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.size(14.dp),
|
||||
)
|
||||
Spacer(Modifier.width(4.dp))
|
||||
Text(
|
||||
"Already in this mood",
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
}
|
||||
} else if (result.downloaded) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(
|
||||
Icons.Rounded.DownloadDone,
|
||||
|
||||
Reference in new issue
Block a user