damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | LICENSE

commit 300463ef5516e93f54b0bf1f8b1bee18694c8727
parent 8369b05c100da60a5dabd1e507c29515efab99c3
Author: William Casarin <jb55@jb55.com>
Date:   Sun,  8 May 2022 19:31:25 -0700

break profile view so that I fix it

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/Views/ChatView.swift | 33+++++++++------------------------
Mdamus/Views/EventView.swift | 3++-
Mdamus/Views/ProfilePicView.swift | 9+++++++--
Mdamus/Views/ProfileView.swift | 63++++++++++++++++++++++++++-------------------------------------
Mdamus/Views/ReplyQuoteView.swift | 3++-
Mdamus/Views/TimelineView.swift | 49+++++++++++++++++++++++++------------------------
6 files changed, 71 insertions(+), 89 deletions(-)

diff --git a/damus/Views/ChatView.swift b/damus/Views/ChatView.swift @@ -81,37 +81,22 @@ struct ChatView: View { @Environment(\.colorScheme) var colorScheme var body: some View { - let profile = profiles.lookup(id: event.pubkey) HStack { - //ZStack { - //Rectangle() - //.foregroundColor(Color.gray) - //.frame(width: 2) - - VStack { - if is_active || just_started { - ProfilePicView(picture: profile?.picture, size: 32, highlight: is_active ? .main : .none, image_cache: damus.image_cache) - } - /* - if just_started { - ProfilePicView(picture: profile?.picture, size: 32, highlight: thread.event.id == event.id ? .main : .none) - } else { - Text("\(format_relative_time(event.created_at))") - .font(.footnote) - .foregroundColor(.gray.opacity(0.5)) - } - */ - - Spacer() + VStack { + if is_active || just_started { + ProfilePicView(pubkey: event.pubkey, size: 32, highlight: is_active ? .main : .none, image_cache: damus.image_cache) + .environmentObject(profiles) } - .frame(maxWidth: 32) - //} + + Spacer() + } + .frame(maxWidth: 32) Group { VStack(alignment: .leading) { if just_started { HStack { - ProfileName(pubkey: event.pubkey, profile: profile) + ProfileName(pubkey: event.pubkey, profile: profiles.lookup(id: event.pubkey)) .foregroundColor(colorScheme == .dark ? id_to_color(event.pubkey) : Color.black) //.shadow(color: Color.black, radius: 2) Text("\(format_relative_time(event.created_at))") diff --git a/damus/Views/EventView.swift b/damus/Views/EventView.swift @@ -53,7 +53,8 @@ struct EventView: View { .environmentObject(profiles) NavigationLink(destination: pv) { - ProfilePicView(picture: profile?.picture, size: PFP_SIZE!, highlight: highlight, image_cache: damus.image_cache) + ProfilePicView(pubkey: event.pubkey, size: PFP_SIZE!, highlight: highlight, image_cache: damus.image_cache) + .environmentObject(profiles) } Spacer() diff --git a/damus/Views/ProfilePicView.swift b/damus/Views/ProfilePicView.swift @@ -33,7 +33,7 @@ func pfp_line_width(_ h: Highlight) -> CGFloat { } struct ProfilePicView: View { - let picture: String? + let pubkey: String let size: CGFloat let highlight: Highlight let image_cache: ImageCache @@ -42,8 +42,12 @@ struct ProfilePicView: View { @EnvironmentObject var profiles: Profiles + var PlaceholderColor: Color { + return id_to_color(pubkey) + } + var Placeholder: some View { - Color.purple.opacity(0.2) + PlaceholderColor.opacity(0.5) .frame(width: size, height: size) .cornerRadius(CORNER_RADIUS) .overlay(Circle().stroke(highlight_color(highlight), lineWidth: pfp_line_width(highlight))) @@ -72,6 +76,7 @@ struct ProfilePicView: View { var MainContent: some View { Group { + let picture = profiles.lookup(id: pubkey)?.picture if let pic_url = picture.flatMap { URL(string: $0) } { ProfilePic(pic_url) } else { diff --git a/damus/Views/ProfileView.swift b/damus/Views/ProfileView.swift @@ -22,55 +22,44 @@ struct ProfileView: View { @EnvironmentObject var profiles: Profiles var TopSection: some View { - HStack(alignment: .top) { + VStack{ let data = profiles.lookup(id: profile.pubkey) - ProfilePicView(picture: data?.picture, size: PFP_SIZE!, highlight: .custom(Color.black, 4), image_cache: damus.image_cache) - //.border(Color.blue) - VStack(alignment: .leading) { - if let pubkey = profile.pubkey { - ProfileName(pubkey: pubkey, profile: data) - .font(.title) - //.border(Color.green) - Text("\(pubkey)") - .textSelection(.enabled) - .font(.footnote) - .foregroundColor(id_to_color(pubkey)) + HStack { + ProfilePicView(pubkey: profile.pubkey, size: PFP_SIZE!, highlight: .custom(Color.black, 2), image_cache: damus.image_cache) + .environmentObject(profiles) + + Spacer() + + Button("Follow") { + print("follow \(profile.pubkey)") } - Text(data?.about ?? "") - //.border(Color.red) } - //.border(Color.purple) - //Spacer() + + if let pubkey = profile.pubkey { + ProfileName(pubkey: pubkey, profile: data) + .font(.title) + //.border(Color.green) + Text("\(pubkey)") + .textSelection(.enabled) + .font(.footnote) + .foregroundColor(id_to_color(pubkey)) + } + Text(data?.about ?? "") } - //.border(Color.indigo) } var body: some View { VStack(alignment: .leading) { - TopSection - /* - Picker("", selection: $selected_tab) { - Text("Posts").tag(ProfileTab.posts) - Text("Following").tag(ProfileTab.following) - } - .pickerStyle(SegmentedPickerStyle()) - */ - + ScrollView { + TopSection - Divider() - - Group { - switch(selected_tab) { - case .posts: - TimelineView(events: $profile.events, damus: damus) - .environmentObject(profiles) - case .following: - Text("Following") - } + Divider() + + InnerTimelineView(events: $profile.events, damus: damus) + .environmentObject(profiles) } .frame(maxHeight: .infinity, alignment: .topLeading) } - //.border(Color.white) .padding([.leading, .trailing], 6) .frame(maxWidth: .infinity, alignment: .topLeading) diff --git a/damus/Views/ReplyQuoteView.swift b/damus/Views/ReplyQuoteView.swift @@ -23,7 +23,8 @@ struct ReplyQuoteView: View { VStack(alignment: .leading) { HStack(alignment: .top) { - ProfilePicView(picture: profiles.lookup(id: event.pubkey)?.picture, size: 16, highlight: .reply, image_cache: image_cache) + ProfilePicView(pubkey: event.pubkey, size: 16, highlight: .reply, image_cache: image_cache) + .environmentObject(profiles) Text(Profile.displayName(profile: profiles.lookup(id: event.pubkey), pubkey: event.pubkey)) .foregroundColor(.accentColor) Text("\(format_relative_time(event.created_at))") diff --git a/damus/Views/TimelineView.swift b/damus/Views/TimelineView.swift @@ -12,6 +12,27 @@ enum TimelineAction { case navigating } +struct InnerTimelineView: View { + @Binding var events: [NostrEvent] + @EnvironmentObject var profiles: Profiles + let damus: DamusState + + var body: some View { + LazyVStack { + ForEach(events, id: \.id) { (ev: NostrEvent) in + let tv = ThreadView(thread: ThreadModel(event: ev, pool: damus.pool), damus: damus) + .environmentObject(profiles) + + NavigationLink(destination: tv) { + EventView(event: ev, highlight: .none, has_action_bar: true, damus: damus) + } + .isDetailLink(true) + .buttonStyle(PlainButtonStyle()) + } + } + } +} + struct TimelineView: View { @Binding var events: [NostrEvent] @@ -21,35 +42,15 @@ struct TimelineView: View { var body: some View { MainContent - .padding([.leading, .trailing], 6) - .environmentObject(profiles) + .padding([.leading, .trailing], 6) + .environmentObject(profiles) } var MainContent: some View { ScrollViewReader { scroller in ScrollView { - LazyVStack { - ForEach(events, id: \.id) { (ev: NostrEvent) in - /* - let evdet = EventDetailView(thread: ThreadModel(event: ev, pool: pool)) - .navigationBarTitle("Thread") - .padding([.leading, .trailing], 6) - .environmentObject(profiles) - */ - - let tv = ThreadView(thread: ThreadModel(event: ev, pool: damus.pool), damus: damus) - .environmentObject(profiles) - - NavigationLink(destination: tv) { - EventView(event: ev, highlight: .none, has_action_bar: true, damus: damus) - } - .isDetailLink(true) - .buttonStyle(PlainButtonStyle()) - //.onTapGesture { - //NotificationCenter.default.post(name: .open_thread, object: ev) - //} - } - } + InnerTimelineView(events: $events, damus: damus) + .environmentObject(profiles) } .onReceive(NotificationCenter.default.publisher(for: .scroll_to_top)) { _ in guard let event = events.first else {