@@ -2,38 +2,60 @@ import SwiftUI
22
33struct PostCellView : View {
44 @ObservedObject var post : WFAPost
5+ var collectionName : String ?
6+
7+ static let createdDateFormat : DateFormatter = {
8+ let formatter = DateFormatter ( )
9+ formatter. locale = Locale . current
10+ formatter. dateStyle = . long
11+ formatter. timeStyle = . short
12+ return formatter
13+ } ( )
514
615 var body : some View {
716 HStack {
817 VStack ( alignment: . leading) {
18+ if let collectionName = collectionName {
19+ Text ( collectionName)
20+ . font ( . caption)
21+ . foregroundColor ( . secondary)
22+ . padding ( EdgeInsets ( top: 3 , leading: 4 , bottom: 3 , trailing: 4 ) )
23+ . overlay ( RoundedRectangle ( cornerRadius: 2 ) . stroke ( Color . secondary, lineWidth: 1 ) )
24+ }
925 Text ( post. title)
1026 . font ( . headline)
11- . lineLimit ( 1 )
12- Text ( buildDateString ( from: post. createdDate ?? Date ( ) ) )
27+ Text ( post. createdDate ?? Date ( ) , formatter: Self . createdDateFormat)
1328 . font ( . caption)
14- . lineLimit ( 1 )
29+ . foregroundColor ( . secondary)
30+ . padding ( . top, - 3 )
1531 }
1632 Spacer ( )
1733 PostStatusBadgeView ( post: post)
1834 }
1935 . padding ( 5 )
2036 }
37+ }
2138
22- func buildDateString( from date: Date ) -> String {
23- let dateFormatter = DateFormatter ( )
24- dateFormatter. dateStyle = . long
25- dateFormatter. timeStyle = . short
39+ struct PostCell_AllPostsPreviews : PreviewProvider {
40+ static var previews : some View {
41+ let context = LocalStorageManager . persistentContainer. viewContext
42+ let testPost = WFAPost ( context: context)
43+ testPost. title = " Test Post Title "
44+ testPost. body = " Here's some cool sample body text. "
45+ testPost. createdDate = Date ( )
2646
27- return dateFormatter. string ( from: date)
47+ return PostCellView ( post: testPost, collectionName: " My Cool Blog " )
48+ . environment ( \. managedObjectContext, context)
2849 }
2950}
3051
31- struct PostCell_Previews : PreviewProvider {
52+ struct PostCell_NormalPreviews : PreviewProvider {
3253 static var previews : some View {
3354 let context = LocalStorageManager . persistentContainer. viewContext
3455 let testPost = WFAPost ( context: context)
3556 testPost. title = " Test Post Title "
3657 testPost. body = " Here's some cool sample body text. "
58+ testPost. collectionAlias = " My Cool Blog "
3759 testPost. createdDate = Date ( )
3860
3961 return PostCellView ( post: testPost)
0 commit comments