@@ -40,10 +40,7 @@ struct ChatView: View {
|
||||
}
|
||||
|
||||
var is_active: Bool {
|
||||
guard let ev = thread.event else {
|
||||
return false
|
||||
}
|
||||
return ev.id == event.id
|
||||
return thread.event.id == event.id
|
||||
}
|
||||
|
||||
func prev_reply_is_same() -> String? {
|
||||
|
||||
@@ -22,7 +22,7 @@ struct ChatroomView: View {
|
||||
next_ev: ind == count-1 ? nil : thread.events[ind+1]
|
||||
)
|
||||
.onTapGesture {
|
||||
if thread.event!.id == ev.id {
|
||||
if thread.event.id == ev.id {
|
||||
//dismiss()
|
||||
toggle_thread_view()
|
||||
} else {
|
||||
@@ -35,13 +35,13 @@ struct ChatroomView: View {
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: .select_quote)) { notif in
|
||||
let ev = notif.object as! NostrEvent
|
||||
if ev.id != thread.event!.id {
|
||||
if ev.id != thread.event.id {
|
||||
thread.set_active_event(ev)
|
||||
}
|
||||
scroll_to_event(scroller: scroller, id: ev.id, delay: 0, animate: true, anchor: .top)
|
||||
}
|
||||
.onAppear() {
|
||||
scroll_to_event(scroller: scroller, id: thread.event!.id, delay: 0.3, animate: true, anchor: .bottom)
|
||||
scroll_to_event(scroller: scroller, id: thread.event.id, delay: 0.3, animate: true, anchor: .bottom)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,10 @@ enum ActionBarSheet: Identifiable {
|
||||
|
||||
struct EventActionBar: View {
|
||||
let event: NostrEvent
|
||||
|
||||
@State var sheet: ActionBarSheet? = nil
|
||||
@EnvironmentObject var profiles: Profiles
|
||||
|
||||
@StateObject var bar: ActionBarModel = ActionBarModel()
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
/*
|
||||
@@ -33,13 +33,26 @@ struct EventActionBar: View {
|
||||
Spacer()
|
||||
|
||||
*/
|
||||
EventActionButton(img: "bubble.left") {
|
||||
EventActionButton(img: "bubble.left", col: nil) {
|
||||
notify(.reply, event)
|
||||
}
|
||||
.padding([.trailing], 40)
|
||||
|
||||
EventActionButton(img: "arrow.2.squarepath") {
|
||||
notify(.boost, event)
|
||||
EventActionButton(img: bar.liked ? "heart.fill" : "heart", col: bar.liked ? Color.red : nil) {
|
||||
if bar.liked {
|
||||
notify(.delete, bar.our_like_event)
|
||||
} else {
|
||||
notify(.like, event)
|
||||
}
|
||||
}
|
||||
.padding([.trailing], 40)
|
||||
|
||||
EventActionButton(img: "arrow.2.squarepath", col: bar.boosted ? Color.green : nil) {
|
||||
if bar.boosted {
|
||||
notify(.delete, bar.our_boost_event)
|
||||
} else {
|
||||
notify(.boost, event)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -47,11 +60,11 @@ struct EventActionBar: View {
|
||||
}
|
||||
|
||||
|
||||
func EventActionButton(img: String, action: @escaping () -> ()) -> some View {
|
||||
func EventActionButton(img: String, col: Color?, action: @escaping () -> ()) -> some View {
|
||||
Button(action: action) {
|
||||
Label("", systemImage: img)
|
||||
.font(.footnote)
|
||||
.foregroundColor(.gray)
|
||||
.foregroundColor(col == nil ? Color.gray : col!)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ enum CollapsedEvent: Identifiable {
|
||||
|
||||
|
||||
struct EventDetailView: View {
|
||||
|
||||
let sub_id = UUID().description
|
||||
let pool: RelayPool
|
||||
|
||||
@StateObject var thread: ThreadModel
|
||||
@State var collapsed: Bool = true
|
||||
@@ -48,37 +48,6 @@ struct EventDetailView: View {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func OldEventView(proxy: ScrollViewProxy, ev: NostrEvent, highlight: Highlight, collapsed_events: [CollapsedEvent]) -> some View {
|
||||
Group {
|
||||
if ev.id == thread.event.id {
|
||||
EventView(event: ev, highlight: .main, has_action_bar: true)
|
||||
.onAppear() {
|
||||
scroll_to_event(scroller: proxy, id: ev.id, delay: 0.5, animate: true)
|
||||
}
|
||||
.onTapGesture {
|
||||
print_event(ev)
|
||||
let any = any_collapsed(collapsed_events)
|
||||
if (collapsed && any) || (!collapsed && !any) {
|
||||
toggle_collapse_thread(scroller: proxy, id: ev.id)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if !(self.collapsed && highlight.is_none) {
|
||||
EventView(event: ev, highlight: collapsed ? .none : highlight, has_action_bar: true)
|
||||
.onTapGesture {
|
||||
print_event(ev)
|
||||
if !collapsed {
|
||||
toggle_collapse_thread(scroller: proxy, id: ev.id)
|
||||
}
|
||||
thread.event = ev
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
func uncollapse_section(scroller: ScrollViewProxy, c: CollapsedEvents)
|
||||
{
|
||||
let ev = thread.events[c.start]
|
||||
@@ -101,9 +70,9 @@ struct EventDetailView: View {
|
||||
toggle_thread_view()
|
||||
}
|
||||
case .event(let ev, let highlight):
|
||||
EventView(event: ev, highlight: highlight, has_action_bar: true)
|
||||
EventView(event: ev, highlight: highlight, has_action_bar: true, pool: pool)
|
||||
.onTapGesture {
|
||||
if thread.event!.id == ev.id {
|
||||
if thread.event.id == ev.id {
|
||||
toggle_thread_view()
|
||||
} else {
|
||||
thread.set_active_event(ev)
|
||||
@@ -324,3 +293,34 @@ func scroll_to_event(scroller: ScrollViewProxy, id: String, delay: Double, anima
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
func OldEventView(proxy: ScrollViewProxy, ev: NostrEvent, highlight: Highlight, collapsed_events: [CollapsedEvent]) -> some View {
|
||||
Group {
|
||||
if ev.id == thread.event.id {
|
||||
EventView(event: ev, highlight: .main, has_action_bar: true)
|
||||
.onAppear() {
|
||||
scroll_to_event(scroller: proxy, id: ev.id, delay: 0.5, animate: true)
|
||||
}
|
||||
.onTapGesture {
|
||||
print_event(ev)
|
||||
let any = any_collapsed(collapsed_events)
|
||||
if (collapsed && any) || (!collapsed && !any) {
|
||||
toggle_collapse_thread(scroller: proxy, id: ev.id)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if !(self.collapsed && highlight.is_none) {
|
||||
EventView(event: ev, highlight: collapsed ? .none : highlight, has_action_bar: true)
|
||||
.onTapGesture {
|
||||
print_event(ev)
|
||||
if !collapsed {
|
||||
toggle_collapse_thread(scroller: proxy, id: ev.id)
|
||||
}
|
||||
thread.event = ev
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -40,17 +40,21 @@ struct EventView: View {
|
||||
let event: NostrEvent
|
||||
let highlight: Highlight
|
||||
let has_action_bar: Bool
|
||||
let pool: RelayPool
|
||||
|
||||
@EnvironmentObject var profiles: Profiles
|
||||
@EnvironmentObject var action_bar: ActionBarModel
|
||||
|
||||
var body: some View {
|
||||
let profile = profiles.lookup(id: event.pubkey)
|
||||
HStack {
|
||||
VStack {
|
||||
ProfilePicView(picture: profile?.picture, size: PFP_SIZE!, highlight: highlight)
|
||||
.onTapGesture {
|
||||
NotificationCenter.default.post(name: .click_profile_pic, object: event.pubkey)
|
||||
}
|
||||
let pv = ProfileView(pool: pool, profile: ProfileModel(pubkey: event.pubkey, pool: pool))
|
||||
.environmentObject(profiles)
|
||||
|
||||
NavigationLink(destination: pv) {
|
||||
ProfilePicView(picture: profile?.picture, size: PFP_SIZE!, highlight: highlight)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
|
||||
@@ -15,13 +15,14 @@ enum ProfileTab: Hashable {
|
||||
struct ProfileView: View {
|
||||
let pool: RelayPool
|
||||
@State private var selected_tab: ProfileTab = .posts
|
||||
@StateObject var profile: ProfileModel
|
||||
|
||||
@EnvironmentObject var profile: ProfileModel
|
||||
//@EnvironmentObject var profile: ProfileModel
|
||||
@EnvironmentObject var profiles: Profiles
|
||||
|
||||
var TopSection: some View {
|
||||
HStack(alignment: .top) {
|
||||
let data = profile.pubkey.flatMap { profiles.lookup(id: $0) }
|
||||
let data = profiles.lookup(id: profile.pubkey)
|
||||
ProfilePicView(picture: data?.picture, size: 64, highlight: .custom(Color.black, 4))
|
||||
//.border(Color.blue)
|
||||
VStack(alignment: .leading) {
|
||||
@@ -64,6 +65,13 @@ struct ProfileView: View {
|
||||
//.border(Color.white)
|
||||
.frame(maxWidth: .infinity, alignment: .topLeading)
|
||||
.navigationBarTitle("Profile")
|
||||
.onAppear() {
|
||||
profile.subscribe()
|
||||
}
|
||||
.onDisappear {
|
||||
profile.unsubscribe()
|
||||
// our profilemodel needs a bit more help
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ func all_referenced_pubkeys(_ ev: NostrEvent) -> [ReferencedId] {
|
||||
|
||||
struct ReplyView: View {
|
||||
let replying_to: NostrEvent
|
||||
let pool: RelayPool
|
||||
|
||||
@EnvironmentObject var profiles: Profiles
|
||||
|
||||
@@ -34,7 +35,7 @@ struct ReplyView: View {
|
||||
.foregroundColor(.gray)
|
||||
.font(.footnote)
|
||||
}
|
||||
EventView(event: replying_to, highlight: .none, has_action_bar: false)
|
||||
EventView(event: replying_to, highlight: .none, has_action_bar: false, pool: pool)
|
||||
PostView(references: replying_to.reply_ids())
|
||||
|
||||
Spacer()
|
||||
|
||||
@@ -10,9 +10,10 @@ import SwiftUI
|
||||
|
||||
struct ThreadView: View {
|
||||
@State var is_chatroom: Bool = false
|
||||
@StateObject var thread: ThreadModel
|
||||
let pool: RelayPool
|
||||
|
||||
@EnvironmentObject var profiles: Profiles
|
||||
@EnvironmentObject var thread: ThreadModel
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
var body: some View {
|
||||
@@ -23,13 +24,12 @@ struct ThreadView: View {
|
||||
.environmentObject(profiles)
|
||||
.environmentObject(thread)
|
||||
} else {
|
||||
EventDetailView(thread: thread)
|
||||
EventDetailView(pool: pool, thread: thread)
|
||||
.navigationBarTitle("Thread")
|
||||
.environmentObject(profiles)
|
||||
.environmentObject(thread)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
NavigationLink(destination: edv, isActive: $is_chatroom) {
|
||||
EmptyView()
|
||||
|
||||
@@ -37,10 +37,16 @@ struct TimelineView: View {
|
||||
.environmentObject(profiles)
|
||||
*/
|
||||
|
||||
EventView(event: ev, highlight: .none, has_action_bar: true)
|
||||
.onTapGesture {
|
||||
NotificationCenter.default.post(name: .open_thread, object: ev)
|
||||
}
|
||||
let tv = ThreadView(thread: ThreadModel(ev: ev, pool: pool), pool: pool)
|
||||
.environmentObject(profiles)
|
||||
|
||||
NavigationLink(destination: tv) {
|
||||
EventView(event: ev, highlight: .none, has_action_bar: true, pool: pool)
|
||||
}
|
||||
.buttonStyle(PlainButtonStyle())
|
||||
//.onTapGesture {
|
||||
//NotificationCenter.default.post(name: .open_thread, object: ev)
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user