make votes and ownVotes optional

This commit is contained in:
Thomas Ricouard 2023-01-03 15:51:36 +01:00
parent 1c827d1f7e
commit 5fe72e36d2
2 changed files with 5 additions and 5 deletions

View file

@ -17,7 +17,7 @@ public struct Poll: Codable {
public let multiple: Bool
public let votesCount: Int
public let votersCount: Int?
public let voted: Bool
public let ownVotes: [Int]
public let voted: Bool?
public let ownVotes: [Int]?
public let options: [Option]
}

View file

@ -16,14 +16,14 @@ public class StatusPollViewModel: ObservableObject {
public init(poll: Poll) {
self.poll = poll
self.votes = poll.ownVotes
self.votes = poll.ownVotes ?? []
}
public func fetchPoll() async {
guard let client else { return }
do {
poll = try await client.get(endpoint: Polls.poll(id: poll.id))
votes = poll.ownVotes
votes = poll.ownVotes ?? []
} catch { }
}
@ -32,7 +32,7 @@ public class StatusPollViewModel: ObservableObject {
do {
poll = try await client.post(endpoint: Polls.vote(id: poll.id, votes: votes))
withAnimation {
votes = poll.ownVotes
votes = poll.ownVotes ?? []
}
} catch {
print(error)