2020-07-25 11:02:11 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
2020-08-17 16:05:26 +00:00
|
|
|
struct PostStatusBadgeView: View {
|
2020-09-08 20:17:58 +00:00
|
|
|
@ObservedObject var post: WFAPost
|
2020-07-25 11:02:11 +00:00
|
|
|
|
|
|
|
var body: some View {
|
2020-09-08 20:17:58 +00:00
|
|
|
let (badgeLabel, badgeColor) = setupBadgeProperties(for: PostStatus(rawValue: post.status)!)
|
2020-07-25 11:02:11 +00:00
|
|
|
Text(badgeLabel)
|
|
|
|
.font(.caption)
|
2020-08-07 13:44:34 +00:00
|
|
|
.fontWeight(.semibold)
|
2020-07-25 11:02:11 +00:00
|
|
|
.foregroundColor(.white)
|
|
|
|
.textCase(.uppercase)
|
|
|
|
.lineLimit(1)
|
|
|
|
.padding(EdgeInsets(top: 2.5, leading: 7.5, bottom: 2.5, trailing: 7.5))
|
|
|
|
.background(badgeColor)
|
|
|
|
.clipShape(RoundedRectangle(cornerRadius: 5.0, style: .circular))
|
|
|
|
}
|
|
|
|
|
|
|
|
func setupBadgeProperties(for status: PostStatus) -> (String, Color) {
|
|
|
|
var badgeLabel: String
|
|
|
|
var badgeColor: Color
|
|
|
|
|
|
|
|
switch status {
|
2020-09-01 13:54:43 +00:00
|
|
|
case .local:
|
|
|
|
badgeLabel = "local"
|
2020-07-25 11:02:11 +00:00
|
|
|
badgeColor = Color(red: 0.75, green: 0.5, blue: 0.85, opacity: 1.0)
|
|
|
|
case .edited:
|
|
|
|
badgeLabel = "edited"
|
|
|
|
badgeColor = Color(red: 0.75, green: 0.7, blue: 0.1, opacity: 1.0)
|
|
|
|
case .published:
|
|
|
|
badgeLabel = "published"
|
|
|
|
badgeColor = .gray
|
|
|
|
}
|
|
|
|
|
|
|
|
return (badgeLabel, badgeColor)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-09 16:12:19 +00:00
|
|
|
struct PostStatusBadge_LocalDraftPreviews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2021-10-08 21:15:38 +00:00
|
|
|
let context = LocalStorageManager.standard.container.viewContext
|
2020-09-09 16:12:19 +00:00
|
|
|
let testPost = WFAPost(context: context)
|
|
|
|
testPost.status = PostStatus.local.rawValue
|
|
|
|
|
|
|
|
return PostStatusBadgeView(post: testPost)
|
|
|
|
.environment(\.managedObjectContext, context)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PostStatusBadge_EditedPreviews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2021-10-08 21:15:38 +00:00
|
|
|
let context = LocalStorageManager.standard.container.viewContext
|
2020-09-09 16:12:19 +00:00
|
|
|
let testPost = WFAPost(context: context)
|
|
|
|
testPost.status = PostStatus.edited.rawValue
|
|
|
|
|
|
|
|
return PostStatusBadgeView(post: testPost)
|
|
|
|
.environment(\.managedObjectContext, context)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PostStatusBadge_PublishedPreviews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2021-10-08 21:15:38 +00:00
|
|
|
let context = LocalStorageManager.standard.container.viewContext
|
2020-09-09 16:12:19 +00:00
|
|
|
let testPost = WFAPost(context: context)
|
|
|
|
testPost.status = PostStatus.published.rawValue
|
|
|
|
|
|
|
|
return PostStatusBadgeView(post: testPost)
|
|
|
|
.environment(\.managedObjectContext, context)
|
|
|
|
}
|
|
|
|
}
|