Decode original post title, and display if the post is reblogged
This commit is contained in:
parent
88fdc3ae62
commit
c79570d812
2 changed files with 28 additions and 3 deletions
|
@ -10,6 +10,12 @@ struct Media: Decodable, Identifiable {
|
|||
let url: String
|
||||
}
|
||||
|
||||
struct OriginalPost: Decodable, Identifiable {
|
||||
let id: Int
|
||||
|
||||
let title: String?
|
||||
}
|
||||
|
||||
struct Post: Decodable, Identifiable {
|
||||
let id: Int
|
||||
|
||||
|
@ -19,4 +25,21 @@ struct Post: Decodable, Identifiable {
|
|||
let postType: PostType
|
||||
|
||||
let media: [Media]
|
||||
|
||||
let username: String
|
||||
let originalUsername: String?
|
||||
|
||||
let originalPost: OriginalPost?
|
||||
|
||||
func isReblogged() -> Bool {
|
||||
return originalUsername != nil
|
||||
}
|
||||
|
||||
func getTitle() -> String? {
|
||||
if isReblogged() {
|
||||
return originalPost?.title
|
||||
} else {
|
||||
return title
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,12 @@ struct PostView: View {
|
|||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Text(String(post.id))
|
||||
if post.isReblogged() {
|
||||
Text("Reblogged from " + post.originalUsername!)
|
||||
}
|
||||
|
||||
if post.title != nil {
|
||||
Text(post.title!)
|
||||
if post.getTitle() != nil {
|
||||
Text(post.getTitle()!)
|
||||
}
|
||||
|
||||
VStack {
|
||||
|
|
Reference in a new issue