refactor: carve out TextEvent body into EventShell
We'll need this for other event types
This commit is contained in:
20
damus/Views/Events/Components/ContextButton.swift
Normal file
20
damus/Views/Events/Components/ContextButton.swift
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// ContextButton.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2023-06-01.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ContextButton: View {
|
||||
var body: some View {
|
||||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
|
||||
}
|
||||
}
|
||||
|
||||
struct ContextButton_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContextButton()
|
||||
}
|
||||
}
|
||||
44
damus/Views/Events/Components/EventTop.swift
Normal file
44
damus/Views/Events/Components/EventTop.swift
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// EventTop.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2023-06-01.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct EventTop: View {
|
||||
let state: DamusState
|
||||
let event: NostrEvent
|
||||
let is_anon: Bool
|
||||
|
||||
init(state: DamusState, event: NostrEvent, is_anon: Bool) {
|
||||
self.state = state
|
||||
self.event = event
|
||||
self.is_anon = is_anon
|
||||
}
|
||||
|
||||
func ProfileName(is_anon: Bool) -> some View {
|
||||
let profile = state.profiles.lookup(id: event.pubkey)
|
||||
let pk = is_anon ? "anon" : event.pubkey
|
||||
return EventProfileName(pubkey: pk, profile: profile, damus: state, size: .normal)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
HStack(alignment: .center, spacing: 0) {
|
||||
ProfileName(is_anon: is_anon)
|
||||
TimeDot()
|
||||
RelativeTime(time: state.events.get_cache_data(event.id).relative_time)
|
||||
Spacer()
|
||||
EventMenuContext(damus: state, event: event)
|
||||
}
|
||||
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
|
||||
struct EventTop_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
EventTop(state: test_damus_state(), event: test_event, is_anon: false)
|
||||
}
|
||||
}
|
||||
25
damus/Views/Events/Components/RelativeTime.swift
Normal file
25
damus/Views/Events/Components/RelativeTime.swift
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// RelativeTime.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2023-06-01.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct RelativeTime: View {
|
||||
@ObservedObject var time: RelativeTimeModel
|
||||
|
||||
var body: some View {
|
||||
Text(verbatim: "\(time.value)")
|
||||
.font(.system(size: 16))
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct RelativeTime_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
RelativeTime(time: RelativeTimeModel())
|
||||
}
|
||||
}
|
||||
30
damus/Views/Events/Components/ReplyPart.swift
Normal file
30
damus/Views/Events/Components/ReplyPart.swift
Normal file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// ReplyPart.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2023-06-01.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ReplyPart: View {
|
||||
let event: NostrEvent
|
||||
let privkey: String?
|
||||
let profiles: Profiles
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
if event_is_reply(event, privkey: privkey) {
|
||||
ReplyDescription(event: event, profiles: profiles)
|
||||
} else {
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ReplyPart_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ReplyPart(event: test_event, privkey: nil, profiles: test_damus_state().profiles)
|
||||
}
|
||||
}
|
||||
22
damus/Views/Events/Components/TimeDot.swift
Normal file
22
damus/Views/Events/Components/TimeDot.swift
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// TimeDot.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2023-06-01.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct TimeDot: View {
|
||||
var body: some View {
|
||||
Text(verbatim: "⋅")
|
||||
.font(.footnote)
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
}
|
||||
|
||||
struct TimeDot_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
TimeDot()
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,15 @@ struct EventMenuContext: View {
|
||||
let muted_threads: MutedThreadsManager
|
||||
@ObservedObject var settings: UserSettingsStore
|
||||
|
||||
init(damus: DamusState, event: NostrEvent) {
|
||||
self.event = event
|
||||
self.keypair = damus.keypair
|
||||
self.target_pubkey = event.pubkey
|
||||
self.bookmarks = damus.bookmarks
|
||||
self.muted_threads = damus.muted_threads
|
||||
self._settings = ObservedObject(wrappedValue: damus.settings)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Menu {
|
||||
@@ -26,6 +35,7 @@ struct EventMenuContext: View {
|
||||
.foregroundColor(Color.gray)
|
||||
}
|
||||
}
|
||||
.padding([.bottom], 4)
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {}
|
||||
}
|
||||
|
||||
72
damus/Views/Events/EventShell.swift
Normal file
72
damus/Views/Events/EventShell.swift
Normal file
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// EventShell.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2023-06-01.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct EventShell<Content: View>: View {
|
||||
let state: DamusState
|
||||
let event: NostrEvent
|
||||
let options: EventViewOptions
|
||||
let content: Content
|
||||
|
||||
init(state: DamusState, event: NostrEvent, options: EventViewOptions, @ViewBuilder content: () -> Content) {
|
||||
self.state = state
|
||||
self.event = event
|
||||
self.options = options
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
var has_action_bar: Bool {
|
||||
!options.contains(.no_action_bar)
|
||||
}
|
||||
|
||||
func get_mention() -> Mention? {
|
||||
if self.options.contains(.nested) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return first_eref_mention(ev: event, privkey: state.keypair.privkey)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
let is_anon = event_is_anonymous(ev: event)
|
||||
|
||||
HStack(spacing: 10) {
|
||||
MaybeAnonPfpView(state: state, is_anon: is_anon, pubkey: event.pubkey, size: options.contains(.small_pfp) ? eventview_pfp_size(.small) : PFP_SIZE )
|
||||
|
||||
VStack {
|
||||
EventTop(state: state, event: event, is_anon: is_anon)
|
||||
ReplyPart(event: event, privkey: state.keypair.privkey, profiles: state.profiles)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal)
|
||||
|
||||
content
|
||||
|
||||
if !options.contains(.no_mentions), let mention = get_mention() {
|
||||
|
||||
BuilderEventView(damus: state, event_id: mention.ref.id)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
|
||||
if has_action_bar {
|
||||
//EmptyRect
|
||||
EventActionBar(damus_state: state, event: event)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct EventShell_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
EventShell(state: test_damus_state(), event: test_event, options: [.no_action_bar]) {
|
||||
Text("Hello")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,9 +35,8 @@ struct SelectedEventView: View {
|
||||
|
||||
Spacer()
|
||||
|
||||
EventMenuContext(event: event, keypair: damus.keypair, target_pubkey: event.pubkey, bookmarks: damus.bookmarks, muted_threads: damus.muted_threads, settings: damus.settings)
|
||||
EventMenuContext(damus: damus, event: event)
|
||||
.padding([.bottom], 4)
|
||||
|
||||
}
|
||||
.padding(.horizontal)
|
||||
.minimumScaleFactor(0.75)
|
||||
|
||||
@@ -24,16 +24,6 @@ struct EventViewOptions: OptionSet {
|
||||
static let embedded: EventViewOptions = [.no_action_bar, .small_pfp, .wide, .truncate_content, .nested]
|
||||
}
|
||||
|
||||
struct RelativeTime: View {
|
||||
@ObservedObject var time: RelativeTimeModel
|
||||
|
||||
var body: some View {
|
||||
Text(verbatim: "\(time.value)")
|
||||
.font(.system(size: 16))
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
}
|
||||
|
||||
struct TextEvent: View {
|
||||
let damus: DamusState
|
||||
let event: NostrEvent
|
||||
@@ -74,63 +64,20 @@ struct TextEvent: View {
|
||||
func TopPart(is_anon: Bool) -> some View {
|
||||
HStack(alignment: .center, spacing: 0) {
|
||||
ProfileName(is_anon: is_anon)
|
||||
TimeDot
|
||||
TimeDot()
|
||||
RelativeTime(time: self.evdata.relative_time)
|
||||
Spacer()
|
||||
ContextButton
|
||||
EventMenuContext(damus: damus, event: event)
|
||||
}
|
||||
.lineLimit(1)
|
||||
}
|
||||
|
||||
var ReplyPart: some View {
|
||||
Group {
|
||||
if event_is_reply(event, privkey: damus.keypair.privkey) {
|
||||
ReplyDescription(event: event, profiles: damus.profiles)
|
||||
} else {
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var WideStyle: some View {
|
||||
VStack(alignment: .leading) {
|
||||
let is_anon = event_is_anonymous(ev: event)
|
||||
|
||||
HStack(spacing: 10) {
|
||||
Pfp(is_anon: is_anon)
|
||||
VStack {
|
||||
TopPart(is_anon: is_anon)
|
||||
ReplyPart
|
||||
}
|
||||
}
|
||||
.padding(.horizontal)
|
||||
|
||||
EventShell(state: damus, event: event, options: options) {
|
||||
EvBody(options: self.options.union(.pad_content))
|
||||
|
||||
if let mention = get_mention() {
|
||||
Mention(mention)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
|
||||
if has_action_bar {
|
||||
//EmptyRect
|
||||
ActionBar
|
||||
.padding(.horizontal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var TimeDot: some View {
|
||||
Text(verbatim: "⋅")
|
||||
.font(.footnote)
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
|
||||
var ContextButton: some View {
|
||||
EventMenuContext(event: event, keypair: damus.keypair, target_pubkey: event.pubkey, bookmarks: damus.bookmarks, muted_threads: damus.muted_threads, settings: damus.settings)
|
||||
.padding([.bottom], 4)
|
||||
}
|
||||
|
||||
func ProfileName(is_anon: Bool) -> some View {
|
||||
let profile = damus.profiles.lookup(id: pubkey)
|
||||
let pk = is_anon ? ANON_PUBKEY : pubkey
|
||||
@@ -184,7 +131,7 @@ struct TextEvent: View {
|
||||
TopPart(is_anon: is_anon)
|
||||
|
||||
if !options.contains(.no_replying_to) {
|
||||
ReplyPart
|
||||
ReplyPart(event: event, privkey: damus.keypair.privkey, profiles: damus.profiles)
|
||||
}
|
||||
|
||||
EvBody(options: self.options)
|
||||
|
||||
Reference in New Issue
Block a user