From 65710eeb5e3897b0b7eb377678e1f7131497e35f Mon Sep 17 00:00:00 2001 From: William Casarin Date: Tue, 9 Aug 2022 16:49:41 -0700 Subject: [PATCH] clicking chat quotes now just expands thems jumping to them is kind of annoying Changelog-Changed: Clicking a chatroom quote reply will now expand it instead of jumping to it Signed-off-by: William Casarin --- damus/Views/ChatView.swift | 6 +++++- damus/Views/EventDetailView.swift | 14 ++++++++++++-- damus/Views/ReplyQuoteView.swift | 3 --- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/damus/Views/ChatView.swift b/damus/Views/ChatView.swift index 684ff45..de87fc9 100644 --- a/damus/Views/ChatView.swift +++ b/damus/Views/ChatView.swift @@ -14,6 +14,7 @@ struct ChatView: View { let damus_state: DamusState + @State var expand_reply: Bool = false @EnvironmentObject var thread: ThreadModel var just_started: Bool { @@ -96,8 +97,11 @@ struct ChatView: View { if let ref_id = thread.replies.lookup(event.id) { if !is_reply_to_prev() { ReplyQuoteView(privkey: damus_state.keypair.privkey, quoter: event, event_id: ref_id, image_cache: damus_state.image_cache, profiles: damus_state.profiles) - .frame(maxHeight: 100) + .frame(maxHeight: expand_reply ? nil : 100) .environmentObject(thread) + .onTapGesture { + expand_reply = !expand_reply + } ReplyDescription } } diff --git a/damus/Views/EventDetailView.swift b/damus/Views/EventDetailView.swift index 9f36a5a..18df648 100644 --- a/damus/Views/EventDetailView.swift +++ b/damus/Views/EventDetailView.swift @@ -66,8 +66,9 @@ struct EventDetailView: View { .onTapGesture { //self.uncollapse_section(scroller: proxy, c: c) //self.toggle_collapse_thread(scroller: proxy, id: nil) - let ev = thread.events[c.start] - thread.set_active_event(ev, privkey: damus.keypair.privkey) + if let ev = thread.events[safe: c.start] { + thread.set_active_event(ev, privkey: damus.keypair.privkey) + } toggle_thread_view() } case .event(let ev, let highlight): @@ -333,3 +334,12 @@ func scroll_to_event(scroller: ScrollViewProxy, id: String, delay: Double, anima } } */ + + +extension Collection { + + /// Returns the element at the specified index if it is within bounds, otherwise nil. + subscript (safe index: Index) -> Element? { + return indices.contains(index) ? self[index] : nil + } +} diff --git a/damus/Views/ReplyQuoteView.swift b/damus/Views/ReplyQuoteView.swift index ec60f7f..641cd33 100644 --- a/damus/Views/ReplyQuoteView.swift +++ b/damus/Views/ReplyQuoteView.swift @@ -50,9 +50,6 @@ struct ReplyQuoteView: View { .padding(4) .frame(maxWidth: .infinity, alignment: .leading) .contentShape(Rectangle()) - .onTapGesture { - NotificationCenter.default.post(name: .select_quote, object: event) - } } else { ProgressView() .progressViewStyle(.circular)