1
Fork 0
mirror of https://github.com/Steffo99/twom.git synced 2024-11-25 01:24:24 +00:00

Improve error and loading display

This commit is contained in:
Steffo 2024-01-17 12:52:36 +01:00
parent 6c6eaaf58e
commit 5083f8dfcf
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
12 changed files with 136 additions and 80 deletions

View file

@ -224,7 +224,9 @@ fun LoginForm(
}
error.Show {
Row(Modifier.basePadding()) {
ErrorText(it)
ErrorText(
text = it
)
}
}
}

View file

@ -21,7 +21,9 @@ fun MainContentLoggedIn(
) {
val session = LocalSession.current
if (session == null) {
ErrorText(stringResource(R.string.error_session_missing))
ErrorText(
text = stringResource(R.string.error_session_missing)
)
return
}

View file

@ -43,7 +43,9 @@ fun RoomListItem(
val session = LocalSession.current
if (session == null) {
ErrorText(stringResource(R.string.error_session_missing))
ErrorText(
text = stringResource(R.string.error_session_missing)
)
return
}

View file

@ -39,19 +39,25 @@ fun MemberListItem(
) {
val session = LocalSession.current
if (session == null) {
ErrorText(stringResource(R.string.error_session_missing))
ErrorText(
text = stringResource(R.string.error_session_missing)
)
return
}
val roomRequest = LocalRoom.current
if (roomRequest == null) {
ErrorText(stringResource(R.string.room_error_room_missing))
ErrorText(
text = stringResource(R.string.room_error_room_missing)
)
return
}
val room = roomRequest.getOrNull()
if (room == null) {
ErrorText(stringResource(R.string.room_error_room_notfound))
ErrorText(
text = stringResource(R.string.room_error_room_notfound)
)
return
}

View file

@ -1,5 +1,6 @@
package eu.steffo.twom.composables.viewroom
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
@ -9,6 +10,8 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import eu.steffo.twom.composables.errorhandling.LoadingText
import eu.steffo.twom.composables.theme.basePadding
import eu.steffo.twom.utils.RSVP
import eu.steffo.twom.utils.RSVPAnswer
@ -18,6 +21,13 @@ fun RSVPForm(
onRequestPublish: (newAnswer: RSVPAnswer, newComment: String) -> Unit = { _, _ -> },
isPublishRunning: Boolean = false,
) {
if (published.answer == RSVPAnswer.LOADING) {
Row(Modifier.basePadding()) {
LoadingText()
}
return
}
var currentAnswer by rememberSaveable { mutableStateOf(published.answer) }
var currentComment by rememberSaveable { mutableStateOf(published.comment) }

View file

@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import eu.steffo.twom.R
@ -18,11 +17,11 @@ import eu.steffo.twom.composables.matrix.LocalSession
fun ViewRoomContent(
modifier: Modifier = Modifier,
) {
val scope = rememberCoroutineScope()
val session = LocalSession.current
if (session == null) {
ErrorText(stringResource(R.string.error_session_missing))
ErrorText(
text = stringResource(R.string.error_session_missing)
)
return
}

View file

@ -15,6 +15,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import eu.steffo.twom.R
import eu.steffo.twom.composables.errorhandling.ErrorText
import eu.steffo.twom.composables.errorhandling.LoadingText
import eu.steffo.twom.composables.errorhandling.LocalizableError
import eu.steffo.twom.composables.matrix.LocalSession
import eu.steffo.twom.composables.theme.basePadding
@ -23,30 +24,50 @@ import kotlin.jvm.optionals.getOrNull
@Composable
fun ViewRoomForm() {
Row(Modifier.basePadding()) {
Text(
text = stringResource(R.string.room_rsvp_title),
style = MaterialTheme.typography.labelLarge,
)
}
val scope = rememberCoroutineScope()
val session = LocalSession.current
if (session == null) {
ErrorText(stringResource(R.string.error_session_missing))
Row(Modifier.basePadding()) {
ErrorText(
text = stringResource(R.string.error_session_missing)
)
}
return
}
val roomRequest = LocalRoom.current
if (roomRequest == null) {
ErrorText(stringResource(R.string.room_error_room_missing))
Row(Modifier.basePadding()) {
LoadingText()
}
return
}
val room = roomRequest.getOrNull()
if (room == null) {
ErrorText(stringResource(R.string.room_error_room_notfound))
Row(Modifier.basePadding()) {
ErrorText(
text = stringResource(R.string.room_error_room_notfound)
)
}
return
}
// FIXME: This breaks if the member is kicked from the chat
val member = room.membershipService().getRoomMember(session.myUserId)
if (member == null) {
ErrorText(stringResource(R.string.room_error_members_notfound))
Row(Modifier.basePadding()) {
ErrorText(
text = stringResource(R.string.room_error_self_notfound)
)
}
return
}
@ -55,12 +76,6 @@ fun ViewRoomForm() {
var isPublishRunning by rememberSaveable { mutableStateOf(false) }
val publishError by remember { mutableStateOf(LocalizableError()) }
Row(Modifier.basePadding()) {
Text(
text = stringResource(R.string.room_rsvp_title),
style = MaterialTheme.typography.labelLarge,
)
}
RSVPForm(
published = published,
onRequestPublish = { answer, comment ->
@ -121,7 +136,12 @@ fun ViewRoomForm() {
},
isPublishRunning = isPublishRunning,
)
publishError.Show {
ErrorText(it)
Row(Modifier.basePadding()) {
ErrorText(
text = it
)
}
}
}

View file

@ -10,39 +10,49 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import eu.steffo.twom.R
import eu.steffo.twom.composables.errorhandling.ErrorText
import eu.steffo.twom.composables.errorhandling.LoadingText
import eu.steffo.twom.composables.theme.basePadding
import org.matrix.android.sdk.api.session.room.members.RoomMemberQueryParams
import kotlin.jvm.optionals.getOrNull
@Composable
fun ViewRoomMembers() {
val roomRequest = LocalRoom.current
if (roomRequest == null) {
ErrorText(stringResource(R.string.room_error_room_missing))
return
}
val room = roomRequest.getOrNull()
if (room == null) {
ErrorText(stringResource(R.string.room_error_room_notfound))
return
}
val roomMembers by room.membershipService().getRoomMembersLive(
RoomMemberQueryParams.Builder().build()
).observeAsState()
if (roomMembers == null) {
ErrorText(stringResource(R.string.room_error_members_notfound))
return
}
Row(Modifier.basePadding()) {
Text(
text = stringResource(R.string.room_invitees_title),
style = MaterialTheme.typography.labelLarge,
)
}
roomMembers!!.forEach {
val roomRequest = LocalRoom.current
if (roomRequest == null) {
Row(Modifier.basePadding()) {
LoadingText()
}
return
}
val room = roomRequest.getOrNull()
if (room == null) {
Row(Modifier.basePadding()) {
ErrorText(
text = stringResource(R.string.room_error_room_notfound)
)
}
return
}
val roomMembersRequest by room.membershipService().getRoomMembersLive(
RoomMemberQueryParams.Builder().build()
).observeAsState()
if (roomMembersRequest == null) {
Row(Modifier.basePadding()) {
LoadingText()
}
return
}
roomMembersRequest!!.forEach {
MemberListItem(member = it)
}
}

View file

@ -2,7 +2,6 @@ package eu.steffo.twom.composables.viewroom
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
@ -13,7 +12,7 @@ import androidx.compose.ui.tooling.preview.Preview
import eu.steffo.twom.R
import eu.steffo.twom.composables.errorhandling.ErrorIconButton
import eu.steffo.twom.composables.errorhandling.ErrorText
import eu.steffo.twom.composables.errorhandling.LocalizableError
import eu.steffo.twom.composables.errorhandling.LoadingText
import eu.steffo.twom.composables.navigation.BackIconButton
@ -22,20 +21,9 @@ import eu.steffo.twom.composables.navigation.BackIconButton
@Preview
fun ViewRoomTopBar(
modifier: Modifier = Modifier,
roomName: String? = null,
roomAvatarUrl: String? = null,
isLoading: Boolean = false,
error: LocalizableError? = null,
) {
val roomSummaryRequest = LocalRoomSummary.current
val isLoading = (roomSummaryRequest == null)
val roomSummary = roomSummaryRequest.getOrNull()
if (roomSummary == null) {
ErrorText(stringResource(R.string.room_error_roomsummary_notfound))
return
}
val roomSummary = roomSummaryRequest?.getOrNull()
TopAppBar(
modifier = modifier,
@ -43,31 +31,33 @@ fun ViewRoomTopBar(
BackIconButton()
},
title = {
if (roomName != null) {
Text(
text = roomName,
if (roomSummaryRequest == null) {
LoadingText(
style = MaterialTheme.typography.titleLarge,
)
} else if (roomSummary == null) {
ErrorText(
style = MaterialTheme.typography.titleLarge,
)
} else {
Text(
text = stringResource(R.string.loading),
text = roomSummary.displayName,
style = MaterialTheme.typography.titleLarge,
color = LocalContentColor.current.copy(0.4f)
)
}
},
actions = {
if (isLoading) {
if (roomSummaryRequest == null) {
CircularProgressIndicator()
} else if (error != null && error.occurred()) {
} else if (roomSummary == null) {
ErrorIconButton(
message = error.renderString()!!
message = stringResource(R.string.room_error_roomsummary_notfound)
)
} else {
RoomIconButton(
avatarUrl = roomAvatarUrl,
avatarUrl = roomSummary.avatarUrl,
)
}
},
)
}
}

View file

@ -9,23 +9,12 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import eu.steffo.twom.R
import eu.steffo.twom.composables.errorhandling.ErrorText
import eu.steffo.twom.composables.errorhandling.LoadingText
import eu.steffo.twom.composables.theme.basePadding
@Composable
@Preview
fun ViewRoomTopic() {
val roomSummaryRequest = LocalRoomSummary.current
if (roomSummaryRequest == null) {
ErrorText(stringResource(R.string.room_error_roomsummary_missing))
return
}
val roomSummary = roomSummaryRequest.getOrNull()
if (roomSummary == null) {
ErrorText(stringResource(R.string.room_error_roomsummary_notfound))
return
}
Row(Modifier.basePadding()) {
Text(
text = stringResource(R.string.room_topic_title),
@ -33,7 +22,20 @@ fun ViewRoomTopic() {
)
}
val roomSummaryRequest = LocalRoomSummary.current
val roomSummary = roomSummaryRequest?.getOrNull()
Row(Modifier.basePadding()) {
Text(roomSummary.topic)
if (roomSummaryRequest == null) {
LoadingText()
} else if (roomSummary == null) {
ErrorText(
text = stringResource(R.string.room_error_roomsummary_notfound)
)
} else {
Text(
text = roomSummary.topic,
)
}
}
}

View file

@ -1,5 +1,6 @@
package eu.steffo.twom.composables.viewroom
import android.util.Log
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
@ -26,6 +27,8 @@ fun observeRSVP(room: Room, member: RoomMemberSummary): RSVP {
stateKey = QueryStringValue.Equals(member.userId),
).observeAsState()
Log.v("observeRSVP", "$request")
if (request == null) {
return RSVP(
event = null,
@ -48,6 +51,15 @@ fun observeRSVP(room: Room, member: RoomMemberSummary): RSVP {
comment = "",
)
// Redactions
if (content.isEmpty()) {
return RSVP(
event = event,
answer = RSVPAnswer.NONE,
comment = "",
)
}
val commentField = content[TwoMGlobals.RSVP_STATE_COMMENT_FIELD]
?: return RSVP(
event = event,

View file

@ -82,4 +82,5 @@
<string name="room_uninvite_label">Uninvite</string>
<string name="room_error_publish_generic">Something went wrong while updating your RSVP: %1$s</string>
<string name="room_error_redact_generic">Your response has been updated, but something went wrong while attempting to remove your previous one: %1$s</string>
<string name="room_error_self_notfound">You have been removed from the room.</string>
</resources>