commit bcff8d5f02454f70e3988695a1b3126c7f16c518
parent 5bb46c5d100e1859712e9b30accd80c8d61691a2
Author: William Casarin <jb55@jb55.com>
Date: Mon, 18 Apr 2022 17:33:15 -0700
refactor timeline and nav
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
3 files changed, 73 insertions(+), 44 deletions(-)
diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj
@@ -17,6 +17,7 @@
4C75EFB728049D990006080F /* RelayPool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFB628049D990006080F /* RelayPool.swift */; };
4C75EFB92804A2740006080F /* EventView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFB82804A2740006080F /* EventView.swift */; };
4C75EFBB2804A34C0006080F /* ProofOfWork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFBA2804A34C0006080F /* ProofOfWork.swift */; };
+ 4CA2EFA0280E37AC0044ACD8 /* TimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA2EF9F280E37AC0044ACD8 /* TimelineView.swift */; };
4CACA9D5280C31E100D9BBE8 /* ReplyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */; };
4CACA9DC280C38C000D9BBE8 /* Profiles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACA9DB280C38C000D9BBE8 /* Profiles.swift */; };
4CE6DEE727F7A08100C66700 /* damusApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE6DEE627F7A08100C66700 /* damusApp.swift */; };
@@ -68,6 +69,7 @@
4C75EFB628049D990006080F /* RelayPool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayPool.swift; sourceTree = "<group>"; };
4C75EFB82804A2740006080F /* EventView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventView.swift; sourceTree = "<group>"; };
4C75EFBA2804A34C0006080F /* ProofOfWork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProofOfWork.swift; sourceTree = "<group>"; };
+ 4CA2EF9F280E37AC0044ACD8 /* TimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineView.swift; sourceTree = "<group>"; };
4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReplyView.swift; sourceTree = "<group>"; };
4CACA9DB280C38C000D9BBE8 /* Profiles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Profiles.swift; sourceTree = "<group>"; };
4CE6DEE327F7A08100C66700 /* damus.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = damus.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -131,6 +133,7 @@
4CEE2AF8280B2EAC00AB5EEF /* PowView.swift */,
4CEE2B01280B39E800AB5EEF /* EventActionBar.swift */,
4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */,
+ 4CA2EF9F280E37AC0044ACD8 /* TimelineView.swift */,
);
path = Views;
sourceTree = "<group>";
@@ -367,6 +370,7 @@
4C75EFB92804A2740006080F /* EventView.swift in Sources */,
4C75EFA627FF87A20006080F /* Nostr.swift in Sources */,
4C75EFB328049D640006080F /* NostrEvent.swift in Sources */,
+ 4CA2EFA0280E37AC0044ACD8 /* TimelineView.swift in Sources */,
4C75EFB128049D510006080F /* NostrResponse.swift in Sources */,
4CEE2AF7280B2DEA00AB5EEF /* ProfileName.swift in Sources */,
4CEE2B02280B39E800AB5EEF /* EventActionBar.swift in Sources */,
diff --git a/damus/ContentView.swift b/damus/ContentView.swift
@@ -24,58 +24,44 @@ enum Sheets: Identifiable {
}
}
-enum Timeline {
- case friends
- case global
- case debug
+enum Timeline: String, CustomStringConvertible {
+ case home
+ case notifications
+
+ var description: String {
+ return self.rawValue
+ }
}
struct ContentView: View {
@State var status: String = "Not connected"
@State var active_sheet: Sheets? = nil
- @State var events: [NostrEvent] = []
@State var profiles: Profiles = Profiles()
@State var friends: [String: ()] = [:]
- @State var has_events: [String: ()] = [:]
- @State var profile_count: Int = 0
- @State var last_event_of_kind: [Int: NostrEvent] = [:]
@State var loading: Bool = true
- @State var timeline: Timeline = .friends
@State var pool: RelayPool? = nil
+ @State var selected_timeline: Timeline? = .home
+ @State var last_event_of_kind: [Int: NostrEvent] = [:]
+ @State var has_events: [String: ()] = [:]
+
+ @State var events: [NostrEvent] = []
+ @State var notifications: [NostrEvent] = []
let sub_id = UUID().description
let pubkey = "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245"
- func MainContent(pool: RelayPool) -> some View {
- ScrollView {
- ForEach(self.events, id: \.id) { (ev: NostrEvent) in
- if ev.is_local && timeline == .debug || (timeline == .global && !ev.is_local) || (timeline == .friends && is_friend(ev.pubkey)) {
- let evdet = EventDetailView(event: ev, pool: pool)
- .navigationBarTitle("Thread")
- .environmentObject(profiles)
- NavigationLink(destination: evdet) {
- EventView(event: ev, highlight: .none, has_action_bar: true)
- }
- .buttonStyle(PlainButtonStyle())
- }
- }
- }
- .environmentObject(profiles)
- }
-
func TimelineButton(timeline: Timeline, img: String) -> some View {
- Button(action: {switch_timeline(timeline)}) {
+ NavigationLink(destination: Text("\(timeline.description)"), tag: timeline, selection: $selected_timeline){
Label("", systemImage: img)
}
.frame(maxWidth: .infinity)
- .foregroundColor(self.timeline != timeline ? .gray : .primary)
+ .foregroundColor(selected_timeline != timeline ? .gray : .primary)
}
func TopBar(selected: Timeline) -> some View {
HStack {
- TimelineButton(timeline: .friends, img: selected == .friends ? "person.2.fill" : "person.2")
- TimelineButton(timeline: .global, img: selected == .global ? "globe.americas.fill" : "globe.americas")
- TimelineButton(timeline: .debug, img: selected == .debug ? "wrench.fill" : "wrench")
+ TimelineButton(timeline: .home, img: selected == .home ? "house.fill" : "house")
+ TimelineButton(timeline: .notifications, img: selected == .notifications ? "bell.fill" : "bell")
}
}
@@ -93,24 +79,26 @@ struct ContentView: View {
}
var body: some View {
- NavigationView {
- VStack {
- if self.loading {
- ProgressView()
- .progressViewStyle(.circular)
- .padding([.bottom], 4)
- }
-
+ VStack {
+ if self.loading {
+ ProgressView()
+ .progressViewStyle(.circular)
+ .padding([.bottom], 4)
+ }
+
+ NavigationView {
ZStack {
if let pool = self.pool {
- MainContent(pool: pool)
+ TimelineView(events: $events, pool: pool)
+ .environmentObject(profiles)
.padding()
}
PostButtonContainer
}
- TopBar(selected: self.timeline ?? .friends)
+ .navigationBarTitle("Damus", displayMode: .inline)
}
- .navigationBarTitle("Damus", displayMode: .inline)
+
+ TopBar(selected: selected_timeline ?? .home)
}
.onAppear() {
self.connect()
@@ -135,7 +123,7 @@ struct ContentView: View {
}
func switch_timeline(_ timeline: Timeline) {
- self.timeline = timeline
+ self.selected_timeline = timeline
}
func add_relay(_ pool: RelayPool, _ relay: String) {
@@ -294,7 +282,6 @@ struct ContentView_Previews: PreviewProvider {
}
-
func get_metadata_since_time(_ metadata_event: NostrEvent?) -> Int64? {
if metadata_event == nil {
return nil
diff --git a/damus/Views/TimelineView.swift b/damus/Views/TimelineView.swift
@@ -0,0 +1,38 @@
+//
+// TimelineView.swift
+// damus
+//
+// Created by William Casarin on 2022-04-18.
+//
+
+import SwiftUI
+
+struct TimelineView: View {
+ @Binding var events: [NostrEvent]
+ @EnvironmentObject var profiles: Profiles
+
+ let pool: RelayPool
+
+ var body: some View {
+ ScrollView {
+ ForEach(events, id: \.id) { (ev: NostrEvent) in
+ let evdet = EventDetailView(event: ev, pool: pool)
+ .navigationBarTitle("Thread")
+ .environmentObject(profiles)
+ NavigationLink(destination: evdet) {
+ EventView(event: ev, highlight: .none, has_action_bar: true)
+ }
+ .buttonStyle(PlainButtonStyle())
+ }
+ }
+ .environmentObject(profiles)
+ }
+}
+
+/*
+struct TimelineView_Previews: PreviewProvider {
+ static var previews: some View {
+ TimelineView()
+ }
+}
+ */