-
Notifications
You must be signed in to change notification settings - Fork 1
/
SearchView.kt
70 lines (64 loc) · 2.38 KB
/
SearchView.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.dluvian.voyage.ui.views.nonMain.search
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.dluvian.nostr_kt.createNprofile
import com.dluvian.voyage.R
import com.dluvian.voyage.core.OnUpdate
import com.dluvian.voyage.core.OpenProfile
import com.dluvian.voyage.core.OpenTopic
import com.dluvian.voyage.core.Topic
import com.dluvian.voyage.core.viewModel.SearchViewModel
import com.dluvian.voyage.data.room.view.AdvancedProfileView
import com.dluvian.voyage.ui.components.row.ClickableProfileRow
import com.dluvian.voyage.ui.components.row.ClickableRow
import com.dluvian.voyage.ui.components.text.SectionHeader
import com.dluvian.voyage.ui.theme.HashtagIcon
@Composable
fun SearchView(vm: SearchViewModel, snackbar: SnackbarHostState, onUpdate: OnUpdate) {
val topics by vm.topics
val profiles by vm.profiles
LaunchedEffect(key1 = Unit) {
vm.subProfiles()
}
SearchScaffold(snackbar = snackbar, onUpdate = onUpdate) {
SearchViewContent(topics = topics, profiles = profiles, onUpdate = onUpdate)
}
}
@Composable
private fun SearchViewContent(
topics: List<Topic>,
profiles: List<AdvancedProfileView>,
onUpdate: OnUpdate
) {
LazyColumn(modifier = Modifier.fillMaxSize()) {
if (topics.isNotEmpty()) {
item {
SectionHeader(header = stringResource(id = R.string.topics))
}
items(topics) { topic ->
ClickableRow(header = topic,
imageVector = HashtagIcon,
onClick = { onUpdate(OpenTopic(topic = topic)) })
}
}
if (profiles.isNotEmpty()) {
item {
SectionHeader(header = stringResource(id = R.string.profiles))
}
items(profiles) { profile ->
ClickableProfileRow(
profile = profile,
onClick = {
onUpdate(OpenProfile(nprofile = createNprofile(hex = profile.pubkey)))
})
}
}
}
}