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 {
guard let client else { return }
Task {
let results: SearchResults? = try? await client.get(endpoint: Search.search(query: acct,
type: "accounts",
offset: nil,
following: nil),
forceVersion: .v2)
if let account = results?.accounts.first {
navigate(to: .accountDetailWithAccount(account: account))
} else {
await UIApplication.shared.open(url)
}
let results: SearchResults? = try? await client.get(endpoint: Search.search(query: acct,
type: "accounts",
offset: nil,
following: nil),
forceVersion: .v2)
if let account = results?.accounts.first {
navigate(to: .accountDetailWithAccount(account: account))
} else {
await UIApplication.shared.open(url)
}
}
public func navigateToAccountFrom(url: URL) async {
guard let client else { return }
Task {
let results: SearchResults? = try? await client.get(endpoint: Search.search(query: url.absoluteString,
type: "accounts",
offset: nil,
following: nil),
forceVersion: .v2)
if let account = results?.accounts.first {
navigate(to: .accountDetailWithAccount(account: account))
} else {
await UIApplication.shared.open(url)
}
let results: SearchResults? = try? await client.get(endpoint: Search.search(query: url.absoluteString,
type: "accounts",
offset: nil,
following: nil),
forceVersion: .v2)
if let account = results?.accounts.first {
navigate(to: .accountDetailWithAccount(account: account))
} else {
await UIApplication.shared.open(url)
}
}
}

View file

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

View file

@ -110,6 +110,11 @@ public struct StatusRowView: View {
viewModel.navigateToDetail(routerPath: routerPath)
}
}
.overlay {
if viewModel.isLoadingRemoteContent {
remoteContentLoadingView
}
}
}
}
@ -149,13 +154,7 @@ public struct StatusRowView: View {
.foregroundColor(.gray)
.fontWeight(.semibold)
.onTapGesture {
if viewModel.isRemote, let url = viewModel.status.account.url {
Task {
await routerPath.navigateToAccountFrom(url: url)
}
} else {
routerPath.navigate(to: .accountDetailWithAccount(account: viewModel.status.account))
}
viewModel.navigateToAccountDetail(account: viewModel.status.account, routerPath: routerPath)
}
}
}
@ -174,13 +173,7 @@ public struct StatusRowView: View {
.foregroundColor(.gray)
.fontWeight(.semibold)
.onTapGesture {
if viewModel.isRemote {
Task {
await routerPath.navigateToAccountFrom(url: mention.url)
}
} else {
routerPath.navigate(to: .accountDetail(id: mention.id))
}
viewModel.navigateToMention(mention: mention, routerPath: routerPath)
}
}
}
@ -191,13 +184,7 @@ public struct StatusRowView: View {
if !viewModel.isCompact {
HStack(alignment: .top) {
Button {
if viewModel.isRemote, let url = status.account.url {
Task {
await routerPath.navigateToAccountFrom(url: url)
}
} else {
routerPath.navigate(to: .accountDetailWithAccount(account: status.account))
}
viewModel.navigateToAccountDetail(account: status.account, routerPath: routerPath)
} label: {
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 isEmbedLoading: Bool = false
@Published var isFiltered: Bool = false
@Published var isLoadingRemoteContent: Bool = false
@Published var translation: String?
@Published var isLoadingTranslation: Bool = false
@ -70,6 +71,34 @@ public class StatusRowViewModel: ObservableObject {
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 {
guard let client,