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:
William Casarin
2024-03-16 12:11:32 +00:00
parent 8cdbc84093
commit 68dd47130e
8 changed files with 17 additions and 52 deletions

View File

@@ -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'.")

View File

@@ -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))
}
}

View File

@@ -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))
}
}