eventsmodel: remove inheritence in Reactions/Reposts model
Simplify with new EventsModel constructors. This is slightly less typesafe but its not a big deal, I hate inheritence more. Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -23,6 +23,14 @@ class EventsModel: ObservableObject {
|
||||
self.kind = kind
|
||||
}
|
||||
|
||||
public static func reposts(state: DamusState, target: NoteId) -> EventsModel {
|
||||
EventsModel(state: state, target: target, kind: .boost)
|
||||
}
|
||||
|
||||
public static func likes(state: DamusState, target: NoteId) -> EventsModel {
|
||||
EventsModel(state: state, target: target, kind: .like)
|
||||
}
|
||||
|
||||
private func get_filter() -> NostrFilter {
|
||||
var filter = NostrFilter(kinds: [kind])
|
||||
filter.referenced_ids = [target]
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
//
|
||||
// LikesModel.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2023-01-11.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
final class ReactionsModel: EventsModel {
|
||||
|
||||
init(state: DamusState, target: NoteId) {
|
||||
super.init(state: state, target: target, kind: .like)
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
//
|
||||
// RepostsModel.swift
|
||||
// damus
|
||||
//
|
||||
// Created by Terry Yiu on 1/22/23.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
final class RepostsModel: EventsModel {
|
||||
|
||||
init(state: DamusState, target: NoteId) {
|
||||
super.init(state: state, target: target, kind: .boost)
|
||||
}
|
||||
}
|
||||
@@ -31,8 +31,8 @@ enum Route: Hashable {
|
||||
case SearchSettings(settings: UserSettingsStore)
|
||||
case DeveloperSettings(settings: UserSettingsStore)
|
||||
case Thread(thread: ThreadModel)
|
||||
case Reposts(reposts: RepostsModel)
|
||||
case Reactions(reactions: ReactionsModel)
|
||||
case Reposts(reposts: EventsModel)
|
||||
case Reactions(reactions: EventsModel)
|
||||
case Zaps(target: ZapTarget)
|
||||
case Search(search: SearchModel)
|
||||
case EULA
|
||||
|
||||
@@ -25,7 +25,7 @@ struct EventDetailBar: View {
|
||||
var body: some View {
|
||||
HStack {
|
||||
if bar.boosts > 0 {
|
||||
NavigationLink(value: Route.Reposts(reposts: RepostsModel(state: state, target: target))) {
|
||||
NavigationLink(value: Route.Reposts(reposts: .reposts(state: state, target: target))) {
|
||||
let nounString = pluralizedString(key: "reposts_count", count: bar.boosts)
|
||||
let noun = Text(nounString).foregroundColor(.gray)
|
||||
Text("\(Text(verbatim: bar.boosts.formatted()).font(.body.bold())) \(noun)", comment: "Sentence composed of 2 variables to describe how many reposts. In source English, the first variable is the number of reposts, and the second variable is 'Repost' or 'Reposts'.")
|
||||
@@ -34,7 +34,7 @@ struct EventDetailBar: View {
|
||||
}
|
||||
|
||||
if bar.likes > 0 && !state.settings.onlyzaps_mode {
|
||||
NavigationLink(value: Route.Reactions(reactions: ReactionsModel(state: state, target: target))) {
|
||||
NavigationLink(value: Route.Reactions(reactions: .likes(state: state, target: target))) {
|
||||
let nounString = pluralizedString(key: "reactions_count", count: bar.likes)
|
||||
let noun = Text(nounString).foregroundColor(.gray)
|
||||
Text("\(Text(verbatim: bar.likes.formatted()).font(.body.bold())) \(noun)", comment: "Sentence composed of 2 variables to describe how many reactions there are on a post. In source English, the first variable is the number of reactions, and the second variable is 'Reaction' or 'Reactions'.")
|
||||
|
||||
@@ -9,8 +9,8 @@ import SwiftUI
|
||||
|
||||
struct ReactionsView: View {
|
||||
let damus_state: DamusState
|
||||
@StateObject var model: ReactionsModel
|
||||
|
||||
@StateObject var model: EventsModel
|
||||
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
var body: some View {
|
||||
@@ -38,6 +38,6 @@ struct ReactionsView: View {
|
||||
struct ReactionsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let state = test_damus_state
|
||||
ReactionsView(damus_state: state, model: ReactionsModel(state: state, target: test_note.id))
|
||||
ReactionsView(damus_state: state, model: .likes(state: state, target: test_note.id))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import SwiftUI
|
||||
|
||||
struct RepostsView: View {
|
||||
let damus_state: DamusState
|
||||
@StateObject var model: RepostsModel
|
||||
@StateObject var model: EventsModel
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
@@ -33,6 +33,6 @@ struct RepostsView: View {
|
||||
struct RepostsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let state = test_damus_state
|
||||
RepostsView(damus_state: state, model: RepostsModel(state: state, target: test_note.id))
|
||||
RepostsView(damus_state: state, model: .reposts(state: state, target: test_note.id))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user