Improve handling of the profile tabs
This commit is contained in:
@@ -329,24 +329,28 @@ class DatabaseNostrRepository(
|
||||
|
||||
return when {
|
||||
synchronizationFilter.kinds != null && synchronizationFilter.search != null -> {
|
||||
logger.d("observeFilteredNostrEvents: $synchronizationFilter")
|
||||
database.nostrEventDao().observeFilteredNostrEvents(
|
||||
kinds = synchronizationFilter.kinds,
|
||||
search = synchronizationFilter.search
|
||||
)
|
||||
}
|
||||
synchronizationFilter.kinds != null && synchronizationFilter.ids != null -> {
|
||||
logger.d("observeFilteredNostrEvents: $synchronizationFilter")
|
||||
database.nostrEventDao().observeFilteredNostrEvents(
|
||||
kinds = synchronizationFilter.kinds,
|
||||
ids = synchronizationFilter.ids
|
||||
)
|
||||
}
|
||||
synchronizationFilter.kinds != null && synchronizationFilter.authors != null -> {
|
||||
logger.d("observeAuthoredNostrEvents: $synchronizationFilter")
|
||||
database.nostrEventDao().observeAuthoredNostrEvents(
|
||||
kinds = synchronizationFilter.kinds,
|
||||
authors = synchronizationFilter.authors
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
logger.d("observeNostrEvents: $synchronizationFilter")
|
||||
database.nostrEventDao().observeNostrEvents(
|
||||
kinds = arrayOf(
|
||||
TextNoteEvent.KIND,
|
||||
|
||||
@@ -47,6 +47,7 @@ import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.rememberTopAppBarState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.key
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -74,10 +75,9 @@ fun MetadataEventDetail(
|
||||
|
||||
val metadataEventDetailViewModel: MetadataEventDetailViewModel = viewModel(
|
||||
factory = MetadataEventDetailViewModel.factory(
|
||||
initialMetadataEventDetailType = MetadataEventDetailType.Posts,
|
||||
publicKey = localNostrEvent.nostrEvent.pubKey,
|
||||
nostrRepository = nostrRepository,
|
||||
pagerState = rememberPagerState { SearchResultType.entries.size }
|
||||
pagerState = rememberPagerState { MetadataEventDetailType.entries.size }
|
||||
),
|
||||
)
|
||||
|
||||
@@ -193,11 +193,8 @@ fun MetadataEventDetail(
|
||||
Tab(
|
||||
selected = metadataEventDetailViewModel.pagerState.currentPage == index,
|
||||
onClick = {
|
||||
|
||||
metadataEventDetailViewModel.updateMetadataEventDetailType(destination) {
|
||||
scope.launch {
|
||||
metadataEventDetailViewModel.pagerState.animateScrollToPage(destination.ordinal)
|
||||
}
|
||||
scope.launch {
|
||||
metadataEventDetailViewModel.pagerState.animateScrollToPage(destination.ordinal)
|
||||
}
|
||||
},
|
||||
text = {
|
||||
@@ -217,22 +214,27 @@ fun MetadataEventDetail(
|
||||
HorizontalPager(
|
||||
state = metadataEventDetailViewModel.pagerState,
|
||||
) { pageIndex ->
|
||||
when (MetadataEventDetailType.entries[pageIndex]) {
|
||||
val metadataEventDetailType = MetadataEventDetailType.entries[pageIndex]
|
||||
|
||||
when (metadataEventDetailType) {
|
||||
MetadataEventDetailType.Posts, MetadataEventDetailType.Replies,
|
||||
MetadataEventDetailType.Articles, MetadataEventDetailType.Zaps,
|
||||
MetadataEventDetailType.Photos, MetadataEventDetailType.Videos,
|
||||
MetadataEventDetailType.Bookmarks, MetadataEventDetailType.Reports, MetadataEventDetailType.Relays -> {
|
||||
val feedListViewModel: FeedListViewModel = viewModel(
|
||||
key = metadataEventDetailType.name,
|
||||
factory = FeedListViewModel.factory(
|
||||
initialFeedListUIState = FeedListUIState.Loading,
|
||||
synchronizationFilter = metadataEventDetailViewModel.getSynchronizationFilter(),
|
||||
synchronizationFilter = metadataEventDetailViewModel.getSynchronizationFilter(metadataEventDetailType),
|
||||
nostrRepository = nostrRepository
|
||||
),
|
||||
)
|
||||
|
||||
feedListViewModel.RenderFeed(
|
||||
onNavigateToEvent = onNavigateToEvent
|
||||
)
|
||||
key(feedListViewModel.feedListUIState) {
|
||||
feedListViewModel.RenderFeed(
|
||||
onNavigateToEvent = onNavigateToEvent
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
MetadataEventDetailType.Following -> {
|
||||
@@ -244,26 +246,8 @@ fun MetadataEventDetail(
|
||||
Text("Implementing logic to see followers")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LaunchedEffect(true) {
|
||||
metadataEventDetailViewModel.updateMetadataEventDetailType(
|
||||
MetadataEventDetailType.Posts
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(true) {
|
||||
metadataEventDetailViewModel.updateMetadataEventDetailType(
|
||||
MetadataEventDetailType.Posts
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,21 +70,12 @@ class FeedListViewModel(
|
||||
fun observeLocalNostrFeed() {
|
||||
logger.d("observeLocalNostrFeed")
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
// Get contact list and sync feed...
|
||||
|
||||
val localProfile = nostrRepository.observeProfile(SeedManager.activePublicKey().toHexKey()).firstOrNull()
|
||||
|
||||
if (localProfile?.profile == null) {
|
||||
feedListUIState = FeedListUIState.Error
|
||||
} else {
|
||||
nostrRepository.observeNostrFeed(
|
||||
synchronizationFilter
|
||||
).collect { localNostrEvents ->
|
||||
feedListUIState = FeedListUIState.Loaded(
|
||||
localNostrEvents = localNostrEvents
|
||||
)
|
||||
}
|
||||
|
||||
nostrRepository.observeNostrFeed(
|
||||
synchronizationFilter
|
||||
).collect { localNostrEvents ->
|
||||
feedListUIState = FeedListUIState.Loaded(
|
||||
localNostrEvents = localNostrEvents
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,23 +35,15 @@ enum class MetadataEventDetailType {
|
||||
}
|
||||
|
||||
class MetadataEventDetailViewModel(
|
||||
initialMetadataEventDetailType: MetadataEventDetailType,
|
||||
val publicKey: HexKey,
|
||||
val nostrRepository: NostrRepository,
|
||||
val pagerState: PagerState
|
||||
): ViewModel() {
|
||||
val logger = Logger.withTag(TAG)
|
||||
|
||||
var metadataEventDetailType: MetadataEventDetailType by mutableStateOf(initialMetadataEventDetailType)
|
||||
private set
|
||||
|
||||
fun updateMetadataEventDetailType (metadataEventDetailType: MetadataEventDetailType, navigateToPage: () -> Unit) {
|
||||
this.metadataEventDetailType = metadataEventDetailType
|
||||
|
||||
navigateToPage.invoke()
|
||||
}
|
||||
|
||||
fun getSynchronizationFilter() = when (metadataEventDetailType) {
|
||||
fun getSynchronizationFilter(
|
||||
metadataEventDetailType: MetadataEventDetailType
|
||||
) = when (metadataEventDetailType) {
|
||||
MetadataEventDetailType.Posts -> {
|
||||
SynchronizationFilter(
|
||||
authors = arrayOf(
|
||||
@@ -186,14 +178,12 @@ class MetadataEventDetailViewModel(
|
||||
const val TAG = "MetadataEventDetailViewModel"
|
||||
|
||||
fun factory(
|
||||
initialMetadataEventDetailType: MetadataEventDetailType = MetadataEventDetailType.Posts,
|
||||
publicKey: HexKey,
|
||||
nostrRepository: NostrRepository,
|
||||
pagerState: PagerState
|
||||
): ViewModelProvider.Factory = viewModelFactory {
|
||||
initializer {
|
||||
MetadataEventDetailViewModel(
|
||||
initialMetadataEventDetailType = initialMetadataEventDetailType,
|
||||
nostrRepository = nostrRepository,
|
||||
pagerState = pagerState,
|
||||
publicKey = publicKey
|
||||
|
||||
Reference in New Issue
Block a user