Display loading when fetching remote user on status row

This commit is contained in:
Thomas Ricouard 2023-01-29 11:17:43 +01:00
parent 62c3f6e04a
commit e84a57ed7f
4 changed files with 72 additions and 43 deletions

View file

@ -124,33 +124,29 @@ public class RouterPath: ObservableObject {
public func navigateToAccountFrom(acct: String, url: URL) async { public func navigateToAccountFrom(acct: String, url: URL) async {
guard let client else { return } guard let client else { return }
Task { let results: SearchResults? = try? await client.get(endpoint: Search.search(query: acct,
let results: SearchResults? = try? await client.get(endpoint: Search.search(query: acct, type: "accounts",
type: "accounts", offset: nil,
offset: nil, following: nil),
following: nil), forceVersion: .v2)
forceVersion: .v2) if let account = results?.accounts.first {
if let account = results?.accounts.first { navigate(to: .accountDetailWithAccount(account: account))
navigate(to: .accountDetailWithAccount(account: account)) } else {
} else { await UIApplication.shared.open(url)
await UIApplication.shared.open(url)
}
} }
} }
public func navigateToAccountFrom(url: URL) async { public func navigateToAccountFrom(url: URL) async {
guard let client else { return } guard let client else { return }
Task { let results: SearchResults? = try? await client.get(endpoint: Search.search(query: url.absoluteString,
let results: SearchResults? = try? await client.get(endpoint: Search.search(query: url.absoluteString, type: "accounts",
type: "accounts", offset: nil,
offset: nil, following: nil),
following: nil), forceVersion: .v2)
forceVersion: .v2) if let account = results?.accounts.first {
if let account = results?.accounts.first { navigate(to: .accountDetailWithAccount(account: account))
navigate(to: .accountDetailWithAccount(account: account)) } else {
} else { await UIApplication.shared.open(url)
await UIApplication.shared.open(url)
}
} }
} }
} }

View file

@ -13,6 +13,7 @@ class VideoPlayerViewModel: ObservableObject {
func preparePlayer(autoPlay: Bool) { func preparePlayer(autoPlay: Bool) {
player = .init(url: url) player = .init(url: url)
player?.isMuted = true player?.isMuted = true
player?.audiovisualBackgroundPlaybackPolicy = .pauses
if autoPlay { if autoPlay {
player?.play() player?.play()
} }

View file

@ -110,6 +110,11 @@ public struct StatusRowView: View {
viewModel.navigateToDetail(routerPath: routerPath) viewModel.navigateToDetail(routerPath: routerPath)
} }
} }
.overlay {
if viewModel.isLoadingRemoteContent {
remoteContentLoadingView
}
}
} }
} }
@ -149,13 +154,7 @@ public struct StatusRowView: View {
.foregroundColor(.gray) .foregroundColor(.gray)
.fontWeight(.semibold) .fontWeight(.semibold)
.onTapGesture { .onTapGesture {
if viewModel.isRemote, let url = viewModel.status.account.url { viewModel.navigateToAccountDetail(account: viewModel.status.account, routerPath: routerPath)
Task {
await routerPath.navigateToAccountFrom(url: url)
}
} else {
routerPath.navigate(to: .accountDetailWithAccount(account: viewModel.status.account))
}
} }
} }
} }
@ -174,13 +173,7 @@ public struct StatusRowView: View {
.foregroundColor(.gray) .foregroundColor(.gray)
.fontWeight(.semibold) .fontWeight(.semibold)
.onTapGesture { .onTapGesture {
if viewModel.isRemote { viewModel.navigateToMention(mention: mention, routerPath: routerPath)
Task {
await routerPath.navigateToAccountFrom(url: mention.url)
}
} else {
routerPath.navigate(to: .accountDetail(id: mention.id))
}
} }
} }
} }
@ -191,13 +184,7 @@ public struct StatusRowView: View {
if !viewModel.isCompact { if !viewModel.isCompact {
HStack(alignment: .top) { HStack(alignment: .top) {
Button { Button {
if viewModel.isRemote, let url = status.account.url { viewModel.navigateToAccountDetail(account: status.account, routerPath: routerPath)
Task {
await routerPath.navigateToAccountFrom(url: url)
}
} else {
routerPath.navigate(to: .accountDetailWithAccount(account: status.account))
}
} label: { } label: {
accountView(status: status) accountView(status: status)
} }
@ -396,4 +383,20 @@ public struct StatusRowView: View {
} }
} }
} }
private var remoteContentLoadingView: some View {
ZStack(alignment: .center) {
VStack {
Spacer()
HStack {
Spacer()
ProgressView()
Spacer()
}
Spacer()
}
}
.background(Color.black.opacity(0.40))
.transition(.opacity)
}
} }

View file

@ -22,6 +22,7 @@ public class StatusRowViewModel: ObservableObject {
@Published var displaySpoiler: Bool = false @Published var displaySpoiler: Bool = false
@Published var isEmbedLoading: Bool = false @Published var isEmbedLoading: Bool = false
@Published var isFiltered: Bool = false @Published var isFiltered: Bool = false
@Published var isLoadingRemoteContent: Bool = false
@Published var translation: String? @Published var translation: String?
@Published var isLoadingTranslation: Bool = false @Published var isLoadingTranslation: Bool = false
@ -70,6 +71,34 @@ public class StatusRowViewModel: ObservableObject {
routerPath.navigate(to: .statusDetail(id: status.reblog?.id ?? status.id)) routerPath.navigate(to: .statusDetail(id: status.reblog?.id ?? status.id))
} }
} }
func navigateToAccountDetail(account: Account, routerPath: RouterPath) {
if isRemote, let url = account.url {
withAnimation {
isLoadingRemoteContent = true
}
Task {
await routerPath.navigateToAccountFrom(url: url)
isLoadingRemoteContent = false
}
} else {
routerPath.navigate(to: .accountDetailWithAccount(account: account))
}
}
func navigateToMention(mention: Mention, routerPath: RouterPath) {
if isRemote {
withAnimation {
isLoadingRemoteContent = true
}
Task {
await routerPath.navigateToAccountFrom(url: mention.url)
isLoadingRemoteContent = false
}
} else {
routerPath.navigate(to: .accountDetail(id: mention.id))
}
}
func loadEmbeddedStatus() async { func loadEmbeddedStatus() async {
guard let client, guard let client,