mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-06 01:09:30 +00:00
make votes and ownVotes optional
This commit is contained in:
parent
1c827d1f7e
commit
5fe72e36d2
2 changed files with 5 additions and 5 deletions
|
@ -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]
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue