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