feat: put rudimentary content into user sheet

Signed-off-by: Infi <wingit@geist.ga>
This commit is contained in:
Infi 2023-06-16 00:16:58 +02:00
parent 7bd65105f3
commit 80b1c9e093
3 changed files with 50 additions and 13 deletions

View File

@ -32,6 +32,7 @@ import chat.revolt.api.RevoltAPI
import chat.revolt.api.internals.ULID
import chat.revolt.api.routes.user.fetchUserProfile
import chat.revolt.api.schemas.Profile
import chat.revolt.api.schemas.User
import chat.revolt.components.generic.RemoteImage
import chat.revolt.components.generic.UserAvatar
import chat.revolt.components.generic.presenceFromStatus
@ -39,10 +40,20 @@ import chat.revolt.components.generic.presenceFromStatus
@Composable
fun SelfUserOverview() {
val selfUser = RevoltAPI.userCache[RevoltAPI.selfId] ?: return
UserOverview(selfUser)
}
@Composable
fun UserOverview(user: User) {
var profile by remember { mutableStateOf<Profile?>(null) }
LaunchedEffect(selfUser) {
profile = fetchUserProfile(selfUser.id ?: ULID.makeSpecial(0))
LaunchedEffect(user) {
try {
profile = fetchUserProfile(user.id ?: ULID.makeSpecial(0))
} catch (e: Exception) {
e.printStackTrace()
}
}
Box(
@ -80,26 +91,26 @@ fun SelfUserOverview() {
.fillMaxWidth()
) {
UserAvatar(
username = selfUser.displayName ?: stringResource(id = R.string.unknown),
userId = selfUser.id ?: ULID.makeSpecial(0),
avatar = selfUser.avatar,
username = user.displayName ?: stringResource(id = R.string.unknown),
userId = user.id ?: ULID.makeSpecial(0),
avatar = user.avatar,
size = 48.dp,
presence = presenceFromStatus(selfUser.status?.presence ?: "Offline"),
presence = presenceFromStatus(user.status?.presence ?: "Offline"),
)
Spacer(modifier = Modifier.width(12.dp))
Text(
text = AnnotatedString.Builder().apply {
if (selfUser.displayName != null) {
if (user.displayName != null) {
pushStyle(SpanStyle(fontWeight = FontWeight.Bold))
append(selfUser.displayName)
append(user.displayName)
pop()
append("\n")
}
append("${selfUser.username}")
append("${user.username}")
pushStyle(SpanStyle(fontWeight = FontWeight.ExtraLight))
append("#${selfUser.discriminator}")
append("#${user.discriminator}")
pop()
}.toAnnotatedString(),
color = if (profile?.background != null) Color.White else LocalContentColor.current,

View File

@ -70,6 +70,7 @@ import chat.revolt.screens.chat.views.NoCurrentChannelScreen
import chat.revolt.screens.chat.views.channel.ChannelScreen
import chat.revolt.sheets.AddServerSheet
import chat.revolt.sheets.StatusSheet
import chat.revolt.sheets.UserContextSheet
import com.airbnb.lottie.RenderMode
import com.airbnb.lottie.compose.LottieAnimation
import com.airbnb.lottie.compose.LottieCompositionSpec
@ -335,9 +336,12 @@ fun ChatRouterScreen(topNav: NavController, viewModel: ChatRouterViewModel = hil
showUserContextSheet = false
},
) {
Column {
Text(text = "this is user context sheet for $userContextSheetTarget")
}
UserContextSheet(
userId = userContextSheetTarget,
onHideSheet = {
userContextSheetState.hide()
}
)
}
}

View File

@ -0,0 +1,22 @@
package chat.revolt.sheets
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import chat.revolt.api.RevoltAPI
import chat.revolt.components.screens.settings.UserOverview
@Composable
fun UserContextSheet(
userId: String,
onHideSheet: suspend () -> Unit,
) {
val user = RevoltAPI.userCache[userId]
if (user == null) {
// TODO fetch user in this scenario
Text(text = "not in user cache, but for now there's always this message")
return
}
UserOverview(user)
}