1
Fork 0
mirror of https://github.com/Steffo99/twom.git synced 2024-11-22 08:04:26 +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 { error.Show {
Row(Modifier.basePadding()) { Row(Modifier.basePadding()) {
ErrorText(it) ErrorText(
text = it
)
} }
} }
} }

View file

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

View file

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

View file

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

View file

@ -1,5 +1,6 @@
package eu.steffo.twom.composables.viewroom package eu.steffo.twom.composables.viewroom
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@ -9,6 +10,8 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp 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.RSVP
import eu.steffo.twom.utils.RSVPAnswer import eu.steffo.twom.utils.RSVPAnswer
@ -18,6 +21,13 @@ fun RSVPForm(
onRequestPublish: (newAnswer: RSVPAnswer, newComment: String) -> Unit = { _, _ -> }, onRequestPublish: (newAnswer: RSVPAnswer, newComment: String) -> Unit = { _, _ -> },
isPublishRunning: Boolean = false, isPublishRunning: Boolean = false,
) { ) {
if (published.answer == RSVPAnswer.LOADING) {
Row(Modifier.basePadding()) {
LoadingText()
}
return
}
var currentAnswer by rememberSaveable { mutableStateOf(published.answer) } var currentAnswer by rememberSaveable { mutableStateOf(published.answer) }
var currentComment by rememberSaveable { mutableStateOf(published.comment) } 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.rememberScrollState
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import eu.steffo.twom.R import eu.steffo.twom.R
@ -18,11 +17,11 @@ import eu.steffo.twom.composables.matrix.LocalSession
fun ViewRoomContent( fun ViewRoomContent(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
val scope = rememberCoroutineScope()
val session = LocalSession.current val session = LocalSession.current
if (session == null) { if (session == null) {
ErrorText(stringResource(R.string.error_session_missing)) ErrorText(
text = stringResource(R.string.error_session_missing)
)
return return
} }

View file

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

View file

@ -2,7 +2,6 @@ package eu.steffo.twom.composables.viewroom
import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar 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.R
import eu.steffo.twom.composables.errorhandling.ErrorIconButton import eu.steffo.twom.composables.errorhandling.ErrorIconButton
import eu.steffo.twom.composables.errorhandling.ErrorText 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 import eu.steffo.twom.composables.navigation.BackIconButton
@ -22,20 +21,9 @@ import eu.steffo.twom.composables.navigation.BackIconButton
@Preview @Preview
fun ViewRoomTopBar( fun ViewRoomTopBar(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
roomName: String? = null,
roomAvatarUrl: String? = null,
isLoading: Boolean = false,
error: LocalizableError? = null,
) { ) {
val roomSummaryRequest = LocalRoomSummary.current val roomSummaryRequest = LocalRoomSummary.current
val isLoading = (roomSummaryRequest == null) val roomSummary = roomSummaryRequest?.getOrNull()
val roomSummary = roomSummaryRequest.getOrNull()
if (roomSummary == null) {
ErrorText(stringResource(R.string.room_error_roomsummary_notfound))
return
}
TopAppBar( TopAppBar(
modifier = modifier, modifier = modifier,
@ -43,29 +31,31 @@ fun ViewRoomTopBar(
BackIconButton() BackIconButton()
}, },
title = { title = {
if (roomName != null) { if (roomSummaryRequest == null) {
Text( LoadingText(
text = roomName, style = MaterialTheme.typography.titleLarge,
)
} else if (roomSummary == null) {
ErrorText(
style = MaterialTheme.typography.titleLarge, style = MaterialTheme.typography.titleLarge,
) )
} else { } else {
Text( Text(
text = stringResource(R.string.loading), text = roomSummary.displayName,
style = MaterialTheme.typography.titleLarge, style = MaterialTheme.typography.titleLarge,
color = LocalContentColor.current.copy(0.4f)
) )
} }
}, },
actions = { actions = {
if (isLoading) { if (roomSummaryRequest == null) {
CircularProgressIndicator() CircularProgressIndicator()
} else if (error != null && error.occurred()) { } else if (roomSummary == null) {
ErrorIconButton( ErrorIconButton(
message = error.renderString()!! message = stringResource(R.string.room_error_roomsummary_notfound)
) )
} else { } else {
RoomIconButton( 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 androidx.compose.ui.tooling.preview.Preview
import eu.steffo.twom.R import eu.steffo.twom.R
import eu.steffo.twom.composables.errorhandling.ErrorText import eu.steffo.twom.composables.errorhandling.ErrorText
import eu.steffo.twom.composables.errorhandling.LoadingText
import eu.steffo.twom.composables.theme.basePadding import eu.steffo.twom.composables.theme.basePadding
@Composable @Composable
@Preview @Preview
fun ViewRoomTopic() { 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()) { Row(Modifier.basePadding()) {
Text( Text(
text = stringResource(R.string.room_topic_title), text = stringResource(R.string.room_topic_title),
@ -33,7 +22,20 @@ fun ViewRoomTopic() {
) )
} }
val roomSummaryRequest = LocalRoomSummary.current
val roomSummary = roomSummaryRequest?.getOrNull()
Row(Modifier.basePadding()) { 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 package eu.steffo.twom.composables.viewroom
import android.util.Log
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.livedata.observeAsState
@ -26,6 +27,8 @@ fun observeRSVP(room: Room, member: RoomMemberSummary): RSVP {
stateKey = QueryStringValue.Equals(member.userId), stateKey = QueryStringValue.Equals(member.userId),
).observeAsState() ).observeAsState()
Log.v("observeRSVP", "$request")
if (request == null) { if (request == null) {
return RSVP( return RSVP(
event = null, event = null,
@ -48,6 +51,15 @@ fun observeRSVP(room: Room, member: RoomMemberSummary): RSVP {
comment = "", comment = "",
) )
// Redactions
if (content.isEmpty()) {
return RSVP(
event = event,
answer = RSVPAnswer.NONE,
comment = "",
)
}
val commentField = content[TwoMGlobals.RSVP_STATE_COMMENT_FIELD] val commentField = content[TwoMGlobals.RSVP_STATE_COMMENT_FIELD]
?: return RSVP( ?: return RSVP(
event = event, event = event,

View file

@ -82,4 +82,5 @@
<string name="room_uninvite_label">Uninvite</string> <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_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_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> </resources>