2020-07-01 11:13:11 -05:00
|
|
|
//
|
|
|
|
// TimelineItemView.swift
|
|
|
|
// NetNewsWire
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 7/1/20.
|
|
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct TimelineItemView: View {
|
|
|
|
|
2020-07-02 05:46:56 -05:00
|
|
|
@EnvironmentObject var defaults: AppDefaults
|
2020-07-01 17:21:58 -05:00
|
|
|
@StateObject var articleIconImageLoader = ArticleIconImageLoader()
|
2020-07-02 05:46:56 -05:00
|
|
|
|
2020-07-01 11:13:11 -05:00
|
|
|
var timelineItem: TimelineItem
|
2020-07-03 12:21:08 -05:00
|
|
|
|
|
|
|
#if os(macOS)
|
|
|
|
var verticalPadding: CGFloat = 10
|
|
|
|
#endif
|
|
|
|
#if os(iOS)
|
|
|
|
var verticalPadding: CGFloat = 0
|
|
|
|
#endif
|
|
|
|
|
2020-07-01 11:13:11 -05:00
|
|
|
var body: some View {
|
2020-07-01 12:30:55 -05:00
|
|
|
VStack {
|
2020-07-01 16:33:07 -05:00
|
|
|
HStack(alignment: .top) {
|
|
|
|
TimelineItemStatusView(status: timelineItem.status)
|
2020-07-01 17:21:58 -05:00
|
|
|
if let image = articleIconImageLoader.image {
|
|
|
|
IconImageView(iconImage: image)
|
2020-07-03 01:24:35 -05:00
|
|
|
.frame(width: CGFloat(defaults.timelineIconDimensions), height: CGFloat(defaults.timelineIconDimensions), alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
|
2020-07-01 17:21:58 -05:00
|
|
|
}
|
2020-07-01 17:39:27 -05:00
|
|
|
VStack {
|
|
|
|
Text(verbatim: timelineItem.article.title ?? "N/A")
|
2020-07-01 17:42:44 -05:00
|
|
|
.fontWeight(.semibold)
|
2020-07-06 17:54:11 +08:00
|
|
|
.lineLimit(Int(defaults.timelineNumberOfLines))
|
2020-07-01 17:39:27 -05:00
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
.padding(.trailing, 4)
|
|
|
|
Spacer()
|
|
|
|
HStack {
|
|
|
|
Text(verbatim: timelineItem.byline)
|
2020-07-01 17:42:44 -05:00
|
|
|
.lineLimit(1)
|
|
|
|
.truncationMode(.tail)
|
2020-07-01 17:39:27 -05:00
|
|
|
.font(.footnote)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
Spacer()
|
|
|
|
Text(verbatim: timelineItem.dateTimeString)
|
2020-07-01 17:42:44 -05:00
|
|
|
.lineLimit(1)
|
2020-07-01 17:39:27 -05:00
|
|
|
.font(.footnote)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.padding(.trailing, 4)
|
|
|
|
}
|
|
|
|
}
|
2020-07-01 16:33:07 -05:00
|
|
|
}
|
2020-07-01 12:30:55 -05:00
|
|
|
}
|
2020-07-03 12:21:08 -05:00
|
|
|
.padding(.vertical, verticalPadding)
|
2020-07-01 17:21:58 -05:00
|
|
|
.onAppear {
|
|
|
|
articleIconImageLoader.loadImage(for: timelineItem.article)
|
|
|
|
}
|
2020-07-01 11:13:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-01 16:33:07 -05:00
|
|
|
struct TimelineItemView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
Group {
|
|
|
|
TimelineItemView(timelineItem: TimelineItem(article: PreviewArticles.basicRead))
|
|
|
|
.frame(maxWidth: 250)
|
|
|
|
TimelineItemView(timelineItem: TimelineItem(article: PreviewArticles.basicUnread))
|
|
|
|
.frame(maxWidth: 250)
|
|
|
|
TimelineItemView(timelineItem: TimelineItem(article: PreviewArticles.basicStarred))
|
|
|
|
.frame(maxWidth: 250)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|