Worked on amending the colors.

This commit is contained in:
Ben Weeks
2023-01-06 22:41:48 +00:00
parent 5733f782d9
commit fba29d4454
4 changed files with 219 additions and 194 deletions

View File

@@ -211,197 +211,207 @@ struct ContentView: View {
} }
var body: some View { var body: some View {
//ZStack { ZStack {
if let damus = self.damus_state {
VStack(alignment: .leading, spacing: 0) { VStack(alignment: .leading, spacing: 0) {
if let damus = self.damus_state {
NavigationView { NavigationView {
SideMenuView(damus_state: damus_state!, isSidebarVisible: $isSideBarOpened)
MainContent(damus: damus) SideMenuView(damus_state: damus, isSidebarVisible: $isSideBarOpened).zIndex(1)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) { VStack(alignment: .leading, spacing: 0) {
let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!)
let followers_model = FollowersModel(damus_state: damus_state!, target: damus_state!.pubkey) MainContent(damus: damus)
let prof_dest = ProfileView(damus_state: damus_state!, profile: profile_model, followers: followers_model) .toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button {
isSideBarOpened.toggle()
} label: {
let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!) let profile_model = ProfileModel(pubkey: damus_state!.pubkey, damus: damus_state!)
let followers_model = FollowersModel(damus_state: damus_state!, target: damus_state!.pubkey) 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) let prof_dest = ProfileView(damus_state: damus_state!, profile: profile_model, followers: followers_model)
if let picture = damus_state?.profiles.lookup(id: pubkey)?.picture { Button {
ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles, picture: picture) isSideBarOpened.toggle()
} else { } label: {
Image(systemName: "person.fill") 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) { if let picture = damus_state?.profiles.lookup(id: pubkey)?.picture {
/// Verify that the user has a profile picture, if not display a generic SF Symbol ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles, picture: picture)
/// (Resolves an in-app error where ``Robohash`` pictures are not generated so the button dissapears } else {
if let picture = damus_state?.profiles.lookup(id: pubkey)?.picture { Image(systemName: "person.fill")
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)) { NavigationLink(destination: prof_dest) {
Label("", systemImage: "gear") /// 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()) .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 TabBar(new_events: $home.new_events, selected: $selected_timeline, action: switch_timeline)
damus.contacts.remove_friend(pk) .padding([.bottom], 8)
//friend_events = friend_events.filter { $0.pubkey != pk }
} }
} }
.onReceive(handle_notify(.follow)) { notif in }
guard let privkey = self.privkey else { .onAppear() {
return 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 damus.contacts.event = ev
guard let damus = self.damus_state else { damus.contacts.remove_friend(pk)
return //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, damus_state?.contacts.event = ev
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 fnotify {
switch post_res { case .pubkey(let pk):
case .post(let post): damus.contacts.add_friend_pubkey(pk)
print("post \(post.content)") case .contact(let ev):
let new_ev = post_to_event(post: post, privkey: privkey, pubkey: pubkey) damus.contacts.add_friend_contact(ev)
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() .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) { func switch_timeline(_ timeline: Timeline) {
@@ -460,7 +470,6 @@ struct ContentView_Previews: PreviewProvider {
} }
} }
func get_since_time(last_event: NostrEvent?) -> Int64? { func get_since_time(last_event: NostrEvent?) -> Int64? {
if let last_event = last_event { if let last_event = last_event {
return last_event.created_at - 60 * 10 return last_event.created_at - 60 * 10

View File

@@ -137,7 +137,7 @@ struct EventProfileName: View {
.padding([.trailing], 2) .padding([.trailing], 2)
Text("@" + String(display_name ?? Profile.displayName(profile: profile, pubkey: pubkey))) Text("@" + String(display_name ?? Profile.displayName(profile: profile, pubkey: pubkey)))
.foregroundColor(.gray) .foregroundColor(Color("DamusMediumGrey"))
.font(eventviewsize_to_font(size)) .font(eventviewsize_to_font(size))
} else { } else {
Text(String(display_name ?? Profile.displayName(profile: profile, pubkey: pubkey))) Text(String(display_name ?? Profile.displayName(profile: profile, pubkey: pubkey)))

View File

@@ -11,13 +11,20 @@ struct SideMenuView: View {
let damus_state: DamusState let damus_state: DamusState
@Binding var isSidebarVisible: Bool @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 sideBarWidth = UIScreen.main.bounds.size.width * 0.7
var bgColor: Color =
Color(.init( func fillColor() -> Color {
red: 52 / 255, colorScheme == .light ? Color("DamusWhite") : Color("DamusBlack")
green: 70 / 255, }
blue: 182 / 255,
alpha: 1)) func textColor() -> Color {
colorScheme == .light ? Color("DamusBlack") : Color("DamusWhite")
}
var body: some View { var body: some View {
if isSidebarVisible { if isSidebarVisible {
@@ -25,7 +32,7 @@ struct SideMenuView: View {
GeometryReader { _ in GeometryReader { _ in
EmptyView() EmptyView()
} }
.background(.black.opacity(0.6)) .background(.gray.opacity(0.6))
.opacity(isSidebarVisible ? 1 : 0) .opacity(isSidebarVisible ? 1 : 0)
.animation(.easeInOut.delay(0.2), value: isSidebarVisible) .animation(.easeInOut.delay(0.2), value: isSidebarVisible)
.onTapGesture { .onTapGesture {
@@ -40,7 +47,7 @@ struct SideMenuView: View {
var content: some View { var content: some View {
HStack(alignment: .top) { HStack(alignment: .top) {
ZStack(alignment: .top) { ZStack(alignment: .top) {
Color("DamusBlack") fillColor()
VStack(alignment: .leading, spacing: 20) { VStack(alignment: .leading, spacing: 20) {
let profile = damus_state.profiles.lookup(id: damus_state.pubkey) let profile = damus_state.profiles.lookup(id: damus_state.pubkey)
@@ -50,14 +57,16 @@ struct SideMenuView: View {
} else { } else {
Image(systemName: "person.fill") 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) Text(display_name)
.foregroundColor(Color("DamusWhite")) .foregroundColor(textColor())
.font(.headline) .font(.title)
ProfileName(pubkey: damus_state.pubkey, profile: profile, prefix: "@", damus: damus_state, show_friend_confirmed: false) }
.font(.callout) if let name = profile?.name {
.foregroundColor(.gray) Text("@" + name)
.foregroundColor(Color("DamusMediumGrey"))
.font(.body)
} }
} }
@@ -80,7 +89,7 @@ struct SideMenuView: View {
.foregroundColor(.accentColor) .foregroundColor(.accentColor)
} }
NavigationLink(destination: ConfigView(state: damus_state)) { NavigationLink(destination: ConfigView(state: damus_state).environmentObject(user_settings)) {
Label("App Settings", systemImage: "xserve") Label("App Settings", systemImage: "xserve")
.font(.title2) .font(.title2)
.foregroundColor(.accentColor) .foregroundColor(.accentColor)
@@ -90,20 +99,30 @@ struct SideMenuView: View {
Button(action: { Button(action: {
//ConfigView(state: damus_state) //ConfigView(state: damus_state)
notify(.logout, ()) confirm_logout = true
}, label: { }, label: {
Label("Sign out", systemImage: "exit") Label("Sign out", systemImage: "pip.exit")
.font(.title3) .font(.title3)
.foregroundColor(Color("DamusWhite")) .foregroundColor(textColor())
}) })
} }
.padding(.top, 50) .padding(.top, 50)
.padding(.bottom, 50) .padding(.bottom, 50)
.padding(.horizontal, 20) .padding(.leading, 40)
} }
.frame(width: sideBarWidth) .frame(width: sideBarWidth)
.offset(x: isSidebarVisible ? 0 : -sideBarWidth) .offset(x: isSidebarVisible ? 0 : -sideBarWidth)
.animation(.default, value: isSidebarVisible) .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() Spacer()
} }

View File

@@ -14,10 +14,7 @@ struct damusApp: App {
WindowGroup { WindowGroup {
MainView() MainView()
} }
} }
} }
struct MainView: View { struct MainView: View {