blob: 799339c5471f4d26f9517c39daf2019435e224ba (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
import SwiftUI
struct PostDetailView: View {
let post: MoebooruPost
@State var loadingStage: PostLoadingState = .loadingPreview
var body: some View {
VStack {
Link(destination: URL(string: "https://yande.re/post/show/\(post.id)")!) {
AsyncImage(url: post.sampleURL) { image in
image
.resizable()
.scaledToFit()
.onAppear {
self.loadingStage = .loaded
}
} placeholder: {
AsyncImage(url: post.previewURL) { image in
image
.resizable()
.scaledToFit()
.onAppear {
self.loadingStage = .loadingFile
}
} placeholder: {
ProgressView()
.progressViewStyle(LinearProgressViewStyle())
.padding()
.onAppear {
self.loadingStage = .loadingPreview
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
.id(post.fileURL)
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
.id(post.fileURL)
}
.buttonStyle(PlainButtonStyle())
Spacer()
VStack(spacing: 5) {
HStack {
Text(post.tags.joined(separator: ", "))
}
.frame(maxWidth: .infinity, alignment: .leading)
HStack {
Text(post.createdAt.formatted())
.frame(maxWidth: .infinity, alignment: .leading)
Group {
switch loadingStage {
case .loadingPreview:
Text("Loading preview …")
case .loadingFile:
Text("Loading file …")
case .loaded:
EmptyView()
}
}
.padding(.trailing, 5)
}
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundStyle(.secondary)
}
.padding(.horizontal, 10)
.padding(.vertical, 10 / 1.33)
.textSelection(.enabled)
.font(.footnote)
.background(.opacity(0.1))
}
}
}
|