Initialize NostrUserListVM at LoggedInPage level, to reuse it at different places(in prep for other UI changes).

This commit is contained in:
KotlinGeekDev
2025-09-12 13:48:59 +01:00
parent f850d5291e
commit 4118e3d45d
5 changed files with 19 additions and 28 deletions

View File

@@ -79,6 +79,7 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.hashtag.HashtagScreen
import com.vitorpamplona.amethyst.ui.screen.loggedIn.home.HomeScreen
import com.vitorpamplona.amethyst.ui.screen.loggedIn.home.ShortNotePostScreen
import com.vitorpamplona.amethyst.ui.screen.loggedIn.lists.ListsScreen
import com.vitorpamplona.amethyst.ui.screen.loggedIn.lists.NostrUserListFeedViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.lists.followsets.FollowSetScreen
import com.vitorpamplona.amethyst.ui.screen.loggedIn.notifications.NotificationScreen
import com.vitorpamplona.amethyst.ui.screen.loggedIn.notifications.publicMessages.NewPublicMessageScreen
@@ -109,6 +110,7 @@ fun AppNavigation(
accountViewModel: AccountViewModel,
accountStateViewModel: AccountStateViewModel,
sharedPreferencesViewModel: SharedPreferencesViewModel,
listsViewModel: NostrUserListFeedViewModel,
) {
val nav = rememberNav()
@@ -125,9 +127,9 @@ fun AppNavigation(
composable<Route.Discover> { DiscoverScreen(accountViewModel, nav) }
composable<Route.Notification> { NotificationScreen(sharedPreferencesViewModel, accountViewModel, nav) }
composableFromEnd<Route.Lists> { ListsScreen(accountViewModel, nav) }
composableFromEnd<Route.Lists> { ListsScreen(accountViewModel, listsViewModel, nav) }
composableArgs<Route.FollowSetRoute> {
FollowSetScreen(it.setIdentifier, accountViewModel, nav)
FollowSetScreen(it.setIdentifier, accountViewModel, listsViewModel, nav)
}
composable<Route.EditProfile> { NewUserMetadataScreen(nav, accountViewModel) }
@@ -144,7 +146,7 @@ fun AppNavigation(
composableFromEndArgs<Route.EditMediaServers> { AllMediaServersScreen(accountViewModel, nav) }
composableFromEndArgs<Route.ContentDiscovery> { DvmContentDiscoveryScreen(it.id, accountViewModel, nav) }
composableFromEndArgs<Route.Profile> { ProfileScreen(it.id, accountViewModel, nav) }
composableFromEndArgs<Route.Profile> { ProfileScreen(it.id, accountViewModel, listsViewModel, nav) }
composableFromEndArgs<Route.Note> { ThreadScreen(it.id, accountViewModel, nav) }
composableFromEndArgs<Route.Hashtag> { HashtagScreen(it, accountViewModel, nav) }
composableFromEndArgs<Route.Geohash> { GeoHashScreen(it, accountViewModel, nav) }

View File

@@ -53,6 +53,7 @@ import com.vitorpamplona.amethyst.ui.screen.SharedPreferencesViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.rooms.datasource.ChatroomListFilterAssemblerSubscription
import com.vitorpamplona.amethyst.ui.screen.loggedIn.discover.datasource.DiscoveryFilterAssemblerSubscription
import com.vitorpamplona.amethyst.ui.screen.loggedIn.home.datasource.HomeFilterAssemblerSubscription
import com.vitorpamplona.amethyst.ui.screen.loggedIn.lists.NostrUserListFeedViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.video.datasource.VideoFilterAssemblerSubscription
import com.vitorpamplona.quartz.nip55AndroidSigner.client.IActivityLauncher
import kotlinx.coroutines.launch
@@ -75,6 +76,12 @@ fun LoggedInPage(
),
)
val listsViewModel: NostrUserListFeedViewModel =
viewModel(
key = "NostrUserListFeedViewModel",
factory = NostrUserListFeedViewModel.Factory(accountViewModel.account),
)
accountViewModel.firstRoute = route
// Adds this account to the authentication procedures for relays.
@@ -111,6 +118,7 @@ fun LoggedInPage(
accountViewModel = accountViewModel,
accountStateViewModel = accountStateViewModel,
sharedPreferencesViewModel = sharedPreferencesViewModel,
listsViewModel = listsViewModel,
)
}

View File

@@ -56,7 +56,6 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.ui.layouts.DisappearingScaffold
import com.vitorpamplona.amethyst.ui.navigation.navs.INav
@@ -73,15 +72,9 @@ import kotlinx.coroutines.launch
@Composable
fun ListsScreen(
accountViewModel: AccountViewModel,
followSetsViewModel: NostrUserListFeedViewModel,
nav: INav,
) {
val followSetsViewModel: NostrUserListFeedViewModel =
viewModel(
key = "NostrUserListFeedViewModel",
factory = NostrUserListFeedViewModel.Factory(accountViewModel.account),
)
val currentCoroutineScope = rememberCoroutineScope()
val lifeCycleOwner = LocalLifecycleOwner.current
DisposableEffect(lifeCycleOwner) {

View File

@@ -60,7 +60,6 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.ui.components.ClickableBox
@@ -84,14 +83,9 @@ import kotlinx.coroutines.launch
fun FollowSetScreen(
selectedSetIdentifier: String,
accountViewModel: AccountViewModel,
followSetViewModel: NostrUserListFeedViewModel,
navigator: INav,
) {
val followSetViewModel: NostrUserListFeedViewModel =
viewModel(
key = "NostrUserListFeedViewModel",
factory = NostrUserListFeedViewModel.Factory(accountViewModel.account),
)
val followSetState by followSetViewModel.feedContent.collectAsState()
val uiScope = rememberCoroutineScope()

View File

@@ -104,6 +104,7 @@ import kotlinx.coroutines.launch
fun ProfileScreen(
userId: String?,
accountViewModel: AccountViewModel,
nostrListsViewModel: NostrUserListFeedViewModel,
nav: INav,
) {
if (userId == null) return
@@ -123,6 +124,7 @@ fun ProfileScreen(
PrepareViewModels(
baseUser = it,
accountViewModel = accountViewModel,
nostrListsViewModel = nostrListsViewModel,
nav = nav,
)
}
@@ -132,6 +134,7 @@ fun ProfileScreen(
fun PrepareViewModels(
baseUser: User,
accountViewModel: AccountViewModel,
nostrListsViewModel: NostrUserListFeedViewModel,
nav: INav,
) {
val followsFeedViewModel: UserProfileFollowsUserFeedViewModel =
@@ -228,15 +231,6 @@ fun PrepareViewModels(
),
)
val followSetsViewModel: NostrUserListFeedViewModel =
viewModel(
key = "NostrUserListFeedViewModel",
factory =
NostrUserListFeedViewModel.Factory(
accountViewModel.account,
),
)
ProfileScreen(
baseUser = baseUser,
threadsViewModel,
@@ -249,7 +243,7 @@ fun PrepareViewModels(
bookmarksFeedViewModel,
galleryFeedViewModel,
reportsFeedViewModel,
followSetsViewModel,
nostrListsViewModel,
accountViewModel = accountViewModel,
nav = nav,
)