@@ -2,38 +2,60 @@ import SwiftUI
2
2
3
3
struct PostCellView : View {
4
4
@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
+ } ( )
5
14
6
15
var body : some View {
7
16
HStack {
8
17
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
+ }
9
25
Text ( post. title)
10
26
. font ( . headline)
11
- . lineLimit ( 1 )
12
- Text ( buildDateString ( from: post. createdDate ?? Date ( ) ) )
27
+ Text ( post. createdDate ?? Date ( ) , formatter: Self . createdDateFormat)
13
28
. font ( . caption)
14
- . lineLimit ( 1 )
29
+ . foregroundColor ( . secondary)
30
+ . padding ( . top, - 3 )
15
31
}
16
32
Spacer ( )
17
33
PostStatusBadgeView ( post: post)
18
34
}
19
35
. padding ( 5 )
20
36
}
37
+ }
21
38
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 ( )
26
46
27
- return dateFormatter. string ( from: date)
47
+ return PostCellView ( post: testPost, collectionName: " My Cool Blog " )
48
+ . environment ( \. managedObjectContext, context)
28
49
}
29
50
}
30
51
31
- struct PostCell_Previews : PreviewProvider {
52
+ struct PostCell_NormalPreviews : PreviewProvider {
32
53
static var previews : some View {
33
54
let context = LocalStorageManager . persistentContainer. viewContext
34
55
let testPost = WFAPost ( context: context)
35
56
testPost. title = " Test Post Title "
36
57
testPost. body = " Here's some cool sample body text. "
58
+ testPost. collectionAlias = " My Cool Blog "
37
59
testPost. createdDate = Date ( )
38
60
39
61
return PostCellView ( post: testPost)
0 commit comments