Skip to content

Commit

Permalink
Merge pull request #32 from fwcd/migrate-previews
Browse files Browse the repository at this point in the history
Migrate to `#Preview` macro
  • Loading branch information
fwcd authored Aug 3, 2024
2 parents 25d6a67 + b5bda2a commit 0ae0c62
Show file tree
Hide file tree
Showing 21 changed files with 138 additions and 168 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "b59e46bd5f55d21597b7891993fdfad5b480f2a164eac75e256504c0971cacb3",
"originHash" : "3fb8bc8365586d0d44419dc7c81707891e304a27cc79313b21fb9f3ab1bd1c6a",
"pins" : [
{
"identity" : "async-http-client",
Expand Down
6 changes: 2 additions & 4 deletions DistributedChatApp/View/AttachmentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ struct AttachmentView: View {
}
}

struct AttachmentView_Previews: PreviewProvider {
static var previews: some View {
AttachmentView(attachment: ChatAttachment(name: "test.txt", content: .url(URL(string: "data:text/plain;base64,dGVzdDEyMwo=")!)))
}
#Preview {
AttachmentView(attachment: ChatAttachment(name: "test.txt", content: .url(URL(string: "data:text/plain;base64,dGVzdDEyMwo=")!)))
}
23 changes: 11 additions & 12 deletions DistributedChatApp/View/BubbleMessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,20 @@ struct BubbleMessageView: View {
}
}

struct BubbleMessageView_Previews: PreviewProvider {
static let message1 = ChatMessage(author: ChatUser(name: "Alice"), content: "Hi!")
static let message2 = ChatMessage(author: ChatUser(name: "Bob"), content: "This is a long\nmultiline message!", repliedToMessageId: message1.id, wasEncrypted: true)
static let message3 = ChatMessage(author: ChatUser(name: "Charles"), content: .encrypted(ChatCryptoCipherData(sealed: Data(), signature: Data(), ephemeralPublicKey: Data())), repliedToMessageId: message1.id)
@StateObject static var messages = Messages(messages: [
#Preview {
let message1 = ChatMessage(author: ChatUser(name: "Alice"), content: "Hi!")
let message2 = ChatMessage(author: ChatUser(name: "Bob"), content: "This is a long\nmultiline message!", repliedToMessageId: message1.id, wasEncrypted: true)
let message3 = ChatMessage(author: ChatUser(name: "Charles"), content: .encrypted(ChatCryptoCipherData(sealed: Data(), signature: Data(), ephemeralPublicKey: Data())), repliedToMessageId: message1.id)
let messages = Messages(messages: [
message1,
message2,
message3
])
static var previews: some View {
VStack {
BubbleMessageView(message: message1, isMe: false)
BubbleMessageView(message: message2, isMe: true)
BubbleMessageView(message: message3, isMe: true)
}
.environmentObject(messages)

return VStack {
BubbleMessageView(message: message1, isMe: false)
BubbleMessageView(message: message2, isMe: true)
BubbleMessageView(message: message3, isMe: true)
}
.environmentObject(messages)
}
19 changes: 9 additions & 10 deletions DistributedChatApp/View/ChannelSnippetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ struct ChannelSnippetView: View {
}
}

struct ChannelSnippetView_Previews: PreviewProvider {
@StateObject static var messages = Messages()
@StateObject static var settings = Settings()
@StateObject static var network = Network(messages: messages)
static var previews: some View {
ChannelSnippetView(channel: .room("test"))
.environmentObject(messages)
.environmentObject(settings)
.environmentObject(network)
}
#Preview {
let messages = Messages()
let settings = Settings()
let network = Network(messages: messages)

return ChannelSnippetView(channel: .room("test"))
.environmentObject(messages)
.environmentObject(settings)
.environmentObject(network)
}
29 changes: 14 additions & 15 deletions DistributedChatApp/View/ChannelView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,22 @@ struct ChannelView: View {
}
}

struct ChatView_Previews: PreviewProvider {
static let controller = ChatController(transport: MockTransport())
static let alice = controller.me
static let bob = ChatUser(name: "Bob")
@StateObject static var messages = Messages(messages: [
#Preview {
let controller = ChatController(transport: MockTransport())
let alice = controller.me
let bob = ChatUser(name: "Bob")
let messages = Messages(messages: [
ChatMessage(author: alice, content: "Hello!"),
ChatMessage(author: bob, content: "Hi!"),
ChatMessage(author: bob, content: "This is fancy!"),
])
@StateObject static var settings = Settings()
@StateObject static var network = Network(myId: controller.me.id, messages: messages)
@StateObject static var navigation = Navigation()
static var previews: some View {
ChannelView(channel: .global, controller: controller)
.environmentObject(messages)
.environmentObject(settings)
.environmentObject(network)
.environmentObject(navigation)
}
let settings = Settings()
let network = Network(myId: controller.me.id, messages: messages)
let navigation = Navigation()

return ChannelView(channel: .global, controller: controller)
.environmentObject(messages)
.environmentObject(settings)
.environmentObject(network)
.environmentObject(navigation)
}
23 changes: 11 additions & 12 deletions DistributedChatApp/View/ChannelsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,15 @@ struct ChannelsView: View {
}
}

struct ChatsView_Previews: PreviewProvider {
@StateObject static var messages = Messages()
@StateObject static var navigation = Navigation()
@StateObject static var settings = Settings()
@StateObject static var network = Network(messages: messages)
static var previews: some View {
ChannelsView(channels: [], controller: ChatController(transport: MockTransport()))
.environmentObject(messages)
.environmentObject(navigation)
.environmentObject(settings)
.environmentObject(network)
}
#Preview {
let messages = Messages()
let navigation = Navigation()
let settings = Settings()
let network = Network(messages: messages)

return ChannelsView(channels: [], controller: ChatController(transport: MockTransport()))
.environmentObject(messages)
.environmentObject(navigation)
.environmentObject(settings)
.environmentObject(network)
}
8 changes: 3 additions & 5 deletions DistributedChatApp/View/ClosableStatusBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ struct ClosableStatusBar<V>: View where V: View {
}
}

struct ClosableStatusBar_Previews: PreviewProvider {
static var previews: some View {
ClosableStatusBar(onClose: {}) {
Text("Test")
}
#Preview {
ClosableStatusBar(onClose: {}) {
Text("Test")
}
}
6 changes: 2 additions & 4 deletions DistributedChatApp/View/CompactMessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ struct CompactMessageView: View {
}
}

struct CompactMessageView_Previews: PreviewProvider {
static var previews: some View {
CompactMessageView(message: ChatMessage(author: ChatUser(name: "Alice"), content: "Test"))
}
#Preview {
CompactMessageView(message: ChatMessage(author: ChatUser(name: "Alice"), content: "Test"))
}
27 changes: 13 additions & 14 deletions DistributedChatApp/View/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,17 @@ struct ContentView: View {
}
}

