Skip to content

Commit 78c8079

Browse files
committed
Topic poll improvements
1 parent ae738bf commit 78c8079

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

Modules/Sources/ParsingClient/Parsers/TopicParser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public struct TopicParser {
131131

132132
private static func parsePollOptions(_ optionsRaw: [[Any]]) throws(ParsingError) -> [Topic.Poll.Option] {
133133
var options: [Topic.Poll.Option] = []
134-
for (idx, option) in optionsRaw.enumerated() {
134+
for (optionId, option) in optionsRaw.enumerated() {
135135
guard let name = option[safe: 0] as? String,
136136
let several = option[safe: 1] as? Int,
137137
let names = option[safe: 2] as? [String],
@@ -151,7 +151,7 @@ public struct TopicParser {
151151
}
152152

153153
let option = Topic.Poll.Option(
154-
id: idx,
154+
id: optionId,
155155
name: name,
156156
several: several == 1 ? true : false,
157157
choices: choices

Modules/Sources/TopicFeature/TopicFeature.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public struct TopicFeature: Reducer, Sendable {
237237
state.shouldShowTopicPollButton = false
238238
return .none
239239

240-
case .view(.topicPollVoteButtonTapped(let selections)):
240+
case let .view(.topicPollVoteButtonTapped(selections)):
241241
let values = selections.sorted(by: { $0.key < $1.key }).map {
242242
Array($0.value)
243243
}
@@ -412,7 +412,7 @@ public struct TopicFeature: Reducer, Sendable {
412412
jumpTo(.post(id: postId), true, &state)
413413
)
414414

415-
case .internal(.voteInPoll(let selections)):
415+
case let .internal(.voteInPoll(selections)):
416416
return .concatenate(
417417
.run { [topicId = state.topicId] _ in
418418
let status = try await apiClient.voteInTopicPoll(

Modules/Sources/TopicFeature/TopicScreen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public struct TopicScreen: View {
7575
if !store.isLoadingTopic {
7676
Header()
7777

78-
if let poll = store.topic!.poll {
78+
if let poll = store.topic?.poll {
7979
Poll(poll)
8080
}
8181

Modules/Sources/TopicFeature/Views/PollView.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ import SharedUI
1111

1212
struct PollView: View {
1313

14-
@Environment(\.tintColor) private var tintColor
14+
// MARK: - Properties
1515

16-
let poll: Topic.Poll
17-
let onVoteButtonTapped: ([Int: Set<Int>]) -> Void
16+
@Environment(\.tintColor) private var tintColor
1817

1918
@State private var isSending = false
2019
@State private var showVoteResultsButtonTapped = false
2120
@State private var selections: [Int: Set<Int>] = [:]
2221

22+
let poll: Topic.Poll
23+
let onVoteButtonTapped: ([Int: Set<Int>]) -> Void
24+
25+
// MARK: - Computed Properties
26+
2327
private var isVotable: Bool {
2428
for option in poll.options {
2529
if selections[option.id] == nil {
@@ -33,6 +37,8 @@ struct PollView: View {
3337
return true
3438
}
3539

40+
// MARK: - Init
41+
3642
init(
3743
poll: Topic.Poll,
3844
onVoteButtonTapped: @escaping ([Int: Set<Int>]) -> Void
@@ -41,6 +47,8 @@ struct PollView: View {
4147
self.onVoteButtonTapped = onVoteButtonTapped
4248
}
4349

50+
// MARK: - Body
51+
4452
var body: some View {
4553
VStack(spacing: 12) {
4654
if !poll.name.isEmpty {
@@ -245,6 +253,8 @@ struct PollView: View {
245253
}
246254
}
247255

256+
// MARK: - CheckBox Toggle Style
257+
248258
struct CheckBoxToggleStyle: ToggleStyle {
249259
func makeBody(configuration: Configuration) -> some View {
250260
HStack {
@@ -272,6 +282,8 @@ struct CheckBoxToggleStyle: ToggleStyle {
272282
}
273283
}
274284

285+
// MARK: - Previews
286+
275287
#Preview {
276288
VStack {
277289
PollView(poll: .mock, onVoteButtonTapped: { selections in

0 commit comments

Comments
 (0)