fix: logic and positioning for user dropdown

Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
Infi 2024-06-05 15:10:42 +02:00
parent e9c3b8ec95
commit 3127b95d9e
1 changed files with 59 additions and 59 deletions

View File

@ -5,7 +5,6 @@ import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
@ -218,81 +217,82 @@ fun UserButtons(
"BlockedOther" -> Box(Modifier.weight(1f)) "BlockedOther" -> Box(Modifier.weight(1f))
} }
when (user.relationship) { if (user.relationship != "User") {
"Friend", "Incoming", "Outgoing", "None", "Blocked", "BlockedOther" -> { Row { // Prevent the dropdown menu from counting towards arrangement spacing
Column { // Prevent the dropdown menu from counting towards arrangement spacing DropdownMenu(
IconButton( expanded = menuOpen,
onClick = { onDismissRequest = { menuOpen = false }
menuOpen = true ) {
} when (user.relationship) {
) { "Friend" -> {
Icon( DropdownMenuItem(
imageVector = Icons.Default.MoreVert,
contentDescription = stringResource(R.string.menu)
)
}
DropdownMenu(expanded = menuOpen, onDismissRequest = { menuOpen = false }) {
when (user.relationship) {
"Friend" -> {
DropdownMenuItem(
text = {
Text(stringResource(R.string.user_info_sheet_remove_friend))
},
onClick = {
scope.launch {
unfriendUser(user.id)
}
}
)
}
}
when (user.relationship) {
"Blocked" -> {}
else -> DropdownMenuItem(
text = { text = {
Text(stringResource(R.string.user_info_sheet_block)) Text(stringResource(R.string.user_info_sheet_remove_friend))
}, },
onClick = { onClick = {
scope.launch { scope.launch {
blockUser(user.id) unfriendUser(user.id)
} }
} }
) )
} }
}
DropdownMenuItem( when (user.relationship) {
"Blocked" -> {}
else -> DropdownMenuItem(
text = { text = {
Text(stringResource(R.string.user_info_sheet_copy_id)) Text(stringResource(R.string.user_info_sheet_block))
}, },
onClick = { onClick = {
scope.launch { scope.launch {
clipboard.setText(AnnotatedString(user.id)) blockUser(user.id)
}
}
)
DropdownMenuItem(
text = {
Text(stringResource(R.string.user_info_sheet_report))
},
onClick = {
scope.launch {
ActionChannel.send(Action.ReportUser(user.id))
if (Platform.needsShowClipboardNotification()) {
Toast.makeText(
context,
context.getString(R.string.copied),
Toast.LENGTH_SHORT
).show()
}
} }
} }
) )
} }
DropdownMenuItem(
text = {
Text(stringResource(R.string.user_info_sheet_copy_id))
},
onClick = {
scope.launch {
clipboard.setText(AnnotatedString(user.id))
}
}
)
DropdownMenuItem(
text = {
Text(stringResource(R.string.user_info_sheet_report))
},
onClick = {
scope.launch {
ActionChannel.send(Action.ReportUser(user.id))
if (Platform.needsShowClipboardNotification()) {
Toast.makeText(
context,
context.getString(R.string.copied),
Toast.LENGTH_SHORT
).show()
}
}
}
)
}
IconButton(
onClick = {
menuOpen = true
}
) {
Icon(
imageVector = Icons.Default.MoreVert,
contentDescription = stringResource(R.string.menu)
)
} }
} }
} }