struct ContentView_Previews: PreviewProvider {
@StateObject static var settings = Settings()
@StateObject static var messages = Messages()
@StateObject static var navigation = Navigation()
@StateObject static var profile = Profile()
@StateObject static var network = Network(myId: profile.me.id, messages: messages)
static var previews: some View {
ContentView(controller: ChatController(transport: MockTransport()))
.environmentObject(settings)
.environmentObject(messages)
.environmentObject(navigation)
.environmentObject(network)
.environmentObject(profile)
}
#Preview {
let settings = Settings()
let messages = Messages()
let navigation = Navigation()
let profile = Profile()
let network = Network(myId: profile.me.id, messages: messages)

return ContentView(controller: ChatController(transport: MockTransport()))
.environmentObject(settings)
.environmentObject(messages)
.environmentObject(navigation)
.environmentObject(network)
.environmentObject(profile)
}
6 changes: 2 additions & 4 deletions DistributedChatApp/View/FileAttachmentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ struct FileAttachmentView: View {
}
}

struct FileAttachmentView_Previews: PreviewProvider {
static var previews: some View {
AttachmentView(attachment: ChatAttachment(name: "test.txt", content: .url(URL(string: "data:text/plain;base64,dGVzdDEyMwo=")!)))
}
#Preview {
AttachmentView(attachment: ChatAttachment(name: "test.txt", content: .url(URL(string: "data:text/plain;base64,dGVzdDEyMwo=")!)))
}
19 changes: 9 additions & 10 deletions DistributedChatApp/View/MessageComposeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,13 @@ struct MessageComposeView: View {
}
}

struct MessageComposeView_Previews: PreviewProvider {
static let controller = ChatController(transport: MockTransport())
@StateObject static var messages = Messages()
@StateObject static var network = Network(messages: messages)
@State static var replyingToMessageId: UUID? = nil
static var previews: some View {
MessageComposeView(channel: .global, controller: controller, replyingToMessageId: $replyingToMessageId)
.environmentObject(messages)
.environmentObject(network)
}
#Preview {
let controller = ChatController(transport: MockTransport())
let messages = Messages()
let network = Network(messages: messages)
let replyingToMessageId: UUID? = nil

return MessageComposeView(channel: .global, controller: controller, replyingToMessageId: .constant(replyingToMessageId))
.environmentObject(messages)
.environmentObject(network)
}
27 changes: 13 additions & 14 deletions DistributedChatApp/View/MessageHistoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,21 @@ struct MessageHistoryView: View {
}
}

