Skip to content

Commit

Permalink
Merge pull request #10 from SirArkimedes/previews
Browse files Browse the repository at this point in the history
Create previews for the Shared views
  • Loading branch information
carson-katri authored Oct 30, 2019
2 parents 1da8bcd + ebc53dc commit cab1e95
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 2 deletions.
17 changes: 17 additions & 0 deletions Shared/Models/Comment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,20 @@ struct Comment: Decodable {
}
}
}

#if DEBUG
extension Comment {
/// Used to initialize a Comment for Debug purposes
init(nested: Int) {
id = "123"
author = "sirarkimedes"
score = 123556
body = "This is a body of text that is purely to act as an example!"
if nested != 0 {
replies = CommentListing(data: CommentListing.CommentListingData(children: [CommentListing.CommentListingData.CommentData(data: Comment(nested: nested - 1))]))
} else{
replies = nil
}
}
}
#endif
9 changes: 9 additions & 0 deletions Shared/Models/Post.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,12 @@ struct Post: Decodable, Identifiable {
}
}
}

#if DEBUG
extension Post {
/// Used to create a Post for example Debug purposes
static var example: Self {
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)
}
}
#endif
21 changes: 21 additions & 0 deletions Shared/Views/CommentsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import SwiftUI
import Request

// MARK: - CommentsView

struct CommentsView: View {
let post: Post

Expand Down Expand Up @@ -40,6 +42,8 @@ struct CommentsView: View {
}
}

// MARK: - CommentView

struct CommentView: View {
let comment: Comment
let postAuthor: String
Expand Down Expand Up @@ -85,3 +89,20 @@ struct CommentView: View {
}
}
}

// MARK: - Comment View preview

#if DEBUG
struct CommentView_Previews: PreviewProvider {
static func example(for author: String, nested: Int = 5) -> some View {
CommentView(comment: Comment(nested: nested), postAuthor: author, nestLevel: 0).frame(width: nil, height: 60)
}

static var previews: some View {
VStack {
example(for: "not", nested: 2)
example(for: "sirarkimedes")
}
}
}
#endif
3 changes: 1 addition & 2 deletions Shared/Views/MetadataView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ struct MetadataView: View {
#if DEBUG
struct MetadataView_Previews: PreviewProvider {
static var previews: some View {
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)
.font(.system(size: 10))
MetadataView(post: Post.example, spaced: true)
}
}
#endif
8 changes: 8 additions & 0 deletions Shared/Views/PostDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,11 @@ struct PostDetailView: View {
#endif
}
}

#if DEBUG
struct PostDetailView_Previews: PreviewProvider {
static var previews: some View {
PostDetailView(post: Post.example)
}
}
#endif
8 changes: 8 additions & 0 deletions Shared/Views/PostView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ struct PostView: View {
}
}
}

#if DEBUG
struct PostView_Previews: PreviewProvider {
static var previews: some View {
PostView(post: Post.example)
}
}
#endif

0 comments on commit cab1e95

Please sign in to comment.