From 5733f782d933a9fbe491ae3f88e7ab77c5a5cc97 Mon Sep 17 00:00:00 2001 From: Ben Weeks Date: Fri, 6 Jan 2023 20:11:19 +0000 Subject: [PATCH 01/12] Latest updates to the sidebar. --- damus.xcodeproj/project.pbxproj | 6 +- damus/ContentView.swift | 339 +++++++++++++++++--------------- damus/Views/SideMenuView.swift | 118 +++++++++++ 3 files changed, 302 insertions(+), 161 deletions(-) create mode 100644 damus/Views/SideMenuView.swift diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj index cdfe468f..74a4c1ff 100644 --- a/damus.xcodeproj/project.pbxproj +++ b/damus.xcodeproj/project.pbxproj @@ -138,6 +138,7 @@ 4CEE2AF9280B2EAC00AB5EEF /* PowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF8280B2EAC00AB5EEF /* PowView.swift */; }; 4CEE2B02280B39E800AB5EEF /* EventActionBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2B01280B39E800AB5EEF /* EventActionBar.swift */; }; 4FE60CDD295E1C5E00105A1F /* Wallet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FE60CDC295E1C5E00105A1F /* Wallet.swift */; }; + 647D9A8D2968520300A295DE /* SideMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 647D9A8C2968520300A295DE /* SideMenuView.swift */; }; 64FBD06F296255C400D9D3B2 /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64FBD06E296255C400D9D3B2 /* Theme.swift */; }; 6C7DE41F2955169800E66263 /* Vault in Frameworks */ = {isa = PBXBuildFile; productRef = 6C7DE41E2955169800E66263 /* Vault */; }; BA693074295D649800ADDB87 /* UserSettingsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA693073295D649800ADDB87 /* UserSettingsStore.swift */; }; @@ -331,6 +332,7 @@ 4CEE2AF8280B2EAC00AB5EEF /* PowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PowView.swift; sourceTree = ""; }; 4CEE2B01280B39E800AB5EEF /* EventActionBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventActionBar.swift; sourceTree = ""; }; 4FE60CDC295E1C5E00105A1F /* Wallet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Wallet.swift; sourceTree = ""; }; + 647D9A8C2968520300A295DE /* SideMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideMenuView.swift; sourceTree = ""; }; 64FBD06E296255C400D9D3B2 /* Theme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = ""; }; BA693073295D649800ADDB87 /* UserSettingsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSettingsStore.swift; sourceTree = ""; }; BAB68BEC29543FA3007BA466 /* SelectWalletView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectWalletView.swift; sourceTree = ""; }; @@ -487,7 +489,6 @@ 4C3AC79E2833115300E1F516 /* FollowButtonView.swift */, 4C3AC79C2833036D00E1F516 /* FollowingView.swift */, 4C90BD17283A9EE5008EE7EF /* LoginView.swift */, - 4C3AC7A42836987600E1F516 /* MainTabView.swift */, 4C363A8928236B57006E126D /* MentionView.swift */, 4C363A8D28236FE4006E126D /* NoteContentView.swift */, 4C75EFAC28049CFB0006080F /* PostButton.swift */, @@ -497,6 +498,7 @@ 4C285C892838B985008A31F1 /* ProfilePictureSelector.swift */, 4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */, 4C8682862814DE470026224F /* ProfileView.swift */, + 4C3AC7A42836987600E1F516 /* MainTabView.swift */, 4C363A8B28236B92006E126D /* PubkeyView.swift */, 4CB55EF2295E5D59007FD187 /* RecommendedRelayView.swift */, 4C06670028FC7C5900038D2A /* RelayView.swift */, @@ -512,6 +514,7 @@ 4C0A3F96280F8E02000448DE /* ThreadView.swift */, 4CA2EF9F280E37AC0044ACD8 /* TimelineView.swift */, 4CB55EF4295E679D007FD187 /* UserRelaysView.swift */, + 647D9A8C2968520300A295DE /* SideMenuView.swift */, ); path = Views; sourceTree = ""; @@ -822,6 +825,7 @@ 4C363A9028247A1D006E126D /* NostrLink.swift in Sources */, 4C0A3F8C280F5FCA000448DE /* ChatroomView.swift in Sources */, 4C477C9E282C3A4800033AA3 /* TipCounter.swift in Sources */, + 647D9A8D2968520300A295DE /* SideMenuView.swift in Sources */, 4C0A3F91280F6528000448DE /* ChatView.swift in Sources */, 4C216F362870A9A700040376 /* InputDismissKeyboard.swift in Sources */, 4C216F382871EDE300040376 /* DirectMessageModel.swift in Sources */, diff --git a/damus/ContentView.swift b/damus/ContentView.swift index 2abd09e4..fe75c0ad 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -80,6 +80,7 @@ struct ContentView: View { @State var thread_open: Bool = false @State var search_open: Bool = false @State var filter_state : FilterState = .posts_and_replies + @State private var isSideBarOpened = false @StateObject var home: HomeModel = HomeModel() @StateObject var user_settings = UserSettingsStore() @@ -210,179 +211,197 @@ struct ContentView: View { } var body: some View { - VStack(alignment: .leading, spacing: 0) { - if let damus = self.damus_state { - NavigationView { - MainContent(damus: damus) - .toolbar { - ToolbarItem(placement: .navigationBarLeading) { - let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!) - let followers_model = FollowersModel(damus_state: damus_state!, target: damus_state!.pubkey) - let prof_dest = ProfileView(damus_state: damus_state!, profile: profile_model, followers: followers_model) - - NavigationLink(destination: prof_dest) { - /// Verify that the user has a profile picture, if not display a generic SF Symbol - /// (Resolves an in-app error where ``Robohash`` pictures are not generated so the button dissapears - if let picture = damus_state?.profiles.lookup(id: pubkey)?.picture { - ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles, picture: picture) - } else { - Image(systemName: "person.fill") + //ZStack { + VStack(alignment: .leading, spacing: 0) { + if let damus = self.damus_state { + NavigationView { + SideMenuView(damus_state: damus_state!, isSidebarVisible: $isSideBarOpened) + MainContent(damus: damus) + .toolbar { + ToolbarItem(placement: .navigationBarLeading) { + let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!) + let followers_model = FollowersModel(damus_state: damus_state!, target: damus_state!.pubkey) + let prof_dest = ProfileView(damus_state: damus_state!, profile: profile_model, followers: followers_model) + + Button { + isSideBarOpened.toggle() + } label: { + let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!) + let followers_model = FollowersModel(damus_state: damus_state!, target: damus_state!.pubkey) + let prof_dest = ProfileView(damus_state: damus_state!, profile: profile_model, followers: followers_model) + + if let picture = damus_state?.profiles.lookup(id: pubkey)?.picture { + ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles, picture: picture) + } else { + Image(systemName: "person.fill") + } } - } - .buttonStyle(PlainButtonStyle()) - } - - ToolbarItem(placement: .navigationBarTrailing) { - HStack(alignment: .center) { - if home.signal.signal != home.signal.max_signal { - Text("\(home.signal.signal)/\(home.signal.max_signal)") - .font(.callout) - .foregroundColor(.gray) - } - - NavigationLink(destination: ConfigView(state: damus_state!).environmentObject(user_settings)) { - Label("", systemImage: "gear") + + NavigationLink(destination: prof_dest) { + /// Verify that the user has a profile picture, if not display a generic SF Symbol + /// (Resolves an in-app error where ``Robohash`` pictures are not generated so the button dissapears + if let picture = damus_state?.profiles.lookup(id: pubkey)?.picture { + ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles, picture: picture) + } else { + Image(systemName: "person.fill") + } } .buttonStyle(PlainButtonStyle()) + + } + + ToolbarItem(placement: .navigationBarTrailing) { + HStack(alignment: .center) { + if home.signal.signal != home.signal.max_signal { + Text("\(home.signal.signal)/\(home.signal.max_signal)") + .font(.callout) + .foregroundColor(.gray) + } + + NavigationLink(destination: ConfigView(state: damus_state!).environmentObject(user_settings)) { + Label("", systemImage: "gear") + } + .buttonStyle(PlainButtonStyle()) + } } } - } + } + .navigationViewStyle(.stack) } - .navigationViewStyle(.stack) - } - - TabBar(new_events: $home.new_events, selected: $selected_timeline, action: switch_timeline) - .padding([.bottom], 8) - } - .onAppear() { - self.connect() - //KingfisherManager.shared.cache.clearDiskCache() - setup_notifications() - } - .sheet(item: $active_sheet) { item in - switch item { - case .post: - PostView(replying_to: nil, references: []) - case .reply(let event): - ReplyView(replying_to: event, damus: damus_state!) - } - } - .onOpenURL { url in - guard let link = decode_nostr_uri(url.absoluteString) else { - return - } - - switch link { - case .ref(let ref): - if ref.key == "p" { - active_profile = ref.ref_id - profile_open = true - } else if ref.key == "e" { - active_event_id = ref.ref_id - thread_open = true - } - case .filter(let filt): - active_search = filt - search_open = true - break - // TODO: handle filter searches? - } - - } - .onReceive(handle_notify(.boost)) { notif in - guard let privkey = self.privkey else { - return - } - - let ev = notif.object as! NostrEvent - let boost = make_boost_event(pubkey: pubkey, privkey: privkey, boosted: ev) - self.damus_state?.pool.send(.event(boost)) - } - .onReceive(handle_notify(.open_thread)) { obj in - //let ev = obj.object as! NostrEvent - //thread.set_active_event(ev) - //is_thread_open = true - } - .onReceive(handle_notify(.reply)) { notif in - let ev = notif.object as! NostrEvent - self.active_sheet = .reply(ev) - } - .onReceive(handle_notify(.like)) { like in - } - .onReceive(handle_notify(.broadcast_event)) { obj in - let ev = obj.object as! NostrEvent - self.damus_state?.pool.send(.event(ev)) - } - .onReceive(handle_notify(.unfollow)) { notif in - guard let privkey = self.privkey else { - return - } - - guard let damus = self.damus_state else { - return - } - - let target = notif.object as! FollowTarget - let pk = target.pubkey - - if let ev = unfollow_user(pool: damus.pool, - our_contacts: damus.contacts.event, - pubkey: damus.pubkey, - privkey: privkey, - unfollow: pk) { - notify(.unfollowed, pk) - damus.contacts.event = ev - damus.contacts.remove_friend(pk) - //friend_events = friend_events.filter { $0.pubkey != pk } + TabBar(new_events: $home.new_events, selected: $selected_timeline, action: switch_timeline) + .padding([.bottom], 8) } - } - .onReceive(handle_notify(.follow)) { notif in - guard let privkey = self.privkey else { - return + .onAppear() { + self.connect() + //KingfisherManager.shared.cache.clearDiskCache() + setup_notifications() } - - let fnotify = notif.object as! FollowTarget - guard let damus = self.damus_state else { - return - } - - if let ev = follow_user(pool: damus.pool, - our_contacts: damus.contacts.event, - pubkey: damus.pubkey, - privkey: privkey, - follow: ReferencedId(ref_id: fnotify.pubkey, relay_id: nil, key: "p")) { - notify(.followed, fnotify.pubkey) - - damus_state?.contacts.event = ev - - switch fnotify { - case .pubkey(let pk): - damus.contacts.add_friend_pubkey(pk) - case .contact(let ev): - damus.contacts.add_friend_contact(ev) + .sheet(item: $active_sheet) { item in + switch item { + case .post: + PostView(replying_to: nil, references: []) + case .reply(let event): + ReplyView(replying_to: event, damus: damus_state!) } } - } - .onReceive(handle_notify(.post)) { obj in - guard let privkey = self.privkey else { - return + .onOpenURL { url in + guard let link = decode_nostr_uri(url.absoluteString) else { + return + } + + switch link { + case .ref(let ref): + if ref.key == "p" { + active_profile = ref.ref_id + profile_open = true + } else if ref.key == "e" { + active_event_id = ref.ref_id + thread_open = true + } + case .filter(let filt): + active_search = filt + search_open = true + break + // TODO: handle filter searches? + } + } - - let post_res = obj.object as! NostrPostResult - switch post_res { - case .post(let post): - print("post \(post.content)") - let new_ev = post_to_event(post: post, privkey: privkey, pubkey: pubkey) - self.damus_state?.pool.send(.event(new_ev)) - case .cancel: - active_sheet = nil - print("post cancelled") + .onReceive(handle_notify(.boost)) { notif in + guard let privkey = self.privkey else { + return + } + + let ev = notif.object as! NostrEvent + let boost = make_boost_event(pubkey: pubkey, privkey: privkey, boosted: ev) + self.damus_state?.pool.send(.event(boost)) } - } - .onReceive(timer) { n in - self.damus_state?.pool.connect_to_disconnected() - } + .onReceive(handle_notify(.open_thread)) { obj in + //let ev = obj.object as! NostrEvent + //thread.set_active_event(ev) + //is_thread_open = true + } + .onReceive(handle_notify(.reply)) { notif in + let ev = notif.object as! NostrEvent + self.active_sheet = .reply(ev) + } + .onReceive(handle_notify(.like)) { like in + } + .onReceive(handle_notify(.broadcast_event)) { obj in + let ev = obj.object as! NostrEvent + self.damus_state?.pool.send(.event(ev)) + } + .onReceive(handle_notify(.unfollow)) { notif in + guard let privkey = self.privkey else { + return + } + + guard let damus = self.damus_state else { + return + } + + let target = notif.object as! FollowTarget + let pk = target.pubkey + + if let ev = unfollow_user(pool: damus.pool, + our_contacts: damus.contacts.event, + pubkey: damus.pubkey, + privkey: privkey, + unfollow: pk) { + notify(.unfollowed, pk) + + damus.contacts.event = ev + damus.contacts.remove_friend(pk) + //friend_events = friend_events.filter { $0.pubkey != pk } + } + } + .onReceive(handle_notify(.follow)) { notif in + guard let privkey = self.privkey else { + return + } + + let fnotify = notif.object as! FollowTarget + guard let damus = self.damus_state else { + return + } + + if let ev = follow_user(pool: damus.pool, + our_contacts: damus.contacts.event, + pubkey: damus.pubkey, + privkey: privkey, + follow: ReferencedId(ref_id: fnotify.pubkey, relay_id: nil, key: "p")) { + notify(.followed, fnotify.pubkey) + + damus_state?.contacts.event = ev + + switch fnotify { + case .pubkey(let pk): + damus.contacts.add_friend_pubkey(pk) + case .contact(let ev): + damus.contacts.add_friend_contact(ev) + } + } + } + .onReceive(handle_notify(.post)) { obj in + guard let privkey = self.privkey else { + return + } + + let post_res = obj.object as! NostrPostResult + switch post_res { + case .post(let post): + print("post \(post.content)") + let new_ev = post_to_event(post: post, privkey: privkey, pubkey: pubkey) + self.damus_state?.pool.send(.event(new_ev)) + case .cancel: + active_sheet = nil + print("post cancelled") + } + } + .onReceive(timer) { n in + self.damus_state?.pool.connect_to_disconnected() + } + //} } func switch_timeline(_ timeline: Timeline) { diff --git a/damus/Views/SideMenuView.swift b/damus/Views/SideMenuView.swift new file mode 100644 index 00000000..51623889 --- /dev/null +++ b/damus/Views/SideMenuView.swift @@ -0,0 +1,118 @@ +// +// SideMenuView.swift +// damus +// +// Created by Ben Weeks on 1/6/23. +// Ref: https://blog.logrocket.com/create-custom-collapsible-sidebar-swiftui/ + +import SwiftUI + +struct SideMenuView: View { + let damus_state: DamusState + @Binding var isSidebarVisible: Bool + + var sideBarWidth = UIScreen.main.bounds.size.width * 0.7 + var bgColor: Color = + Color(.init( + red: 52 / 255, + green: 70 / 255, + blue: 182 / 255, + alpha: 1)) + + var body: some View { + if isSidebarVisible { + ZStack { + GeometryReader { _ in + EmptyView() + } + .background(.black.opacity(0.6)) + .opacity(isSidebarVisible ? 1 : 0) + .animation(.easeInOut.delay(0.2), value: isSidebarVisible) + .onTapGesture { + isSidebarVisible.toggle() + } + content + } + .edgesIgnoringSafeArea(.all) + } + } + + var content: some View { + HStack(alignment: .top) { + ZStack(alignment: .top) { + Color("DamusBlack") + + VStack(alignment: .leading, spacing: 20) { + let profile = damus_state.profiles.lookup(id: damus_state.pubkey) + + if let picture = damus_state.profiles.lookup(id: damus_state.pubkey)?.picture { + ProfilePicView(pubkey: damus_state.pubkey, size: 60, highlight: .none, profiles: damus_state.profiles, picture: picture) + } else { + Image(systemName: "person.fill") + } + if let display_name = profile?.display_name { + VStack(alignment: .leading) { + Text(display_name) + .foregroundColor(Color("DamusWhite")) + .font(.headline) + ProfileName(pubkey: damus_state.pubkey, profile: profile, prefix: "@", damus: damus_state, show_friend_confirmed: false) + .font(.callout) + .foregroundColor(.gray) + } + } + + Divider() + + //NavigationView { + let followers = FollowersModel(damus_state: damus_state, target: damus_state.pubkey) + let profile_model = ProfileModel(pubkey: damus_state.pubkey, damus: damus_state) + + NavigationLink(destination: ProfileView(damus_state: damus_state, profile: profile_model, followers: followers) + ) { + Label("Profile", systemImage: "person") + .font(.title2) + .foregroundColor(.accentColor) + } + + NavigationLink(destination: EmptyView()) { + Label("Relays", systemImage: "gear") + .font(.title2) + .foregroundColor(.accentColor) + } + + NavigationLink(destination: ConfigView(state: damus_state)) { + Label("App Settings", systemImage: "xserve") + .font(.title2) + .foregroundColor(.accentColor) + } + + Spacer() + + Button(action: { + //ConfigView(state: damus_state) + notify(.logout, ()) + }, label: { + Label("Sign out", systemImage: "exit") + .font(.title3) + .foregroundColor(Color("DamusWhite")) + }) + } + .padding(.top, 50) + .padding(.bottom, 50) + .padding(.horizontal, 20) + } + .frame(width: sideBarWidth) + .offset(x: isSidebarVisible ? 0 : -sideBarWidth) + .animation(.default, value: isSidebarVisible) + + Spacer() + } + } +} + +struct Previews_SideMenuView_Previews: PreviewProvider { + static var previews: some View { + let ds = test_damus_state() + SideMenuView(damus_state: ds, isSidebarVisible: .constant(true)) + } +} From fba29d44549ccceb4f7e8afc172b1585c0f37bb6 Mon Sep 17 00:00:00 2001 From: Ben Weeks Date: Fri, 6 Jan 2023 22:41:48 +0000 Subject: [PATCH 02/12] Worked on amending the colors. --- damus/ContentView.swift | 349 +++++++++++++++++---------------- damus/Views/ProfileName.swift | 2 +- damus/Views/SideMenuView.swift | 59 ++++-- damus/damusApp.swift | 3 - 4 files changed, 219 insertions(+), 194 deletions(-) diff --git a/damus/ContentView.swift b/damus/ContentView.swift index fe75c0ad..5217c3f6 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -211,197 +211,207 @@ struct ContentView: View { } var body: some View { - //ZStack { + ZStack { + if let damus = self.damus_state { + VStack(alignment: .leading, spacing: 0) { - if let damus = self.damus_state { NavigationView { - SideMenuView(damus_state: damus_state!, isSidebarVisible: $isSideBarOpened) - MainContent(damus: damus) - .toolbar { - ToolbarItem(placement: .navigationBarLeading) { - let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!) - let followers_model = FollowersModel(damus_state: damus_state!, target: damus_state!.pubkey) - let prof_dest = ProfileView(damus_state: damus_state!, profile: profile_model, followers: followers_model) - - Button { - isSideBarOpened.toggle() - } label: { + + SideMenuView(damus_state: damus, isSidebarVisible: $isSideBarOpened).zIndex(1) + + VStack(alignment: .leading, spacing: 0) { + + MainContent(damus: damus) + .toolbar { + ToolbarItem(placement: .navigationBarLeading) { let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!) let followers_model = FollowersModel(damus_state: damus_state!, target: damus_state!.pubkey) let prof_dest = ProfileView(damus_state: damus_state!, profile: profile_model, followers: followers_model) - if let picture = damus_state?.profiles.lookup(id: pubkey)?.picture { - ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles, picture: picture) - } else { - Image(systemName: "person.fill") - } - } - - NavigationLink(destination: prof_dest) { - /// Verify that the user has a profile picture, if not display a generic SF Symbol - /// (Resolves an in-app error where ``Robohash`` pictures are not generated so the button dissapears - if let picture = damus_state?.profiles.lookup(id: pubkey)?.picture { - ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles, picture: picture) - } else { - Image(systemName: "person.fill") - } - } - .buttonStyle(PlainButtonStyle()) - - } - - ToolbarItem(placement: .navigationBarTrailing) { - HStack(alignment: .center) { - if home.signal.signal != home.signal.max_signal { - Text("\(home.signal.signal)/\(home.signal.max_signal)") - .font(.callout) - .foregroundColor(.gray) + Button { + isSideBarOpened.toggle() + } label: { + let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!) + let followers_model = FollowersModel(damus_state: damus_state!, target: damus_state!.pubkey) + let prof_dest = ProfileView(damus_state: damus_state!, profile: profile_model, followers: followers_model) + + if let picture = damus_state?.profiles.lookup(id: pubkey)?.picture { + ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles, picture: picture) + } else { + Image(systemName: "person.fill") + } } - NavigationLink(destination: ConfigView(state: damus_state!).environmentObject(user_settings)) { - Label("", systemImage: "gear") + NavigationLink(destination: prof_dest) { + /// Verify that the user has a profile picture, if not display a generic SF Symbol + /// (Resolves an in-app error where ``Robohash`` pictures are not generated so the button dissapears + if let picture = damus_state?.profiles.lookup(id: pubkey)?.picture { + ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles, picture: picture) + } else { + Image(systemName: "person.fill") + } } .buttonStyle(PlainButtonStyle()) + + } + + ToolbarItem(placement: .navigationBarTrailing) { + HStack(alignment: .center) { + if home.signal.signal != home.signal.max_signal { + Text("\(home.signal.signal)/\(home.signal.max_signal)") + .font(.callout) + .foregroundColor(.gray) + } + + /* + NavigationLink(destination: ConfigView(state: damus_state!).environmentObject(user_settings)) { + Label("", systemImage: "gear") + } + .buttonStyle(PlainButtonStyle()) + */ + } } } - } - } - .navigationViewStyle(.stack) - } - - TabBar(new_events: $home.new_events, selected: $selected_timeline, action: switch_timeline) - .padding([.bottom], 8) - } - .onAppear() { - self.connect() - //KingfisherManager.shared.cache.clearDiskCache() - setup_notifications() - } - .sheet(item: $active_sheet) { item in - switch item { - case .post: - PostView(replying_to: nil, references: []) - case .reply(let event): - ReplyView(replying_to: event, damus: damus_state!) - } - } - .onOpenURL { url in - guard let link = decode_nostr_uri(url.absoluteString) else { - return - } - - switch link { - case .ref(let ref): - if ref.key == "p" { - active_profile = ref.ref_id - profile_open = true - } else if ref.key == "e" { - active_event_id = ref.ref_id - thread_open = true - } - case .filter(let filt): - active_search = filt - search_open = true - break - // TODO: handle filter searches? - } - - } - .onReceive(handle_notify(.boost)) { notif in - guard let privkey = self.privkey else { - return - } - - let ev = notif.object as! NostrEvent - let boost = make_boost_event(pubkey: pubkey, privkey: privkey, boosted: ev) - self.damus_state?.pool.send(.event(boost)) - } - .onReceive(handle_notify(.open_thread)) { obj in - //let ev = obj.object as! NostrEvent - //thread.set_active_event(ev) - //is_thread_open = true - } - .onReceive(handle_notify(.reply)) { notif in - let ev = notif.object as! NostrEvent - self.active_sheet = .reply(ev) - } - .onReceive(handle_notify(.like)) { like in - } - .onReceive(handle_notify(.broadcast_event)) { obj in - let ev = obj.object as! NostrEvent - self.damus_state?.pool.send(.event(ev)) - } - .onReceive(handle_notify(.unfollow)) { notif in - guard let privkey = self.privkey else { - return - } - - guard let damus = self.damus_state else { - return - } - - let target = notif.object as! FollowTarget - let pk = target.pubkey - - if let ev = unfollow_user(pool: damus.pool, - our_contacts: damus.contacts.event, - pubkey: damus.pubkey, - privkey: privkey, - unfollow: pk) { - notify(.unfollowed, pk) + } + }.navigationViewStyle(.stack) - damus.contacts.event = ev - damus.contacts.remove_friend(pk) - //friend_events = friend_events.filter { $0.pubkey != pk } + TabBar(new_events: $home.new_events, selected: $selected_timeline, action: switch_timeline) + .padding([.bottom], 8) } } - .onReceive(handle_notify(.follow)) { notif in - guard let privkey = self.privkey else { - return + } + .onAppear() { + self.connect() + //KingfisherManager.shared.cache.clearDiskCache() + setup_notifications() + } + .sheet(item: $active_sheet) { item in + switch item { + case .post: + PostView(replying_to: nil, references: []) + case .reply(let event): + ReplyView(replying_to: event, damus: damus_state!) + } + } + .onOpenURL { url in + guard let link = decode_nostr_uri(url.absoluteString) else { + return + } + + switch link { + case .ref(let ref): + if ref.key == "p" { + active_profile = ref.ref_id + profile_open = true + } else if ref.key == "e" { + active_event_id = ref.ref_id + thread_open = true } + case .filter(let filt): + active_search = filt + search_open = true + break + // TODO: handle filter searches? + } + + } + .onReceive(handle_notify(.boost)) { notif in + guard let privkey = self.privkey else { + return + } + + let ev = notif.object as! NostrEvent + let boost = make_boost_event(pubkey: pubkey, privkey: privkey, boosted: ev) + self.damus_state?.pool.send(.event(boost)) + } + .onReceive(handle_notify(.open_thread)) { obj in + //let ev = obj.object as! NostrEvent + //thread.set_active_event(ev) + //is_thread_open = true + } + .onReceive(handle_notify(.reply)) { notif in + let ev = notif.object as! NostrEvent + self.active_sheet = .reply(ev) + } + .onReceive(handle_notify(.like)) { like in + } + .onReceive(handle_notify(.broadcast_event)) { obj in + let ev = obj.object as! NostrEvent + self.damus_state?.pool.send(.event(ev)) + } + .onReceive(handle_notify(.unfollow)) { notif in + guard let privkey = self.privkey else { + return + } + + guard let damus = self.damus_state else { + return + } + + let target = notif.object as! FollowTarget + let pk = target.pubkey + + if let ev = unfollow_user(pool: damus.pool, + our_contacts: damus.contacts.event, + pubkey: damus.pubkey, + privkey: privkey, + unfollow: pk) { + notify(.unfollowed, pk) - let fnotify = notif.object as! FollowTarget - guard let damus = self.damus_state else { - return - } + damus.contacts.event = ev + damus.contacts.remove_friend(pk) + //friend_events = friend_events.filter { $0.pubkey != pk } + } + } + .onReceive(handle_notify(.follow)) { notif in + guard let privkey = self.privkey else { + return + } + + let fnotify = notif.object as! FollowTarget + guard let damus = self.damus_state else { + return + } + + if let ev = follow_user(pool: damus.pool, + our_contacts: damus.contacts.event, + pubkey: damus.pubkey, + privkey: privkey, + follow: ReferencedId(ref_id: fnotify.pubkey, relay_id: nil, key: "p")) { + notify(.followed, fnotify.pubkey) - if let ev = follow_user(pool: damus.pool, - our_contacts: damus.contacts.event, - pubkey: damus.pubkey, - privkey: privkey, - follow: ReferencedId(ref_id: fnotify.pubkey, relay_id: nil, key: "p")) { - notify(.followed, fnotify.pubkey) - - damus_state?.contacts.event = ev - - switch fnotify { - case .pubkey(let pk): - damus.contacts.add_friend_pubkey(pk) - case .contact(let ev): - damus.contacts.add_friend_contact(ev) - } - } - } - .onReceive(handle_notify(.post)) { obj in - guard let privkey = self.privkey else { - return - } + damus_state?.contacts.event = ev - let post_res = obj.object as! NostrPostResult - switch post_res { - case .post(let post): - print("post \(post.content)") - let new_ev = post_to_event(post: post, privkey: privkey, pubkey: pubkey) - self.damus_state?.pool.send(.event(new_ev)) - case .cancel: - active_sheet = nil - print("post cancelled") + switch fnotify { + case .pubkey(let pk): + damus.contacts.add_friend_pubkey(pk) + case .contact(let ev): + damus.contacts.add_friend_contact(ev) } } - .onReceive(timer) { n in - self.damus_state?.pool.connect_to_disconnected() + } + .onReceive(handle_notify(.post)) { obj in + guard let privkey = self.privkey else { + return } - //} + + let post_res = obj.object as! NostrPostResult + switch post_res { + case .post(let post): + print("post \(post.content)") + let new_ev = post_to_event(post: post, privkey: privkey, pubkey: pubkey) + self.damus_state?.pool.send(.event(new_ev)) + case .cancel: + active_sheet = nil + print("post cancelled") + } + } + .onReceive(timer) { n in + self.damus_state?.pool.connect_to_disconnected() + } + + + } func switch_timeline(_ timeline: Timeline) { @@ -460,7 +470,6 @@ struct ContentView_Previews: PreviewProvider { } } - func get_since_time(last_event: NostrEvent?) -> Int64? { if let last_event = last_event { return last_event.created_at - 60 * 10 diff --git a/damus/Views/ProfileName.swift b/damus/Views/ProfileName.swift index b7bba8f0..b48b3a38 100644 --- a/damus/Views/ProfileName.swift +++ b/damus/Views/ProfileName.swift @@ -137,7 +137,7 @@ struct EventProfileName: View { .padding([.trailing], 2) Text("@" + String(display_name ?? Profile.displayName(profile: profile, pubkey: pubkey))) - .foregroundColor(.gray) + .foregroundColor(Color("DamusMediumGrey")) .font(eventviewsize_to_font(size)) } else { Text(String(display_name ?? Profile.displayName(profile: profile, pubkey: pubkey))) diff --git a/damus/Views/SideMenuView.swift b/damus/Views/SideMenuView.swift index 51623889..1f044adf 100644 --- a/damus/Views/SideMenuView.swift +++ b/damus/Views/SideMenuView.swift @@ -11,13 +11,20 @@ struct SideMenuView: View { let damus_state: DamusState @Binding var isSidebarVisible: Bool + @State var confirm_logout: Bool = false + @StateObject var user_settings = UserSettingsStore() + + @Environment(\.colorScheme) var colorScheme + var sideBarWidth = UIScreen.main.bounds.size.width * 0.7 - var bgColor: Color = - Color(.init( - red: 52 / 255, - green: 70 / 255, - blue: 182 / 255, - alpha: 1)) + + func fillColor() -> Color { + colorScheme == .light ? Color("DamusWhite") : Color("DamusBlack") + } + + func textColor() -> Color { + colorScheme == .light ? Color("DamusBlack") : Color("DamusWhite") + } var body: some View { if isSidebarVisible { @@ -25,7 +32,7 @@ struct SideMenuView: View { GeometryReader { _ in EmptyView() } - .background(.black.opacity(0.6)) + .background(.gray.opacity(0.6)) .opacity(isSidebarVisible ? 1 : 0) .animation(.easeInOut.delay(0.2), value: isSidebarVisible) .onTapGesture { @@ -40,7 +47,7 @@ struct SideMenuView: View { var content: some View { HStack(alignment: .top) { ZStack(alignment: .top) { - Color("DamusBlack") + fillColor() VStack(alignment: .leading, spacing: 20) { let profile = damus_state.profiles.lookup(id: damus_state.pubkey) @@ -50,14 +57,16 @@ struct SideMenuView: View { } else { Image(systemName: "person.fill") } - if let display_name = profile?.display_name { - VStack(alignment: .leading) { + VStack(alignment: .leading) { + if let display_name = profile?.display_name { Text(display_name) - .foregroundColor(Color("DamusWhite")) - .font(.headline) - ProfileName(pubkey: damus_state.pubkey, profile: profile, prefix: "@", damus: damus_state, show_friend_confirmed: false) - .font(.callout) - .foregroundColor(.gray) + .foregroundColor(textColor()) + .font(.title) + } + if let name = profile?.name { + Text("@" + name) + .foregroundColor(Color("DamusMediumGrey")) + .font(.body) } } @@ -80,7 +89,7 @@ struct SideMenuView: View { .foregroundColor(.accentColor) } - NavigationLink(destination: ConfigView(state: damus_state)) { + NavigationLink(destination: ConfigView(state: damus_state).environmentObject(user_settings)) { Label("App Settings", systemImage: "xserve") .font(.title2) .foregroundColor(.accentColor) @@ -90,20 +99,30 @@ struct SideMenuView: View { Button(action: { //ConfigView(state: damus_state) - notify(.logout, ()) + confirm_logout = true }, label: { - Label("Sign out", systemImage: "exit") + Label("Sign out", systemImage: "pip.exit") .font(.title3) - .foregroundColor(Color("DamusWhite")) + .foregroundColor(textColor()) }) } .padding(.top, 50) .padding(.bottom, 50) - .padding(.horizontal, 20) + .padding(.leading, 40) } .frame(width: sideBarWidth) .offset(x: isSidebarVisible ? 0 : -sideBarWidth) .animation(.default, value: isSidebarVisible) + .alert("Logout", isPresented: $confirm_logout) { + Button("Cancel") { + confirm_logout = false + } + Button("Logout") { + notify(.logout, ()) + } + } message: { + Text("Make sure your nsec account key is saved before you logout or you will lose access to this account") + } Spacer() } diff --git a/damus/damusApp.swift b/damus/damusApp.swift index 72215085..be7056b1 100644 --- a/damus/damusApp.swift +++ b/damus/damusApp.swift @@ -14,10 +14,7 @@ struct damusApp: App { WindowGroup { MainView() } - } - - } struct MainView: View { From c6ca0a058e10a34190a1a2bf35407f27e5ddef08 Mon Sep 17 00:00:00 2001 From: Ben Weeks Date: Sat, 7 Jan 2023 22:13:44 +0000 Subject: [PATCH 03/12] Updated text color to white and swapped icons round --- damus/ContentView.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/damus/ContentView.swift b/damus/ContentView.swift index 2a5a08ac..b59c8814 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -213,11 +213,11 @@ struct ContentView: View { var body: some View { ZStack { if let damus = self.damus_state { - + VStack(alignment: .leading, spacing: 0) { NavigationView { - - SideMenuView(damus_state: damus, isSidebarVisible: $isSideBarOpened).zIndex(1) + + SideMenuView(damus_state: damus, isSidebarVisible: $isSideBarOpened) VStack(alignment: .leading, spacing: 0) { From 8161d55d053b1ca0567e3bfbc1c0abe250242fbb Mon Sep 17 00:00:00 2001 From: Ben Weeks Date: Sat, 7 Jan 2023 22:15:38 +0000 Subject: [PATCH 04/12] Updated colors and swapped icons. --- damus/Views/SideMenuView.swift | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/damus/Views/SideMenuView.swift b/damus/Views/SideMenuView.swift index 1f044adf..34472995 100644 --- a/damus/Views/SideMenuView.swift +++ b/damus/Views/SideMenuView.swift @@ -71,6 +71,7 @@ struct SideMenuView: View { } Divider() + .padding(.trailing,40) //NavigationView { let followers = FollowersModel(damus_state: damus_state, target: damus_state.pubkey) @@ -80,19 +81,19 @@ struct SideMenuView: View { ) { Label("Profile", systemImage: "person") .font(.title2) - .foregroundColor(.accentColor) + .foregroundColor(textColor()) } NavigationLink(destination: EmptyView()) { - Label("Relays", systemImage: "gear") + Label("Relays", systemImage: "xserve") .font(.title2) - .foregroundColor(.accentColor) + .foregroundColor(textColor()) } NavigationLink(destination: ConfigView(state: damus_state).environmentObject(user_settings)) { - Label("App Settings", systemImage: "xserve") + Label("App settings", systemImage: "gear") .font(.title2) - .foregroundColor(.accentColor) + .foregroundColor(textColor()) } Spacer() From 3bf39dc04b41dcd07803e707fa818ad0482309bd Mon Sep 17 00:00:00 2001 From: Ben Weeks Date: Sat, 7 Jan 2023 23:29:22 +0000 Subject: [PATCH 05/12] Fixed overlay issue (now has faded background) --- damus/ContentView.swift | 76 ++++++++++++++-------------------- damus/Views/SideMenuView.swift | 2 + 2 files changed, 33 insertions(+), 45 deletions(-) diff --git a/damus/ContentView.swift b/damus/ContentView.swift index 2fd57d9e..c48f33bf 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -205,50 +205,33 @@ struct ContentView: View { } var body: some View { - ZStack { + VStack(alignment: .leading, spacing: 0) { if let damus = self.damus_state { - - VStack(alignment: .leading, spacing: 0) { - NavigationView { - - SideMenuView(damus_state: damus, isSidebarVisible: $isSideBarOpened) - - VStack(alignment: .leading, spacing: 0) { - - MainContent(damus: damus) - .toolbar { + NavigationView { + ZStack { + MainContent(damus: damus) + .toolbar() { ToolbarItem(placement: .navigationBarLeading) { - let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!) - let followers_model = FollowersModel(damus_state: damus_state!, target: damus_state!.pubkey) - let prof_dest = ProfileView(damus_state: damus_state!, profile: profile_model, followers: followers_model) - - Button { - isSideBarOpened.toggle() - } label: { + let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!) let followers_model = FollowersModel(damus_state: damus_state!, target: damus_state!.pubkey) let prof_dest = ProfileView(damus_state: damus_state!, profile: profile_model, followers: followers_model) - if let picture = damus_state?.profiles.lookup(id: pubkey)?.picture { - ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles, picture: picture) - } else { - Image(systemName: "person.fill") + Button { + isSideBarOpened.toggle() + } label: { + let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!) + let followers_model = FollowersModel(damus_state: damus_state!, target: damus_state!.pubkey) + let prof_dest = ProfileView(damus_state: damus_state!, profile: profile_model, followers: followers_model) + + if let picture = damus_state?.profiles.lookup(id: pubkey)?.picture { + ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles, picture: picture) + } else { + Image(systemName: "person.fill") + } } } - - NavigationLink(destination: prof_dest) { - /// Verify that the user has a profile picture, if not display a generic SF Symbol - /// (Resolves an in-app error where ``Robohash`` pictures are not generated so the button dissapears - if let picture = damus_state?.profiles.lookup(id: pubkey)?.picture { - ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles, picture: picture) - } else { - Image(systemName: "person.fill") - } - } - .buttonStyle(PlainButtonStyle()) - - } - + ToolbarItem(placement: .navigationBarTrailing) { HStack(alignment: .center) { if home.signal.signal != home.signal.max_signal { @@ -265,13 +248,19 @@ struct ContentView: View { */ } } - } - } - }.navigationViewStyle(.stack) - - TabBar(new_events: $home.new_events, selected: $selected_timeline, action: switch_timeline) - .padding([.bottom], 8) + } + + Color.clear + .overlay( + SideMenuView(damus_state: damus, isSidebarVisible: $isSideBarOpened) + ) + } + .navigationBarHidden(isSideBarOpened ? true: false) // Would prefer a different way of doing this. } + .navigationViewStyle(.stack) + + TabBar(new_events: $home.new_events, selected: $selected_timeline, action: switch_timeline) + .padding([.bottom], 8) } } .onAppear() { @@ -403,9 +392,6 @@ struct ContentView: View { .onReceive(timer) { n in self.damus_state?.pool.connect_to_disconnected() } - - - } func switch_timeline(_ timeline: Timeline) { diff --git a/damus/Views/SideMenuView.swift b/damus/Views/SideMenuView.swift index 34472995..1088b685 100644 --- a/damus/Views/SideMenuView.swift +++ b/damus/Views/SideMenuView.swift @@ -84,11 +84,13 @@ struct SideMenuView: View { .foregroundColor(textColor()) } + /* NavigationLink(destination: EmptyView()) { Label("Relays", systemImage: "xserve") .font(.title2) .foregroundColor(textColor()) } + */ NavigationLink(destination: ConfigView(state: damus_state).environmentObject(user_settings)) { Label("App settings", systemImage: "gear") From 392281ca40792333464dbff0ef1ff0ecfeabf62f Mon Sep 17 00:00:00 2001 From: Ben Weeks Date: Sat, 7 Jan 2023 23:33:57 +0000 Subject: [PATCH 06/12] Removed unnecessary code. --- damus/ContentView.swift | 42 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/damus/ContentView.swift b/damus/ContentView.swift index c48f33bf..9aaaf0b8 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -211,42 +211,22 @@ struct ContentView: View { ZStack { MainContent(damus: damus) .toolbar() { - ToolbarItem(placement: .navigationBarLeading) { + ToolbarItem(placement: .navigationBarLeading) { + let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!) + let followers_model = FollowersModel(damus_state: damus_state!, target: damus_state!.pubkey) + Button { + isSideBarOpened.toggle() + } label: { let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!) let followers_model = FollowersModel(damus_state: damus_state!, target: damus_state!.pubkey) - let prof_dest = ProfileView(damus_state: damus_state!, profile: profile_model, followers: followers_model) - - Button { - isSideBarOpened.toggle() - } label: { - let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!) - let followers_model = FollowersModel(damus_state: damus_state!, target: damus_state!.pubkey) - let prof_dest = ProfileView(damus_state: damus_state!, profile: profile_model, followers: followers_model) - - if let picture = damus_state?.profiles.lookup(id: pubkey)?.picture { - ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles, picture: picture) - } else { - Image(systemName: "person.fill") - } + + if let picture = damus_state?.profiles.lookup(id: pubkey)?.picture { + ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles, picture: picture) + } else { + Image(systemName: "person.fill") } } - - ToolbarItem(placement: .navigationBarTrailing) { - HStack(alignment: .center) { - if home.signal.signal != home.signal.max_signal { - Text("\(home.signal.signal)/\(home.signal.max_signal)") - .font(.callout) - .foregroundColor(.gray) - } - - /* - NavigationLink(destination: ConfigView(state: damus_state!).environmentObject(user_settings)) { - Label("", systemImage: "gear") - } - .buttonStyle(PlainButtonStyle()) - */ - } } } From 4378397c4ca1cdbb9f7a57a55aebe02f9fc42d60 Mon Sep 17 00:00:00 2001 From: Ben Weeks Date: Sat, 7 Jan 2023 23:59:35 +0000 Subject: [PATCH 07/12] Fixed animation. Made menu a touch smaller. --- damus/Views/SideMenuView.swift | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/damus/Views/SideMenuView.swift b/damus/Views/SideMenuView.swift index 1088b685..5df84e9f 100644 --- a/damus/Views/SideMenuView.swift +++ b/damus/Views/SideMenuView.swift @@ -16,7 +16,7 @@ struct SideMenuView: View { @Environment(\.colorScheme) var colorScheme - var sideBarWidth = UIScreen.main.bounds.size.width * 0.7 + var sideBarWidth = UIScreen.main.bounds.size.width * 0.65 func fillColor() -> Color { colorScheme == .light ? Color("DamusWhite") : Color("DamusBlack") @@ -27,21 +27,20 @@ struct SideMenuView: View { } var body: some View { - if isSidebarVisible { - ZStack { - GeometryReader { _ in - EmptyView() - } - .background(.gray.opacity(0.6)) - .opacity(isSidebarVisible ? 1 : 0) - .animation(.easeInOut.delay(0.2), value: isSidebarVisible) - .onTapGesture { - isSidebarVisible.toggle() - } - content + ZStack { + GeometryReader { _ in + EmptyView() } - .edgesIgnoringSafeArea(.all) + .background(.gray.opacity(0.6)) + .opacity(isSidebarVisible ? 1 : 0) + .animation(.easeInOut.delay(0.2), value: isSidebarVisible) + .onTapGesture { + isSidebarVisible.toggle() + } + content } + .edgesIgnoringSafeArea(.all) + } var content: some View { @@ -109,8 +108,8 @@ struct SideMenuView: View { .foregroundColor(textColor()) }) } - .padding(.top, 50) - .padding(.bottom, 50) + .padding(.top, 60) + .padding(.bottom, 40) .padding(.leading, 40) } .frame(width: sideBarWidth) From 9b236f95837321963fd2cf558040f6fec1e2ff95 Mon Sep 17 00:00:00 2001 From: Ben Weeks Date: Sun, 8 Jan 2023 00:20:43 +0000 Subject: [PATCH 08/12] Changed opacity to Damus on-brand grey. Removed unnecessary code. --- damus/ContentView.swift | 1 - damus/Views/SideMenuView.swift | 14 +++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/damus/ContentView.swift b/damus/ContentView.swift index 9aaaf0b8..2267656c 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -212,7 +212,6 @@ struct ContentView: View { MainContent(damus: damus) .toolbar() { ToolbarItem(placement: .navigationBarLeading) { - let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!) let followers_model = FollowersModel(damus_state: damus_state!, target: damus_state!.pubkey) Button { diff --git a/damus/Views/SideMenuView.swift b/damus/Views/SideMenuView.swift index 5df84e9f..a3215bcc 100644 --- a/damus/Views/SideMenuView.swift +++ b/damus/Views/SideMenuView.swift @@ -31,7 +31,7 @@ struct SideMenuView: View { GeometryReader { _ in EmptyView() } - .background(.gray.opacity(0.6)) + .background(Color("DamusDarkGrey").opacity(0.6)) .opacity(isSidebarVisible ? 1 : 0) .animation(.easeInOut.delay(0.2), value: isSidebarVisible) .onTapGesture { @@ -82,6 +82,9 @@ struct SideMenuView: View { .font(.title2) .foregroundColor(textColor()) } + .simultaneousGesture(TapGesture().onEnded { + isSidebarVisible = false + }) /* NavigationLink(destination: EmptyView()) { @@ -89,6 +92,9 @@ struct SideMenuView: View { .font(.title2) .foregroundColor(textColor()) } + .simultaneousGesture(TapGesture().onEnded { + isSidebarVisible.toggle() + }) */ NavigationLink(destination: ConfigView(state: damus_state).environmentObject(user_settings)) { @@ -96,6 +102,9 @@ struct SideMenuView: View { .font(.title2) .foregroundColor(textColor()) } + .simultaneousGesture(TapGesture().onEnded { + isSidebarVisible = false + }) Spacer() @@ -115,6 +124,9 @@ struct SideMenuView: View { .frame(width: sideBarWidth) .offset(x: isSidebarVisible ? 0 : -sideBarWidth) .animation(.default, value: isSidebarVisible) + .onTapGesture { + isSidebarVisible.toggle() + } .alert("Logout", isPresented: $confirm_logout) { Button("Cancel") { confirm_logout = false From 38211a74f5bb5a7da8a73144db50398cb45cd0e3 Mon Sep 17 00:00:00 2001 From: Ben Weeks Date: Sun, 8 Jan 2023 00:26:35 +0000 Subject: [PATCH 09/12] Moved the sidebar to above the tab buttons. --- damus/ContentView.swift | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/damus/ContentView.swift b/damus/ContentView.swift index 2267656c..039e1c9d 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -209,9 +209,10 @@ struct ContentView: View { if let damus = self.damus_state { NavigationView { ZStack { - MainContent(damus: damus) - .toolbar() { - ToolbarItem(placement: .navigationBarLeading) { + VStack { + MainContent(damus: damus) + .toolbar() { + ToolbarItem(placement: .navigationBarLeading) { let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!) let followers_model = FollowersModel(damus_state: damus_state!, target: damus_state!.pubkey) Button { @@ -219,7 +220,7 @@ struct ContentView: View { } label: { let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!) let followers_model = FollowersModel(damus_state: damus_state!, target: damus_state!.pubkey) - + if let picture = damus_state?.profiles.lookup(id: pubkey)?.picture { ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles, picture: picture) } else { @@ -227,7 +228,12 @@ struct ContentView: View { } } } - } + } + + TabBar(new_events: $home.new_events, selected: $selected_timeline, action: switch_timeline) + .padding([.bottom], 8) + + } Color.clear .overlay( @@ -238,8 +244,7 @@ struct ContentView: View { } .navigationViewStyle(.stack) - TabBar(new_events: $home.new_events, selected: $selected_timeline, action: switch_timeline) - .padding([.bottom], 8) + } } .onAppear() { From fac1911524d50b662db0f081e0590615d3e9ba24 Mon Sep 17 00:00:00 2001 From: Ben Weeks Date: Sun, 8 Jan 2023 00:38:02 +0000 Subject: [PATCH 10/12] Undid change to navigation appearing above the tabView as unfortunately has consequence hadn't spotted of the tab view dropping from profile page and settings page. --- damus/ContentView.swift | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/damus/ContentView.swift b/damus/ContentView.swift index 039e1c9d..039c3711 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -229,10 +229,6 @@ struct ContentView: View { } } } - - TabBar(new_events: $home.new_events, selected: $selected_timeline, action: switch_timeline) - .padding([.bottom], 8) - } Color.clear @@ -243,8 +239,9 @@ struct ContentView: View { .navigationBarHidden(isSideBarOpened ? true: false) // Would prefer a different way of doing this. } .navigationViewStyle(.stack) - - + + TabBar(new_events: $home.new_events, selected: $selected_timeline, action: switch_timeline) + .padding([.bottom], 8) } } .onAppear() { From cb54ac0494cf722341da742149d6c37d8d2a2664 Mon Sep 17 00:00:00 2001 From: Ben Weeks Date: Sun, 8 Jan 2023 01:00:35 +0000 Subject: [PATCH 11/12] Updated sidebar to close when tab items at the bottom are clicked too. --- damus/ContentView.swift | 3 +-- damus/Views/MainTabView.swift | 12 +++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/damus/ContentView.swift b/damus/ContentView.swift index 039c3711..43ec7943 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -240,7 +240,7 @@ struct ContentView: View { } .navigationViewStyle(.stack) - TabBar(new_events: $home.new_events, selected: $selected_timeline, action: switch_timeline) + TabBar(new_events: $home.new_events, selected: $selected_timeline, isSidebarVisible: $isSideBarOpened, action: switch_timeline) .padding([.bottom], 8) } } @@ -283,7 +283,6 @@ struct ContentView: View { guard let privkey = self.privkey else { return } - let ev = notif.object as! NostrEvent let boost = make_boost_event(pubkey: pubkey, privkey: privkey, boosted: ev) self.damus_state?.pool.send(.event(boost)) diff --git a/damus/Views/MainTabView.swift b/damus/Views/MainTabView.swift index e7666052..3bd72d1e 100644 --- a/damus/Views/MainTabView.swift +++ b/damus/Views/MainTabView.swift @@ -31,9 +31,9 @@ func timeline_bit(_ timeline: Timeline) -> Int { struct TabButton: View { let timeline: Timeline let img: String - @Binding var selected: Timeline? @Binding var new_events: NewEventsBits + @Binding var isSidebarVisible: Bool let action: (Timeline) -> () @@ -56,6 +56,7 @@ struct TabButton: View { Button(action: { action(timeline) new_events = NewEventsBits(prev: new_events, unsetting: timeline) + isSidebarVisible = false }) { Label("", systemImage: selected == timeline ? "\(img).fill" : img) .contentShape(Rectangle()) @@ -69,6 +70,7 @@ struct TabButton: View { struct TabBar: View { @Binding var new_events: NewEventsBits @Binding var selected: Timeline? + @Binding var isSidebarVisible: Bool let action: (Timeline) -> () @@ -76,10 +78,10 @@ struct TabBar: View { VStack { Divider() HStack { - TabButton(timeline: .home, img: "house", selected: $selected, new_events: $new_events, action: action).keyboardShortcut("1") - TabButton(timeline: .dms, img: "bubble.left.and.bubble.right", selected: $selected, new_events: $new_events, action: action).keyboardShortcut("2") - TabButton(timeline: .search, img: "magnifyingglass.circle", selected: $selected, new_events: $new_events, action: action).keyboardShortcut("3") - TabButton(timeline: .notifications, img: "bell", selected: $selected, new_events: $new_events, action: action).keyboardShortcut("4") + TabButton(timeline: .home, img: "house", selected: $selected, new_events: $new_events, isSidebarVisible: $isSidebarVisible, action: action).keyboardShortcut("1") + TabButton(timeline: .dms, img: "bubble.left.and.bubble.right", selected: $selected, new_events: $new_events, isSidebarVisible: $isSidebarVisible, action: action).keyboardShortcut("2") + TabButton(timeline: .search, img: "magnifyingglass.circle", selected: $selected, new_events: $new_events, isSidebarVisible: $isSidebarVisible, action: action).keyboardShortcut("3") + TabButton(timeline: .notifications, img: "bell", selected: $selected, new_events: $new_events, isSidebarVisible: $isSidebarVisible, action: action).keyboardShortcut("4") } } } From 966f330317ba4d5987288dd32891c725044654fe Mon Sep 17 00:00:00 2001 From: Ben Weeks Date: Sun, 8 Jan 2023 23:32:35 +0000 Subject: [PATCH 12/12] Added hidden dummy code for future options. --- damus/Views/SideMenuView.swift | 39 ++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/damus/Views/SideMenuView.swift b/damus/Views/SideMenuView.swift index a3215bcc..5da58ea5 100644 --- a/damus/Views/SideMenuView.swift +++ b/damus/Views/SideMenuView.swift @@ -72,12 +72,26 @@ struct SideMenuView: View { Divider() .padding(.trailing,40) - //NavigationView { + /* + HStack(alignment: .bottom) { + Text("69,420") + .foregroundColor(.accentColor) + .font(.largeTitle) + Text("SATS") + .font(.caption) + .padding(.bottom,6) + } + + Divider() + .padding(.trailing,40) + */ + + // THERE IS A LIMIT OF 10 NAVIGATIONLINKS!!! (Consider some in other views) + let followers = FollowersModel(damus_state: damus_state, target: damus_state.pubkey) let profile_model = ProfileModel(pubkey: damus_state.pubkey, damus: damus_state) - - NavigationLink(destination: ProfileView(damus_state: damus_state, profile: profile_model, followers: followers) - ) { + + NavigationLink(destination: ProfileView(damus_state: damus_state, profile: profile_model, followers: followers)) { Label("Profile", systemImage: "person") .font(.title2) .foregroundColor(textColor()) @@ -92,11 +106,22 @@ struct SideMenuView: View { .font(.title2) .foregroundColor(textColor()) } - .simultaneousGesture(TapGesture().onEnded { - isSidebarVisible.toggle() - }) + .simultaneousGesture(TapGesture().onEnded { + isSidebarVisible.toggle() + }) */ + /* + NavigationLink(destination: EmptyView()) { + Label("Wallet", systemImage: "bolt") + .font(.title2) + .foregroundColor(textColor()) + } + .simultaneousGesture(TapGesture().onEnded { + isSidebarVisible.toggle() + }) + */ + NavigationLink(destination: ConfigView(state: damus_state).environmentObject(user_settings)) { Label("App settings", systemImage: "gear") .font(.title2)