mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-02-03 07:57:31 +01:00
Load embed gracefully
This commit is contained in:
parent
b2d4d151e5
commit
d9481cc802
@ -3,6 +3,7 @@ import Models
|
|||||||
import Env
|
import Env
|
||||||
import DesignSystem
|
import DesignSystem
|
||||||
import Network
|
import Network
|
||||||
|
import Shimmer
|
||||||
|
|
||||||
public struct StatusRowView: View {
|
public struct StatusRowView: View {
|
||||||
@Environment(\.redactionReasons) private var reasons
|
@Environment(\.redactionReasons) private var reasons
|
||||||
@ -35,7 +36,7 @@ public struct StatusRowView: View {
|
|||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
viewModel.client = client
|
viewModel.client = client
|
||||||
if !viewModel.isCompact {
|
if !viewModel.isCompact, viewModel.embededStatus == nil {
|
||||||
Task {
|
Task {
|
||||||
await viewModel.loadEmbededStatus()
|
await viewModel.loadEmbededStatus()
|
||||||
}
|
}
|
||||||
@ -122,8 +123,14 @@ public struct StatusRowView: View {
|
|||||||
routeurPath.handleStatus(status: status, url: url)
|
routeurPath.handleStatus(status: status, url: url)
|
||||||
})
|
})
|
||||||
|
|
||||||
if !viewModel.isCompact, let embed = viewModel.embededStatus {
|
if !reasons.contains(.placeholder) {
|
||||||
|
if !viewModel.isCompact, !viewModel.isEmbedLoading, let embed = viewModel.embededStatus {
|
||||||
StatusEmbededView(status: embed)
|
StatusEmbededView(status: embed)
|
||||||
|
} else if viewModel.isEmbedLoading, !viewModel.isCompact {
|
||||||
|
StatusEmbededView(status: .placeholder())
|
||||||
|
.redacted(reason: .placeholder)
|
||||||
|
.shimmering()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let poll = status.poll {
|
if let poll = status.poll {
|
||||||
@ -134,7 +141,7 @@ public struct StatusRowView: View {
|
|||||||
StatusMediaPreviewView(attachements: status.mediaAttachments, isCompact: viewModel.isCompact)
|
StatusMediaPreviewView(attachements: status.mediaAttachments, isCompact: viewModel.isCompact)
|
||||||
.padding(.vertical, 4)
|
.padding(.vertical, 4)
|
||||||
}
|
}
|
||||||
if let card = status.card, !viewModel.isCompact, viewModel.embededStatus?.url != status.card?.url {
|
if let card = status.card, viewModel.embededStatus?.url != status.card?.url, !viewModel.isEmbedLoading {
|
||||||
StatusCardView(card: card)
|
StatusCardView(card: card)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ public class StatusRowViewModel: ObservableObject {
|
|||||||
@Published var repliesCount: Int
|
@Published var repliesCount: Int
|
||||||
@Published var embededStatus: Status?
|
@Published var embededStatus: Status?
|
||||||
@Published var displaySpoiler: Bool = false
|
@Published var displaySpoiler: Bool = false
|
||||||
|
@Published var isEmbedLoading: Bool = true
|
||||||
|
|
||||||
var client: Client?
|
var client: Client?
|
||||||
|
|
||||||
@ -41,8 +42,14 @@ public class StatusRowViewModel: ObservableObject {
|
|||||||
guard let client,
|
guard let client,
|
||||||
let urls = status.content.findStatusesURLs(),
|
let urls = status.content.findStatusesURLs(),
|
||||||
!urls.isEmpty,
|
!urls.isEmpty,
|
||||||
let url = urls.first else { return }
|
let url = urls.first else {
|
||||||
|
isEmbedLoading = false
|
||||||
|
return
|
||||||
|
}
|
||||||
do {
|
do {
|
||||||
|
withAnimation {
|
||||||
|
isEmbedLoading = true
|
||||||
|
}
|
||||||
if url.absoluteString.contains(client.server), let id = Int(url.lastPathComponent) {
|
if url.absoluteString.contains(client.server), let id = Int(url.lastPathComponent) {
|
||||||
self.embededStatus = try await client.get(endpoint: Statuses.status(id: String(id)))
|
self.embededStatus = try await client.get(endpoint: Statuses.status(id: String(id)))
|
||||||
} else {
|
} else {
|
||||||
@ -52,7 +59,12 @@ public class StatusRowViewModel: ObservableObject {
|
|||||||
forceVersion: .v2)
|
forceVersion: .v2)
|
||||||
self.embededStatus = results.statuses.first
|
self.embededStatus = results.statuses.first
|
||||||
}
|
}
|
||||||
} catch { }
|
withAnimation {
|
||||||
|
isEmbedLoading = false
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
isEmbedLoading = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func favourite() async {
|
func favourite() async {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user