mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-02-17 02:05:13 +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 multiple: Bool
|
||||||
public let votesCount: Int
|
public let votesCount: Int
|
||||||
public let votersCount: Int?
|
public let votersCount: Int?
|
||||||
public let voted: Bool
|
public let voted: Bool?
|
||||||
public let ownVotes: [Int]
|
public let ownVotes: [Int]?
|
||||||
public let options: [Option]
|
public let options: [Option]
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,14 +16,14 @@ public class StatusPollViewModel: ObservableObject {
|
||||||
|
|
||||||
public init(poll: Poll) {
|
public init(poll: Poll) {
|
||||||
self.poll = poll
|
self.poll = poll
|
||||||
self.votes = poll.ownVotes
|
self.votes = poll.ownVotes ?? []
|
||||||
}
|
}
|
||||||
|
|
||||||
public func fetchPoll() async {
|
public func fetchPoll() async {
|
||||||
guard let client else { return }
|
guard let client else { return }
|
||||||
do {
|
do {
|
||||||
poll = try await client.get(endpoint: Polls.poll(id: poll.id))
|
poll = try await client.get(endpoint: Polls.poll(id: poll.id))
|
||||||
votes = poll.ownVotes
|
votes = poll.ownVotes ?? []
|
||||||
} catch { }
|
} catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ public class StatusPollViewModel: ObservableObject {
|
||||||
do {
|
do {
|
||||||
poll = try await client.post(endpoint: Polls.vote(id: poll.id, votes: votes))
|
poll = try await client.post(endpoint: Polls.vote(id: poll.id, votes: votes))
|
||||||
withAnimation {
|
withAnimation {
|
||||||
votes = poll.ownVotes
|
votes = poll.ownVotes ?? []
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
print(error)
|
print(error)
|
||||||
|
|
Loading…
Reference in a new issue