refactor: move BuilderEventView to it's own file
This commit is contained in:
@@ -126,6 +126,7 @@
|
|||||||
4CB88396296F7F8B00DC99E7 /* ReactionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB88395296F7F8B00DC99E7 /* ReactionView.swift */; };
|
4CB88396296F7F8B00DC99E7 /* ReactionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB88395296F7F8B00DC99E7 /* ReactionView.swift */; };
|
||||||
4CB8839A297322D200DC99E7 /* DMTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB88399297322D200DC99E7 /* DMTests.swift */; };
|
4CB8839A297322D200DC99E7 /* DMTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB88399297322D200DC99E7 /* DMTests.swift */; };
|
||||||
4CBCA930297DB57F00EC6B2F /* WebsiteLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CBCA92F297DB57F00EC6B2F /* WebsiteLink.swift */; };
|
4CBCA930297DB57F00EC6B2F /* WebsiteLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CBCA92F297DB57F00EC6B2F /* WebsiteLink.swift */; };
|
||||||
|
4CC7AAEB297F0AEC00430951 /* BuilderEventView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CC7AAEA297F0AEC00430951 /* BuilderEventView.swift */; };
|
||||||
4CD7641B28A1641400B6928F /* EndBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CD7641A28A1641400B6928F /* EndBlock.swift */; };
|
4CD7641B28A1641400B6928F /* EndBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CD7641A28A1641400B6928F /* EndBlock.swift */; };
|
||||||
4CE4F8CD281352B30009DFBB /* Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4F8CC281352B30009DFBB /* Notifications.swift */; };
|
4CE4F8CD281352B30009DFBB /* Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4F8CC281352B30009DFBB /* Notifications.swift */; };
|
||||||
4CE4F9DE2852768D00C00DD9 /* ConfigView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4F9DD2852768D00C00DD9 /* ConfigView.swift */; };
|
4CE4F9DE2852768D00C00DD9 /* ConfigView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4F9DD2852768D00C00DD9 /* ConfigView.swift */; };
|
||||||
@@ -347,6 +348,7 @@
|
|||||||
4CB88395296F7F8B00DC99E7 /* ReactionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactionView.swift; sourceTree = "<group>"; };
|
4CB88395296F7F8B00DC99E7 /* ReactionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactionView.swift; sourceTree = "<group>"; };
|
||||||
4CB88399297322D200DC99E7 /* DMTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DMTests.swift; sourceTree = "<group>"; };
|
4CB88399297322D200DC99E7 /* DMTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DMTests.swift; sourceTree = "<group>"; };
|
||||||
4CBCA92F297DB57F00EC6B2F /* WebsiteLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebsiteLink.swift; sourceTree = "<group>"; };
|
4CBCA92F297DB57F00EC6B2F /* WebsiteLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebsiteLink.swift; sourceTree = "<group>"; };
|
||||||
|
4CC7AAEA297F0AEC00430951 /* BuilderEventView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuilderEventView.swift; sourceTree = "<group>"; };
|
||||||
4CD7641A28A1641400B6928F /* EndBlock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EndBlock.swift; sourceTree = "<group>"; };
|
4CD7641A28A1641400B6928F /* EndBlock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EndBlock.swift; sourceTree = "<group>"; };
|
||||||
4CE4F8CC281352B30009DFBB /* Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notifications.swift; sourceTree = "<group>"; };
|
4CE4F8CC281352B30009DFBB /* Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notifications.swift; sourceTree = "<group>"; };
|
||||||
4CE4F9DD2852768D00C00DD9 /* ConfigView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigView.swift; sourceTree = "<group>"; };
|
4CE4F9DD2852768D00C00DD9 /* ConfigView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigView.swift; sourceTree = "<group>"; };
|
||||||
@@ -610,6 +612,7 @@
|
|||||||
4C3A1D3629637E0500558C0F /* PreviewCache.swift */,
|
4C3A1D3629637E0500558C0F /* PreviewCache.swift */,
|
||||||
64FBD06E296255C400D9D3B2 /* Theme.swift */,
|
64FBD06E296255C400D9D3B2 /* Theme.swift */,
|
||||||
4CB8838529656C8B00DC99E7 /* NIP05.swift */,
|
4CB8838529656C8B00DC99E7 /* NIP05.swift */,
|
||||||
|
4CC7AAEA297F0AEC00430951 /* BuilderEventView.swift */,
|
||||||
);
|
);
|
||||||
path = Util;
|
path = Util;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -945,6 +948,7 @@
|
|||||||
4C3BEFDC281DCE6100B3DE84 /* Liked.swift in Sources */,
|
4C3BEFDC281DCE6100B3DE84 /* Liked.swift in Sources */,
|
||||||
4C75EFB128049D510006080F /* NostrResponse.swift in Sources */,
|
4C75EFB128049D510006080F /* NostrResponse.swift in Sources */,
|
||||||
4CEE2AF7280B2DEA00AB5EEF /* ProfileName.swift in Sources */,
|
4CEE2AF7280B2DEA00AB5EEF /* ProfileName.swift in Sources */,
|
||||||
|
4CC7AAEB297F0AEC00430951 /* BuilderEventView.swift in Sources */,
|
||||||
31D2E847295218AF006D67F8 /* Shimmer.swift in Sources */,
|
31D2E847295218AF006D67F8 /* Shimmer.swift in Sources */,
|
||||||
4C285C8228385570008A31F1 /* CarouselView.swift in Sources */,
|
4C285C8228385570008A31F1 /* CarouselView.swift in Sources */,
|
||||||
4C3EA67F28FFC01D00C48A62 /* InvoiceView.swift in Sources */,
|
4C3EA67F28FFC01D00C48A62 /* InvoiceView.swift in Sources */,
|
||||||
|
|||||||
80
damus/Util/BuilderEventView.swift
Normal file
80
damus/Util/BuilderEventView.swift
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
//
|
||||||
|
// BuilderEventView.swift
|
||||||
|
// damus
|
||||||
|
//
|
||||||
|
// Created by William Casarin on 2023-01-23.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct BuilderEventView: View {
|
||||||
|
let damus: DamusState
|
||||||
|
let event_id: String
|
||||||
|
@State var event: NostrEvent?
|
||||||
|
@State var subscription_uuid: String = UUID().description
|
||||||
|
|
||||||
|
func unsubscribe() {
|
||||||
|
damus.pool.unsubscribe(sub_id: subscription_uuid)
|
||||||
|
}
|
||||||
|
|
||||||
|
func subscribe(filters: [NostrFilter]) {
|
||||||
|
damus.pool.register_handler(sub_id: subscription_uuid, handler: handle_event)
|
||||||
|
damus.pool.send(.subscribe(.init(filters: filters, sub_id: subscription_uuid)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func handle_event(relay_id: String, ev: NostrConnectionEvent) {
|
||||||
|
guard case .nostr_event(let nostr_response) = ev else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guard case .event(let id, let nostr_event) = nostr_response else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Is current event
|
||||||
|
if id == subscription_uuid {
|
||||||
|
if event != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
event = nostr_event
|
||||||
|
|
||||||
|
unsubscribe()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func load() {
|
||||||
|
subscribe(filters: [
|
||||||
|
NostrFilter(
|
||||||
|
ids: [self.event_id],
|
||||||
|
limit: 1
|
||||||
|
)
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
if let event = event {
|
||||||
|
let ev = event.inner_event ?? event
|
||||||
|
NavigationLink(destination: BuildThreadV2View(damus: damus, event_id: ev.id)) {
|
||||||
|
EventView(damus: damus, event: event, show_friend_icon: true, size: .small, embedded: true)
|
||||||
|
}.buttonStyle(.plain)
|
||||||
|
} else {
|
||||||
|
ProgressView().padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(minWidth: 0, maxWidth: .infinity)
|
||||||
|
.border(Color.gray.opacity(0.2), width: 1)
|
||||||
|
.cornerRadius(2)
|
||||||
|
.onAppear {
|
||||||
|
self.load()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct BuilderEventView_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
BuilderEventView(damus: test_damus_state(), event_id: "536bee9e83c818e3b82c101935128ae27a0d4290039aaf253efe5f09232c1962")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -56,71 +56,6 @@ func eventviewsize_to_font(_ size: EventViewKind) -> Font {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BuilderEventView: View {
|
|
||||||
let damus: DamusState
|
|
||||||
let event_id: String
|
|
||||||
@State var event: NostrEvent?
|
|
||||||
@State var subscription_uuid: String = UUID().description
|
|
||||||
|
|
||||||
func unsubscribe() {
|
|
||||||
damus.pool.unsubscribe(sub_id: subscription_uuid)
|
|
||||||
}
|
|
||||||
|
|
||||||
func subscribe(filters: [NostrFilter]) {
|
|
||||||
damus.pool.register_handler(sub_id: subscription_uuid, handler: handle_event)
|
|
||||||
damus.pool.send(.subscribe(.init(filters: filters, sub_id: subscription_uuid)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func handle_event(relay_id: String, ev: NostrConnectionEvent) {
|
|
||||||
guard case .nostr_event(let nostr_response) = ev else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
guard case .event(let id, let nostr_event) = nostr_response else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is current event
|
|
||||||
if id == subscription_uuid {
|
|
||||||
if event != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
event = nostr_event
|
|
||||||
|
|
||||||
unsubscribe()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func load() {
|
|
||||||
subscribe(filters: [
|
|
||||||
NostrFilter(
|
|
||||||
ids: [self.event_id],
|
|
||||||
limit: 1
|
|
||||||
)
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack {
|
|
||||||
if let event = event {
|
|
||||||
let ev = event.inner_event ?? event
|
|
||||||
NavigationLink(destination: BuildThreadV2View(damus: damus, event_id: ev.id)) {
|
|
||||||
EventView(damus: damus, event: event, show_friend_icon: true, size: .small, embedded: true)
|
|
||||||
}.buttonStyle(.plain)
|
|
||||||
} else {
|
|
||||||
ProgressView().padding()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.frame(minWidth: 0, maxWidth: .infinity)
|
|
||||||
.border(Color.gray.opacity(0.2), width: 1)
|
|
||||||
.cornerRadius(2)
|
|
||||||
.onAppear {
|
|
||||||
self.load()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct EventView: View {
|
struct EventView: View {
|
||||||
let event: NostrEvent
|
let event: NostrEvent
|
||||||
let highlight: Highlight
|
let highlight: Highlight
|
||||||
|
|||||||
Reference in New Issue
Block a user