mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-26 18:21:00 +00:00
Display loading when fetching remote user on status row
This commit is contained in:
parent
62c3f6e04a
commit
e84a57ed7f
4 changed files with 72 additions and 43 deletions
|
@ -124,7 +124,6 @@ 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,
|
||||
|
@ -136,11 +135,9 @@ public class RouterPath: ObservableObject {
|
|||
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,
|
||||
|
@ -152,5 +149,4 @@ public class RouterPath: ObservableObject {
|
|||
await UIApplication.shared.open(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -71,6 +72,34 @@ public class StatusRowViewModel: ObservableObject {
|
|||
}
|
||||
}
|
||||
|
||||
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,
|
||||
embeddedStatus == nil,
|
||||
|
|
Loading…
Reference in a new issue