|
@ -43,6 +43,8 @@ struct ContentView: View { |
|
|
@State var sub_id: String? = nil |
|
|
@State var sub_id: String? = nil |
|
|
@State var active_sheet: Sheets? = nil |
|
|
@State var active_sheet: Sheets? = nil |
|
|
@State var events: [NostrEvent] = [] |
|
|
@State var events: [NostrEvent] = [] |
|
|
|
|
|
@State var has_events: [String: Bool] = [:] |
|
|
|
|
|
@State var loading: Bool = true |
|
|
@State var connection: NostrConnection? = nil |
|
|
@State var connection: NostrConnection? = nil |
|
|
|
|
|
|
|
|
var MainContent: some View { |
|
|
var MainContent: some View { |
|
@ -56,6 +58,7 @@ struct ContentView: View { |
|
|
var body: some View { |
|
|
var body: some View { |
|
|
ZStack { |
|
|
ZStack { |
|
|
MainContent |
|
|
MainContent |
|
|
|
|
|
.padding() |
|
|
VStack { |
|
|
VStack { |
|
|
Spacer() |
|
|
Spacer() |
|
|
|
|
|
|
|
@ -76,6 +79,10 @@ struct ContentView: View { |
|
|
PostView() |
|
|
PostView() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
.onReceive(NotificationCenter.default.publisher(for: .post)) { obj in |
|
|
|
|
|
let post = obj.object as! NostrPost |
|
|
|
|
|
print("post \(post.content)") |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func connect() { |
|
|
func connect() { |
|
@ -97,6 +104,7 @@ struct ContentView: View { |
|
|
if self.sub_id != sub_id { |
|
|
if self.sub_id != sub_id { |
|
|
self.sub_id = sub_id |
|
|
self.sub_id = sub_id |
|
|
} |
|
|
} |
|
|
|
|
|
print("subscribing to \(sub_id)") |
|
|
self.connection?.send(filter, sub_id: sub_id) |
|
|
self.connection?.send(filter, sub_id: sub_id) |
|
|
case .cancelled: |
|
|
case .cancelled: |
|
|
self.connection?.connect() |
|
|
self.connection?.connect() |
|
@ -108,11 +116,14 @@ struct ContentView: View { |
|
|
case .nostr_event(let ev): |
|
|
case .nostr_event(let ev): |
|
|
switch ev { |
|
|
switch ev { |
|
|
case .event(_, let ev): |
|
|
case .event(_, let ev): |
|
|
|
|
|
if self.loading { |
|
|
|
|
|
self.loading = false |
|
|
|
|
|
} |
|
|
self.sub_id = sub_id |
|
|
self.sub_id = sub_id |
|
|
if ev.kind == 1 { |
|
|
if ev.kind == 1 && !(has_events[ev.id] ?? false) { |
|
|
|
|
|
has_events[ev.id] = true |
|
|
self.events.append(ev) |
|
|
self.events.append(ev) |
|
|
} |
|
|
} |
|
|
print(ev) |
|
|
|
|
|
case .notice(let msg): |
|
|
case .notice(let msg): |
|
|
print(msg) |
|
|
print(msg) |
|
|
} |
|
|
} |
|
@ -130,7 +141,7 @@ func PostButton(action: @escaping () -> ()) -> some View { |
|
|
return Button(action: action, label: { |
|
|
return Button(action: action, label: { |
|
|
Text("+") |
|
|
Text("+") |
|
|
.font(.system(.largeTitle)) |
|
|
.font(.system(.largeTitle)) |
|
|
.frame(width: 67, height: 60) |
|
|
.frame(width: 57, height: 50) |
|
|
.foregroundColor(Color.white) |
|
|
.foregroundColor(Color.white) |
|
|
.padding(.bottom, 7) |
|
|
.padding(.bottom, 7) |
|
|
}) |
|
|
}) |
|
|