Skip to content

Commit cab1e95

Browse files
authored
Merge pull request #10 from SirArkimedes/previews
Create previews for the Shared views
2 parents 1da8bcd + ebc53dc commit cab1e95

File tree

6 files changed

+64
-2
lines changed

6 files changed

+64
-2
lines changed

Shared/Models/Comment.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,20 @@ struct Comment: Decodable {
3838
}
3939
}
4040
}
41+
42+
#if DEBUG
43+
extension Comment {
44+
/// Used to initialize a Comment for Debug purposes
45+
init(nested: Int) {
46+
id = "123"
47+
author = "sirarkimedes"
48+
score = 123556
49+
body = "This is a body of text that is purely to act as an example!"
50+
if nested != 0 {
51+
replies = CommentListing(data: CommentListing.CommentListingData(children: [CommentListing.CommentListingData.CommentData(data: Comment(nested: nested - 1))]))
52+
} else{
53+
replies = nil
54+
}
55+
}
56+
}
57+
#endif

Shared/Models/Post.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,12 @@ struct Post: Decodable, Identifiable {
6363
}
6464
}
6565
}
66+
67+
#if DEBUG
68+
extension Post {
69+
/// Used to create a Post for example Debug purposes
70+
static var example: Self {
71+
return Post(title: "Hello World | This is secondary text", name: "hello-world", id: "hw", selftext: "This is some body content. Blah blah\nblah blah blah", selftext_html: nil, thumbnail: "blahblah", url: "", author: "me", subreddit: "swift", score: 1000, num_comments: 50, stickied: true, created_utc: Date().timeIntervalSince1970 - 100, preview: nil, link_flair_text: "Hello World", is_original_content: true, spoiler: false, replies: nil)
72+
}
73+
}
74+
#endif

Shared/Views/CommentsView.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import SwiftUI
1010
import Request
1111

12+
// MARK: - CommentsView
13+
1214
struct CommentsView: View {
1315
let post: Post
1416

@@ -40,6 +42,8 @@ struct CommentsView: View {
4042
}
4143
}
4244

45+
// MARK: - CommentView
46+
4347
struct CommentView: View {
4448
let comment: Comment
4549
let postAuthor: String
@@ -85,3 +89,20 @@ struct CommentView: View {
8589
}
8690
}
8791
}
92+
93+
// MARK: - Comment View preview
94+
95+
#if DEBUG
96+
struct CommentView_Previews: PreviewProvider {
97+
static func example(for author: String, nested: Int = 5) -> some View {
98+
CommentView(comment: Comment(nested: nested), postAuthor: author, nestLevel: 0).frame(width: nil, height: 60)
99+
}
100+
101+
static var previews: some View {
102+
VStack {
103+
example(for: "not", nested: 2)
104+
example(for: "sirarkimedes")
105+
}
106+
}
107+
}
108+
#endif

Shared/Views/MetadataView.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ struct MetadataView: View {
5151
#if DEBUG
5252
struct MetadataView_Previews: PreviewProvider {
5353
static var previews: some View {
54-
MetadataView(post: Post(title: "Hello World | This is secondary text", name: "hello-world", id: "hw", selftext: "This is some body content. Blah blah\nblah blah blah", selftext_html: nil, thumbnail: "blahblah", url: "", author: "me", subreddit: "swift", score: 1000, num_comments: 50, stickied: true, created_utc: Date().timeIntervalSince1970, preview: nil, link_flair_text: "Hello World", is_original_content: true, spoiler: false, replies: nil), spaced: true)
55-
.font(.system(size: 10))
54+
MetadataView(post: Post.example, spaced: true)
5655
}
5756
}
5857
#endif

Shared/Views/PostDetailView.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,11 @@ struct PostDetailView: View {
6666
#endif
6767
}
6868
}
69+
70+
#if DEBUG
71+
struct PostDetailView_Previews: PreviewProvider {
72+
static var previews: some View {
73+
PostDetailView(post: Post.example)
74+
}
75+
}
76+
#endif

Shared/Views/PostView.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,11 @@ struct PostView: View {
4949
}
5050
}
5151
}
52+
53+
#if DEBUG
54+
struct PostView_Previews: PreviewProvider {
55+
static var previews: some View {
56+
PostView(post: Post.example)
57+
}
58+
}
59+
#endif

0 commit comments

Comments
 (0)