ArticleItemView now uses feedIconPath

This commit is contained in:
Stuart Breckenridge 2022-07-07 19:12:42 +01:00
parent 350c373ae2
commit db9dbc97ec
No known key found for this signature in database
GPG Key ID: 64DCE361D27B805B

View File

@ -13,14 +13,14 @@ struct ArticleItemView: View {
var article: LatestArticle
var deepLink: URL
@State private var iconImage: UIImage?
@State private var iconImage: Image?
var body: some View {
Link(destination: deepLink, label: {
HStack(alignment: .top, spacing: nil, content: {
// Feed Icon
if iconImage != nil {
Image(uiImage: iconImage!)
iconImage!
.resizable()
.frame(width: 30, height: 30)
.cornerRadius(4)
@ -49,16 +49,18 @@ struct ArticleItemView: View {
}
})
}).onAppear {
iconImage = thumbnail(article.feedIcon)
iconImage = thumbnail(from: article.feedIconPath)
}
}
func thumbnail(_ data: Data?) -> UIImage {
if data == nil {
return UIImage(systemName: "globe")!
} else {
return UIImage(data: data!)!
func thumbnail(from path: String?) -> Image? {
guard let imagePath = path,
let url = URL(string: imagePath),
let data = try? Data(contentsOf: url),
let uiImage = UIImage(data: data) else {
return Image(uiImage: UIImage(systemName: "globe")!)
}
return Image(uiImage: uiImage)
}
func pubDate(_ dateString: String) -> String {