2020-06-03 22:33:04 -04:00
|
|
|
import SwiftUI
|
2020-11-18 08:27:32 -05:00
|
|
|
import URLImage
|
2020-06-03 22:33:04 -04:00
|
|
|
|
|
|
|
extension String {
|
|
|
|
func encodeUrl() -> String? {
|
|
|
|
return self.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PostView: View {
|
2020-06-04 08:00:35 -04:00
|
|
|
let post: ParsedPostContainer
|
2020-06-03 22:33:04 -04:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack {
|
2020-06-03 23:17:23 -04:00
|
|
|
HStack {
|
2020-11-18 08:27:32 -05:00
|
|
|
URLImage(url: URL(string: post.post.avatarUrl.encodeUrl()!)!) { image in
|
2020-06-03 23:17:23 -04:00
|
|
|
image
|
2020-11-18 08:27:32 -05:00
|
|
|
.resizable()
|
|
|
|
.aspectRatio(contentMode: .fit)
|
|
|
|
}.frame(width: 50.0, height: 50.0).padding(.leading)
|
2020-06-03 23:17:23 -04:00
|
|
|
|
|
|
|
VStack(alignment: .leading) {
|
2020-06-04 08:00:35 -04:00
|
|
|
if post.post.isReblogged() {
|
|
|
|
Text(post.post.username + " reblogged from " + post.post.originalUsername!).foregroundColor(.gray)
|
2020-06-03 23:17:23 -04:00
|
|
|
}
|
|
|
|
|
2020-06-04 08:00:35 -04:00
|
|
|
if post.post.getTitle() != nil {
|
|
|
|
Text(post.post.getTitle()!)
|
2020-06-03 23:17:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
}.frame(maxWidth: .infinity)
|
2020-06-03 22:33:04 -04:00
|
|
|
|
|
|
|
VStack {
|
2020-06-04 08:00:35 -04:00
|
|
|
ForEach(post.post.media) { media in
|
2020-06-04 06:03:09 -04:00
|
|
|
if !media.url.isEmpty {
|
|
|
|
VStack {
|
2020-11-18 08:27:32 -05:00
|
|
|
URLImage(url: URL(string: media.url.encodeUrl()!)!) { image in
|
2020-06-04 06:03:09 -04:00
|
|
|
image
|
|
|
|
.aspectRatio(contentMode: .fit)
|
2020-11-18 08:27:32 -05:00
|
|
|
}
|
2020-06-04 06:03:09 -04:00
|
|
|
}
|
2020-06-03 22:33:04 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-04 08:00:35 -04:00
|
|
|
|
|
|
|
AttributedText(post.contentAttributed)
|
2020-06-03 23:17:23 -04:00
|
|
|
}.frame(maxWidth: .infinity)
|
2020-06-03 22:33:04 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PostView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2020-06-04 09:42:42 -04:00
|
|
|
return PostView(post: ParsedPostContainer(post: fooPost, contentAttributed: NSMutableAttributedString()))
|
2020-06-03 22:33:04 -04:00
|
|
|
}
|
|
|
|
}
|