HighlightEventRef.swift (3930B)
1 // 2 // HighlightEventRef.swift 3 // damus 4 // 5 // Created by eric on 4/29/24. 6 // 7 8 import SwiftUI 9 import Kingfisher 10 11 struct HighlightEventRef: View { 12 let damus_state: DamusState 13 let event_ref: NoteId 14 15 init(damus_state: DamusState, event_ref: NoteId) { 16 self.damus_state = damus_state 17 self.event_ref = event_ref 18 } 19 20 struct FailedImage: View { 21 var body: some View { 22 Image("markdown") 23 .resizable() 24 .foregroundColor(DamusColors.neutral6) 25 .background(DamusColors.neutral3) 26 .frame(width: 35, height: 35) 27 .clipShape(RoundedRectangle(cornerRadius: 10)) 28 .overlay(RoundedRectangle(cornerRadius: 10).stroke(.gray.opacity(0.5), lineWidth: 0.5)) 29 .scaledToFit() 30 } 31 } 32 33 var body: some View { 34 EventLoaderView(damus_state: damus_state, event_id: event_ref) { event in 35 EventMutingContainerView(damus_state: damus_state, event: event) { 36 if event.known_kind == .longform { 37 HStack(alignment: .top, spacing: 10) { 38 let longform_event = LongformEvent.parse(from: event) 39 if let url = longform_event.image { 40 KFAnimatedImage(url) 41 .callbackQueue(.dispatch(.global(qos:.background))) 42 .backgroundDecode(true) 43 .imageContext(.note, disable_animation: true) 44 .image_fade(duration: 0.25) 45 .cancelOnDisappear(true) 46 .configure { view in 47 view.framePreloadCount = 3 48 } 49 .background { 50 FailedImage() 51 } 52 .frame(width: 35, height: 35) 53 .kfClickable() 54 .clipShape(RoundedRectangle(cornerRadius: 10)) 55 .overlay(RoundedRectangle(cornerRadius: 10).stroke(.gray.opacity(0.5), lineWidth: 0.5)) 56 .scaledToFit() 57 } else { 58 FailedImage() 59 } 60 61 VStack(alignment: .leading, spacing: 5) { 62 Text(longform_event.title ?? NSLocalizedString("Untitled", comment: "Title of longform event if it is untitled.")) 63 .font(.system(size: 14, weight: .bold)) 64 .lineLimit(1) 65 66 let profile_txn = damus_state.profiles.lookup(id: longform_event.event.pubkey, txn_name: "highlight-profile") 67 let profile = profile_txn?.unsafeUnownedValue 68 69 if let display_name = profile?.display_name { 70 Text(display_name) 71 .font(.system(size: 12)) 72 .foregroundColor(.gray) 73 } else if let name = profile?.name { 74 Text(name) 75 .font(.system(size: 12)) 76 .foregroundColor(.gray) 77 } 78 } 79 } 80 .padding([.leading, .vertical], 7) 81 .frame(maxWidth: .infinity, alignment: .leading) 82 .cornerRadius(10) 83 .overlay( 84 RoundedRectangle(cornerRadius: 10) 85 .stroke(DamusColors.neutral3, lineWidth: 2) 86 ) 87 } else { 88 EmptyView() 89 } 90 } 91 } 92 } 93 }