Optimizing UserProfile status

This commit is contained in:
Vitor Pamplona
2023-05-28 17:33:01 -04:00
parent 013eedd892
commit b513877552
@@ -439,20 +439,39 @@ private fun ProfileActions(
coroutineScope: CoroutineScope coroutineScope: CoroutineScope
) { ) {
val accountUserState by account.userProfile().live().follows.observeAsState() val accountUserState by account.userProfile().live().follows.observeAsState()
val accountLocalUserState by account.live.observeAsState()
val accountUser = remember(accountUserState) { accountUserState?.user } ?: return val accountUser = remember(accountUserState) { accountUserState?.user } ?: return
val isHidden by remember(accountUserState, accountLocalUserState) {
derivedStateOf {
account.isHidden(baseUser)
}
}
val isLoggedInFollowingUser by remember(accountUserState, accountLocalUserState) {
derivedStateOf {
accountUser.isFollowingCached(baseUser)
}
}
val isUserFollowingLoggedIn by remember(accountUserState, accountLocalUserState) {
derivedStateOf {
baseUser.isFollowingCached(accountUser)
}
}
if (accountUser == baseUser) { if (accountUser == baseUser) {
EditButton(account) EditButton(account)
} }
if (account.isHidden(baseUser)) { if (isHidden) {
ShowUserButton { ShowUserButton {
account.showUser(baseUser.pubkeyHex) account.showUser(baseUser.pubkeyHex)
} }
} else if (accountUser.isFollowingCached(baseUser)) { } else if (isLoggedInFollowingUser) {
UnfollowButton { coroutineScope.launch(Dispatchers.IO) { account.unfollow(baseUser) } } UnfollowButton { coroutineScope.launch(Dispatchers.IO) { account.unfollow(baseUser) } }
} else { } else {
if (baseUser.isFollowingCached(accountUser)) { if (isUserFollowingLoggedIn) {
FollowButton( FollowButton(
{ coroutineScope.launch(Dispatchers.IO) { account.follow(baseUser) } }, { coroutineScope.launch(Dispatchers.IO) { account.follow(baseUser) } },
R.string.follow_back R.string.follow_back