struct MessageHistoryView_Previews: PreviewProvider {
static let controller = ChatController(transport: MockTransport())
static let alice = controller.me
static let bob = ChatUser(name: "Bob")
@StateObject static var messages = Messages(messages: [
#Preview {
let controller = ChatController(transport: MockTransport())
let alice = controller.me
let bob = ChatUser(name: "Bob")
let messages = Messages(messages: [
ChatMessage(author: alice, content: "Hello!"),
ChatMessage(author: bob, content: "Hi!"),
ChatMessage(author: bob, content: "This is fancy!"),
])
@StateObject static var settings = Settings()
@StateObject static var navigation = Navigation()
@State static var replyingToMessageId: UUID? = nil
static var previews: some View {
MessageHistoryView(channel: nil, controller: controller, replyingToMessageId: $replyingToMessageId)
.environmentObject(messages)
.environmentObject(settings)
.environmentObject(navigation)
}
let settings = Settings()
let navigation = Navigation()
let replyingToMessageId: UUID? = nil

return MessageHistoryView(channel: nil, controller: controller, replyingToMessageId: .constant(replyingToMessageId))
.environmentObject(messages)
.environmentObject(settings)
.environmentObject(navigation)
}
27 changes: 13 additions & 14 deletions DistributedChatApp/View/MessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,21 @@ struct MessageView: View {
}
}

struct MessageView_Previews: PreviewProvider {
static let controller = ChatController(transport: MockTransport())
static let alice = controller.me
static let bob = ChatUser(name: "Bob")
@StateObject static var messages = Messages(messages: [
#Preview {
let controller = ChatController(transport: MockTransport())
let alice = controller.me
let bob = ChatUser(name: "Bob")
let messages = Messages(messages: [
ChatMessage(author: alice, content: "Hello!"),
ChatMessage(author: bob, content: "Hi!"),
ChatMessage(author: bob, content: "This is fancy!"),
])
@StateObject static var settings = Settings()
@StateObject static var navigation = Navigation()
@State static var replyingToMessageId: UUID? = nil
static var previews: some View {
MessageView(message: messages.messages.values.first { $0.content == "Hello!" }!, controller: controller, replyingToMessageId: $replyingToMessageId)
.environmentObject(messages)
.environmentObject(settings)
.environmentObject(navigation)
}
let settings = Settings()
let navigation = Navigation()
let replyingToMessageId: UUID? = nil

return MessageView(message: messages.messages.values.first { $0.content == "Hello!" }!, controller: controller, replyingToMessageId: .constant(replyingToMessageId))
.environmentObject(messages)
.environmentObject(settings)
.environmentObject(navigation)
}
18 changes: 8 additions & 10 deletions DistributedChatApp/View/NetworkView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,19 @@ struct NetworkView: View {
}
}

struct NetworkView_Previews: PreviewProvider {
static let alice = ChatUser(name: "Alice")
static let bob = ChatUser(name: "Bob")
@StateObject static var network = Network(nearbyUsers: [
#Preview {
let alice = ChatUser(name: "Alice")
let bob = ChatUser(name: "Bob")
let network = Network(nearbyUsers: [
NearbyUser(peripheralIdentifier: UUID(uuidString: "6b61a69b-f4b4-4321-92db-9d61653ddaf6")!, chatUser: alice, rssi: -49),
NearbyUser(peripheralIdentifier: UUID(uuidString: "b7b7d248-9640-490d-8187-44fc9ebfa1ff")!, chatUser: bob, rssi: -55),
], presences: [
ChatPresence(user: alice, status: .online),
ChatPresence(user: bob, status: .away, info: "At the gym"),
], messages: Messages())
@StateObject static var navigation = Navigation()
let navigation = Navigation()

static var previews: some View {
NetworkView()
.environmentObject(network)
.environmentObject(navigation)
}
return NetworkView()
.environmentObject(network)
.environmentObject(navigation)
}
10 changes: 4 additions & 6 deletions DistributedChatApp/View/NewChannelView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ struct NewChannelView: View {
}
}

struct NewChannelView_Previews: PreviewProvider {
@StateObject static var network = Network()
#Preview {
let network = Network()

static var previews: some View {
NewChannelView { _ in }
.environmentObject(network)
}
return NewChannelView { _ in }
.environmentObject(network)
}
6 changes: 2 additions & 4 deletions DistributedChatApp/View/PlainMessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ struct PlainMessageView: View {
}
}

struct PlainMessageView_Previews: PreviewProvider {
static var previews: some View {
PlainMessageView(message: ChatMessage(author: ChatUser(name: "Alice"), content: "Test"))
}
#Preview {
PlainMessageView(message: ChatMessage(author: ChatUser(name: "Alice"), content: "Test"))
}
14 changes: 6 additions & 8 deletions DistributedChatApp/View/PresenceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ struct PresenceView: View {
}
}

struct PresenceView_Previews: PreviewProvider {
@StateObject static var network = Network()
@StateObject static var navigation = Navigation()
#Preview {
let network = Network()
let navigation = Navigation()

static var previews: some View {
PresenceView(presence: ChatPresence(user: .init()))
.environmentObject(network)
.environmentObject(navigation)
}
return PresenceView(presence: ChatPresence(user: .init()))
.environmentObject(network)
.environmentObject(navigation)
}
11 changes: 5 additions & 6 deletions DistributedChatApp/View/ProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ struct ProfileView: View {
}
}

struct ProfileView_Previews: PreviewProvider {
@StateObject static var profile = Profile()
static var previews: some View {
ProfileView()
.environmentObject(profile)
}
#Preview {
let profile = Profile()

return ProfileView()
.environmentObject(profile)
}
Loading

0 comments on commit 0ae0c62

Please sign in to comment.