feat: show bio in user context sheet
Signed-off-by: Infi <wingit@geist.ga>
This commit is contained in:
parent
5a365e8bd2
commit
df35bf979e
|
|
@ -3,6 +3,8 @@ package chat.revolt.components.generic
|
|||
import android.text.SpannableStringBuilder
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
import android.view.ViewGroup
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.material3.LocalTextStyle
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
|
|
@ -96,7 +98,12 @@ fun UIMarkdown(
|
|||
|
||||
setTextColor(foregroundColor.toArgb())
|
||||
setMaxLines(maxLines)
|
||||
setTextSize(android.util.TypedValue.COMPLEX_UNIT_SP, fontSize.value)
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize.value)
|
||||
|
||||
layoutParams = ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
}
|
||||
},
|
||||
modifier = modifier,
|
||||
|
|
|
|||
|
|
@ -50,12 +50,19 @@ fun UserOverview(user: User) {
|
|||
|
||||
LaunchedEffect(user) {
|
||||
try {
|
||||
profile = fetchUserProfile(user.id ?: ULID.makeSpecial(0))
|
||||
if (profile == null) {
|
||||
profile = fetchUserProfile(user.id ?: ULID.makeSpecial(0))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
RawUserOverview(user, profile)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun RawUserOverview(user: User, profile: Profile? = null) {
|
||||
Box(
|
||||
contentAlignment = Alignment.BottomStart,
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,32 @@
|
|||
package chat.revolt.sheets
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import chat.revolt.R
|
||||
import chat.revolt.api.RevoltAPI
|
||||
import chat.revolt.components.screens.settings.UserOverview
|
||||
import chat.revolt.api.routes.user.fetchUserProfile
|
||||
import chat.revolt.api.schemas.Profile
|
||||
import chat.revolt.components.generic.UIMarkdown
|
||||
import chat.revolt.components.screens.settings.RawUserOverview
|
||||
|
||||
@Composable
|
||||
fun UserContextSheet(
|
||||
|
|
@ -12,11 +35,48 @@ fun UserContextSheet(
|
|||
) {
|
||||
val user = RevoltAPI.userCache[userId]
|
||||
|
||||
var profile by remember { mutableStateOf<Profile?>(null) }
|
||||
|
||||
LaunchedEffect(user) {
|
||||
try {
|
||||
user?.id?.let { fetchUserProfile(it) }?.let { profile = it }
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
Column(
|
||||
modifier = Modifier.verticalScroll(rememberScrollState())
|
||||
) {
|
||||
RawUserOverview(user, profile)
|
||||
Text(
|
||||
text = stringResource(id = R.string.user_context_sheet_category_bio),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
modifier = Modifier.padding(bottom = 10.dp, start = 16.dp, top = 20.dp, end = 16.dp)
|
||||
)
|
||||
|
||||
if (profile?.content != null) {
|
||||
UIMarkdown(
|
||||
text = profile!!.content!!,
|
||||
modifier = Modifier.padding(horizontal = 16.dp)
|
||||
)
|
||||
} else if (profile != null) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.user_context_sheet_bio_empty),
|
||||
modifier = Modifier.padding(horizontal = 16.dp)
|
||||
)
|
||||
} else {
|
||||
Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxWidth()) {
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
|
|
@ -179,6 +179,9 @@
|
|||
<string name="server_context_sheet_actions_copy_id_copied">Copied server ID to clipboard</string>
|
||||
<string name="server_context_sheet_actions_mark_read">Mark as read</string>
|
||||
|
||||
<string name="user_context_sheet_category_bio">Bio</string>
|
||||
<string name="user_context_sheet_bio_empty">This user hasn\'t set a bio yet.</string>
|
||||
|
||||
<string name="add_server_sheet_title">Add a server</string>
|
||||
<string name="add_server_sheet_join_by_invite">Join by invite code or link</string>
|
||||
<string name="add_server_sheet_join_by_invite_modal_title">Invite code or link</string>
|
||||
|
|
|
|||
Loading…
Reference in New Issue