mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Stop showing "Preview unavailable" while loading room preview details on the JoinRoomScreen
This commit is contained in:
committed by
Stefan Ceriu
parent
cefa38049f
commit
63a474bb3f
@@ -2638,7 +2638,9 @@ class ClientProxyMock: ClientProxyProtocol {
|
|||||||
func joinRoomAlias(_ roomAlias: String) async -> Result<Void, ClientProxyError> {
|
func joinRoomAlias(_ roomAlias: String) async -> Result<Void, ClientProxyError> {
|
||||||
joinRoomAliasCallsCount += 1
|
joinRoomAliasCallsCount += 1
|
||||||
joinRoomAliasReceivedRoomAlias = roomAlias
|
joinRoomAliasReceivedRoomAlias = roomAlias
|
||||||
joinRoomAliasReceivedInvocations.append(roomAlias)
|
DispatchQueue.main.async {
|
||||||
|
self.joinRoomAliasReceivedInvocations.append(roomAlias)
|
||||||
|
}
|
||||||
if let joinRoomAliasClosure = joinRoomAliasClosure {
|
if let joinRoomAliasClosure = joinRoomAliasClosure {
|
||||||
return await joinRoomAliasClosure(roomAlias)
|
return await joinRoomAliasClosure(roomAlias)
|
||||||
} else {
|
} else {
|
||||||
@@ -4478,7 +4480,9 @@ class ComposerDraftServiceMock: ComposerDraftServiceProtocol {
|
|||||||
func saveDraft(_ draft: ComposerDraftProxy) async -> Result<Void, ComposerDraftServiceError> {
|
func saveDraft(_ draft: ComposerDraftProxy) async -> Result<Void, ComposerDraftServiceError> {
|
||||||
saveDraftCallsCount += 1
|
saveDraftCallsCount += 1
|
||||||
saveDraftReceivedDraft = draft
|
saveDraftReceivedDraft = draft
|
||||||
saveDraftReceivedInvocations.append(draft)
|
DispatchQueue.main.async {
|
||||||
|
self.saveDraftReceivedInvocations.append(draft)
|
||||||
|
}
|
||||||
if let saveDraftClosure = saveDraftClosure {
|
if let saveDraftClosure = saveDraftClosure {
|
||||||
return await saveDraftClosure(draft)
|
return await saveDraftClosure(draft)
|
||||||
} else {
|
} else {
|
||||||
@@ -4674,7 +4678,9 @@ class ComposerDraftServiceMock: ComposerDraftServiceProtocol {
|
|||||||
func getReply(eventID: String) async -> Result<TimelineItemReply, ComposerDraftServiceError> {
|
func getReply(eventID: String) async -> Result<TimelineItemReply, ComposerDraftServiceError> {
|
||||||
getReplyEventIDCallsCount += 1
|
getReplyEventIDCallsCount += 1
|
||||||
getReplyEventIDReceivedEventID = eventID
|
getReplyEventIDReceivedEventID = eventID
|
||||||
getReplyEventIDReceivedInvocations.append(eventID)
|
DispatchQueue.main.async {
|
||||||
|
self.getReplyEventIDReceivedInvocations.append(eventID)
|
||||||
|
}
|
||||||
if let getReplyEventIDClosure = getReplyEventIDClosure {
|
if let getReplyEventIDClosure = getReplyEventIDClosure {
|
||||||
return await getReplyEventIDClosure(eventID)
|
return await getReplyEventIDClosure(eventID)
|
||||||
} else {
|
} else {
|
||||||
@@ -10715,7 +10721,9 @@ class RoomProxyMock: RoomProxyProtocol {
|
|||||||
func saveDraft(_ draft: ComposerDraft) async -> Result<Void, RoomProxyError> {
|
func saveDraft(_ draft: ComposerDraft) async -> Result<Void, RoomProxyError> {
|
||||||
saveDraftCallsCount += 1
|
saveDraftCallsCount += 1
|
||||||
saveDraftReceivedDraft = draft
|
saveDraftReceivedDraft = draft
|
||||||
saveDraftReceivedInvocations.append(draft)
|
DispatchQueue.main.async {
|
||||||
|
self.saveDraftReceivedInvocations.append(draft)
|
||||||
|
}
|
||||||
if let saveDraftClosure = saveDraftClosure {
|
if let saveDraftClosure = saveDraftClosure {
|
||||||
return await saveDraftClosure(draft)
|
return await saveDraftClosure(draft)
|
||||||
} else {
|
} else {
|
||||||
@@ -13236,7 +13244,9 @@ class TimelineProxyMock: TimelineProxyProtocol {
|
|||||||
func getLoadedReplyDetails(eventID: String) async -> Result<InReplyToDetails, TimelineProxyError> {
|
func getLoadedReplyDetails(eventID: String) async -> Result<InReplyToDetails, TimelineProxyError> {
|
||||||
getLoadedReplyDetailsEventIDCallsCount += 1
|
getLoadedReplyDetailsEventIDCallsCount += 1
|
||||||
getLoadedReplyDetailsEventIDReceivedEventID = eventID
|
getLoadedReplyDetailsEventIDReceivedEventID = eventID
|
||||||
getLoadedReplyDetailsEventIDReceivedInvocations.append(eventID)
|
DispatchQueue.main.async {
|
||||||
|
self.getLoadedReplyDetailsEventIDReceivedInvocations.append(eventID)
|
||||||
|
}
|
||||||
if let getLoadedReplyDetailsEventIDClosure = getLoadedReplyDetailsEventIDClosure {
|
if let getLoadedReplyDetailsEventIDClosure = getLoadedReplyDetailsEventIDClosure {
|
||||||
return await getLoadedReplyDetailsEventIDClosure(eventID)
|
return await getLoadedReplyDetailsEventIDClosure(eventID)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ enum JoinRoomScreenViewModelAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum JoinRoomScreenInteractionMode {
|
enum JoinRoomScreenInteractionMode {
|
||||||
|
case loading
|
||||||
case unknown
|
case unknown
|
||||||
case invited
|
case invited
|
||||||
case join
|
case join
|
||||||
@@ -34,32 +35,9 @@ struct JoinRoomScreenViewState: BindableState {
|
|||||||
|
|
||||||
var roomDetails: RoomPreviewDetails?
|
var roomDetails: RoomPreviewDetails?
|
||||||
|
|
||||||
var mode: JoinRoomScreenInteractionMode {
|
var mode: JoinRoomScreenInteractionMode = .loading
|
||||||
guard let roomDetails else {
|
|
||||||
return .unknown
|
|
||||||
}
|
|
||||||
|
|
||||||
if roomDetails.isInvited {
|
|
||||||
return .invited
|
|
||||||
}
|
|
||||||
|
|
||||||
if roomDetails.isPublic {
|
|
||||||
return .join
|
|
||||||
}
|
|
||||||
|
|
||||||
// Knocking is not supported yet, treat it as .unknown
|
|
||||||
// if roomDetails.canKnock {
|
|
||||||
// return .knock
|
|
||||||
// }
|
|
||||||
|
|
||||||
return .unknown
|
|
||||||
}
|
|
||||||
|
|
||||||
var bindings = JoinRoomScreenViewStateBindings()
|
var bindings = JoinRoomScreenViewStateBindings()
|
||||||
|
|
||||||
var title: String {
|
|
||||||
roomDetails?.name ?? L10n.screenJoinRoomTitleNoPreview
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct JoinRoomScreenViewStateBindings {
|
struct JoinRoomScreenViewStateBindings {
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
|
|||||||
showLoadingIndicator()
|
showLoadingIndicator()
|
||||||
|
|
||||||
defer {
|
defer {
|
||||||
|
updateMode()
|
||||||
hideLoadingIndicator()
|
hideLoadingIndicator()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,6 +86,23 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func updateMode() {
|
||||||
|
guard let roomDetails = state.roomDetails else {
|
||||||
|
state.mode = .unknown
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if roomDetails.isPublic {
|
||||||
|
state.mode = .join
|
||||||
|
} else if roomDetails.isInvited {
|
||||||
|
state.mode = .invited
|
||||||
|
} else if roomDetails.canKnock { // Knocking is not supported yet, treat it as .unknown
|
||||||
|
state.mode = .unknown
|
||||||
|
} else {
|
||||||
|
state.mode = .unknown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func joinRoom() async {
|
private func joinRoom() async {
|
||||||
showLoadingIndicator()
|
showLoadingIndicator()
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,11 @@ struct JoinRoomScreen: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
FullscreenDialog(topPadding: 80, background: .bloom) {
|
FullscreenDialog(topPadding: 80, background: .bloom) {
|
||||||
mainContent
|
if context.viewState.mode == .loading {
|
||||||
|
EmptyView()
|
||||||
|
} else {
|
||||||
|
mainContent
|
||||||
|
}
|
||||||
} bottomContent: {
|
} bottomContent: {
|
||||||
buttons
|
buttons
|
||||||
}
|
}
|
||||||
@@ -36,15 +40,17 @@ struct JoinRoomScreen: View {
|
|||||||
|
|
||||||
var mainContent: some View {
|
var mainContent: some View {
|
||||||
VStack(spacing: 16) {
|
VStack(spacing: 16) {
|
||||||
|
let title = context.viewState.roomDetails?.name ?? L10n.screenJoinRoomTitleNoPreview
|
||||||
|
|
||||||
LoadableAvatarImage(url: context.viewState.roomDetails?.avatarURL,
|
LoadableAvatarImage(url: context.viewState.roomDetails?.avatarURL,
|
||||||
name: context.viewState.title,
|
name: title,
|
||||||
contentID: context.viewState.roomID,
|
contentID: context.viewState.roomID,
|
||||||
avatarSize: .room(on: .joinRoom),
|
avatarSize: .room(on: .joinRoom),
|
||||||
imageProvider: context.imageProvider)
|
imageProvider: context.imageProvider)
|
||||||
.dynamicTypeSize(dynamicTypeSize < .accessibility1 ? dynamicTypeSize : .accessibility1)
|
.dynamicTypeSize(dynamicTypeSize < .accessibility1 ? dynamicTypeSize : .accessibility1)
|
||||||
|
|
||||||
VStack(spacing: 8) {
|
VStack(spacing: 8) {
|
||||||
Text(context.viewState.title)
|
Text(title)
|
||||||
.font(.compound.headingMDBold)
|
.font(.compound.headingMDBold)
|
||||||
.foregroundStyle(.compound.textPrimary)
|
.foregroundStyle(.compound.textPrimary)
|
||||||
.multilineTextAlignment(.center)
|
.multilineTextAlignment(.center)
|
||||||
@@ -73,7 +79,7 @@ struct JoinRoomScreen: View {
|
|||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
var buttons: some View {
|
var buttons: some View {
|
||||||
switch context.viewState.mode {
|
switch context.viewState.mode {
|
||||||
case .unknown:
|
case .loading, .unknown:
|
||||||
EmptyView()
|
EmptyView()
|
||||||
case .knock:
|
case .knock:
|
||||||
Button(L10n.screenJoinRoomKnockAction) { context.send(viewAction: .knock) }
|
Button(L10n.screenJoinRoomKnockAction) { context.send(viewAction: .knock) }
|
||||||
@@ -113,11 +119,11 @@ struct JoinRoomScreen_Previews: PreviewProvider, TestablePreview {
|
|||||||
.previewDisplayName("Unknown")
|
.previewDisplayName("Unknown")
|
||||||
.snapshot(delay: 0.25)
|
.snapshot(delay: 0.25)
|
||||||
|
|
||||||
// NavigationStack {
|
NavigationStack {
|
||||||
// JoinRoomScreen(context: knockViewModel.context)
|
JoinRoomScreen(context: knockViewModel.context)
|
||||||
// }
|
}
|
||||||
// .previewDisplayName("Knock")
|
.previewDisplayName("Knock")
|
||||||
// .snapshot(delay: 0.25)
|
.snapshot(delay: 0.25)
|
||||||
|
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
JoinRoomScreen(context: joinViewModel.context)
|
JoinRoomScreen(context: joinViewModel.context)
|
||||||
@@ -137,7 +143,7 @@ struct JoinRoomScreen_Previews: PreviewProvider, TestablePreview {
|
|||||||
|
|
||||||
// swiftlint:disable:next large_tuple
|
// swiftlint:disable:next large_tuple
|
||||||
let membership: (isJoined: Bool, isInvited: Bool, isPublic: Bool, canKnock: Bool) = switch mode {
|
let membership: (isJoined: Bool, isInvited: Bool, isPublic: Bool, canKnock: Bool) = switch mode {
|
||||||
case .unknown:
|
case .loading, .unknown:
|
||||||
(false, false, false, false)
|
(false, false, false, false)
|
||||||
case .invited:
|
case .invited:
|
||||||
(false, true, false, false)
|
(false, true, false, false)
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:4141eb3498060912c08033afe6a4990b884e4c6e5dcfd3a68a43961fe767971b
|
||||||
|
size 2110440
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:4141eb3498060912c08033afe6a4990b884e4c6e5dcfd3a68a43961fe767971b
|
||||||
|
size 2110440
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:8813f3c236f05d54b3d2d8650756db9cbf464dfab1ff1718d9871b6825aa785a
|
||||||
|
size 864729
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:8813f3c236f05d54b3d2d8650756db9cbf464dfab1ff1718d9871b6825aa785a
|
||||||
|
size 864729
|
||||||
Reference in New Issue
Block a user