Skip to content

Commit 2673b18

Browse files
committed
Scoreboard refactoring.
1 parent e3efaad commit 2673b18

File tree

2 files changed

+33
-98
lines changed

2 files changed

+33
-98
lines changed

Moblin/View/Settings/Scenes/Widgets/Widget/Scoreboard/WidgetScoreboardGenericSettingsView.swift

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,12 @@ private struct ScoreboardStartStopClockButtonView: View {
7575
}
7676
}
7777

78-
private struct ScoreboardUndoButtonView: View {
79-
let model: Model
80-
let widget: SettingsWidget
78+
struct ScoreboardUndoButtonView: View {
79+
let action: () -> Void
8180

8281
var body: some View {
8382
Button {
84-
model.handleUpdateGenericScoreboard(action: .init(id: widget.id, action: .undo))
83+
action()
8584
} label: {
8685
Image(systemName: "arrow.uturn.backward")
8786
.font(.title)
@@ -90,13 +89,12 @@ private struct ScoreboardUndoButtonView: View {
9089
}
9190
}
9291

93-
private struct ScoreboardIncrementHomeButtonView: View {
94-
let model: Model
95-
let widget: SettingsWidget
92+
struct ScoreboardIncrementButtonView: View {
93+
let action: () -> Void
9694

9795
var body: some View {
9896
Button {
99-
model.handleUpdateGenericScoreboard(action: .init(id: widget.id, action: .incrementHome))
97+
action()
10098
} label: {
10199
Image(systemName: "plus")
102100
.font(.title)
@@ -105,24 +103,8 @@ private struct ScoreboardIncrementHomeButtonView: View {
105103
}
106104
}
107105

108-
private struct ScoreboardIncrementAwayButtonView: View {
109-
let model: Model
110-
let widget: SettingsWidget
111-
112-
var body: some View {
113-
Button {
114-
model.handleUpdateGenericScoreboard(action: .init(id: widget.id, action: .incrementAway))
115-
} label: {
116-
Image(systemName: "plus")
117-
.font(.title)
118-
}
119-
.buttonStyle(.borderless)
120-
}
121-
}
122-
123-
private struct ScoreboardResetScoreButtonView: View {
124-
let model: Model
125-
let widget: SettingsWidget
106+
struct ScoreboardResetScoreButtonView: View {
107+
let action: () -> Void
126108
@State private var presentingResetConfirimation = false
127109

128110
var body: some View {
@@ -136,7 +118,7 @@ private struct ScoreboardResetScoreButtonView: View {
136118
.tint(.red)
137119
.confirmationDialog("", isPresented: $presentingResetConfirimation) {
138120
Button("Reset score", role: .destructive) {
139-
model.handleUpdateGenericScoreboard(action: .init(id: widget.id, action: .reset))
121+
action()
140122
}
141123
}
142124
}
@@ -157,12 +139,20 @@ struct WidgetScoreboardGenericQuickButtonControlsView: View {
157139
}
158140
Divider()
159141
VStack(spacing: 13) {
160-
ScoreboardUndoButtonView(model: model, widget: widget)
161-
ScoreboardResetScoreButtonView(model: model, widget: widget)
142+
ScoreboardUndoButtonView {
143+
model.handleUpdateGenericScoreboard(action: .init(id: widget.id, action: .undo))
144+
}
145+
ScoreboardResetScoreButtonView {
146+
model.handleUpdateGenericScoreboard(action: .init(id: widget.id, action: .reset))
147+
}
162148
}
163149
VStack(spacing: 13) {
164-
ScoreboardIncrementHomeButtonView(model: model, widget: widget)
165-
ScoreboardIncrementAwayButtonView(model: model, widget: widget)
150+
ScoreboardIncrementButtonView {
151+
model.handleUpdateGenericScoreboard(action: .init(id: widget.id, action: .incrementHome))
152+
}
153+
ScoreboardIncrementButtonView {
154+
model.handleUpdateGenericScoreboard(action: .init(id: widget.id, action: .incrementAway))
155+
}
166156
}
167157
}
168158
}

Moblin/View/Settings/Scenes/Widgets/Widget/Scoreboard/WidgetScoreboardPadelSettingsView.swift

Lines changed: 12 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -70,69 +70,6 @@ private struct PlayerView: View {
7070
}
7171
}
7272

73-
private struct ScoreboardUndoButtonView: View {
74-
let model: Model
75-
let widget: SettingsWidget
76-
77-
var body: some View {
78-
Button {
79-
model.handleUpdatePadelScoreboard(action: .init(id: widget.id, action: .undo))
80-
} label: {
81-
Image(systemName: "arrow.uturn.backward")
82-
}
83-
.buttonStyle(.borderless)
84-
}
85-
}
86-
87-
private struct ScoreboardIncrementHomeButtonView: View {
88-
let model: Model
89-
let widget: SettingsWidget
90-
91-
var body: some View {
92-
Button {
93-
model.handleUpdatePadelScoreboard(action: .init(id: widget.id, action: .incrementHome))
94-
} label: {
95-
Image(systemName: "plus")
96-
}
97-
.buttonStyle(.borderless)
98-
}
99-
}
100-
101-
private struct ScoreboardIncrementAwayButtonView: View {
102-
let model: Model
103-
let widget: SettingsWidget
104-
105-
var body: some View {
106-
Button {
107-
model.handleUpdatePadelScoreboard(action: .init(id: widget.id, action: .incrementAway))
108-
} label: {
109-
Image(systemName: "plus")
110-
}
111-
.buttonStyle(.borderless)
112-
}
113-
}
114-
115-
private struct ScoreboardResetScoreButtonView: View {
116-
let model: Model
117-
let widget: SettingsWidget
118-
@State private var presentingResetConfirimation = false
119-
120-
var body: some View {
121-
Button {
122-
presentingResetConfirimation = true
123-
} label: {
124-
Image(systemName: "trash")
125-
}
126-
.buttonStyle(.borderless)
127-
.tint(.red)
128-
.confirmationDialog("", isPresented: $presentingResetConfirimation) {
129-
Button("Reset score", role: .destructive) {
130-
model.handleUpdatePadelScoreboard(action: .init(id: widget.id, action: .reset))
131-
}
132-
}
133-
}
134-
}
135-
13673
struct WidgetScoreboardPadelQuickButtonControlsView: View {
13774
let model: Model
13875
let widget: SettingsWidget
@@ -141,13 +78,21 @@ struct WidgetScoreboardPadelQuickButtonControlsView: View {
14178
VStack(spacing: 13) {
14279
HStack(spacing: 13) {
14380
Spacer()
144-
ScoreboardUndoButtonView(model: model, widget: widget)
145-
ScoreboardIncrementHomeButtonView(model: model, widget: widget)
81+
ScoreboardUndoButtonView {
82+
model.handleUpdatePadelScoreboard(action: .init(id: widget.id, action: .undo))
83+
}
84+
ScoreboardIncrementButtonView {
85+
model.handleUpdatePadelScoreboard(action: .init(id: widget.id, action: .incrementHome))
86+
}
14687
}
14788
HStack(spacing: 13) {
14889
Spacer()
149-
ScoreboardResetScoreButtonView(model: model, widget: widget)
150-
ScoreboardIncrementAwayButtonView(model: model, widget: widget)
90+
ScoreboardResetScoreButtonView {
91+
model.handleUpdatePadelScoreboard(action: .init(id: widget.id, action: .reset))
92+
}
93+
ScoreboardIncrementButtonView {
94+
model.handleUpdatePadelScoreboard(action: .init(id: widget.id, action: .incrementAway))
95+
}
15196
}
15297
}
15398
.font(.title)

0 commit comments

Comments
 (0)