Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pager duty model error #66

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions PagerCall.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
CODE_SIGN_ENTITLEMENTS = PagerCall/PagerCall.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 97A8B2WE2P;
Expand Down Expand Up @@ -324,7 +324,7 @@
CODE_SIGN_ENTITLEMENTS = PagerCall/PagerCall.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 97A8B2WE2P;
Expand Down
6 changes: 3 additions & 3 deletions PagerCall/ContentView.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import SwiftUI

struct ContentView: View {
@ObservedObject var pagerDuty: PagerDuty
@ObservedObject var pagerDuty: PagerDutyModel
@State private var hoverId = ""

var body: some View {
VStack {
if let pdErr = self.pagerDuty.error as? PagerDutyError {
if let pdErr = self.pagerDuty.error {
List {
HStack {
Spacer()
Expand Down Expand Up @@ -76,5 +76,5 @@ struct ContentView: View {
}

#Preview {
ContentView(pagerDuty: PagerDuty())
ContentView(pagerDuty: PagerDutyModel())
}
2 changes: 1 addition & 1 deletion PagerCall/PagerCallApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct PagerCallApp: App {
// NOTE: Define "apiKey" in PagerCallApp so that values are not lost during sleep.
@State private var apiKey = Vault.apiKey
@AppStorage("interval") private var interval = Constants.defaultInterval
@StateObject private var pagerDuty = PagerDuty()
@StateObject private var pagerDuty = PagerDutyModel()

// swiftlint:disable unused_declaration
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
Expand Down
4 changes: 0 additions & 4 deletions PagerCall/PagerDutyAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ struct PagerDutyAPI {
decoder.dateDecodingStrategy = .iso8601
let resp = try decoder.decode(IncidentsResp.self, from: data)

for iii in resp.incidents {
print(iii.createdAt.relative())
}

return resp.incidents
}

Expand Down
11 changes: 7 additions & 4 deletions PagerCall/PagerDutyModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ enum Status: String {
}

@MainActor
class PagerDuty: ObservableObject {
class PagerDutyModel: ObservableObject {
private let api = PagerDutyAPI()

@Published var incidents: Incidents = []
@Published var status: Status = .notOnCallWithoutIncident
@Published var updatedAt: Date?
@Published var error: Error?
@Published var error: PagerDutyError?

func update() async {
do {
Expand All @@ -40,8 +40,11 @@ class PagerDuty: ObservableObject {
}
} catch {
Logger.shared.error("failed to get incidents: \(error)")
status = .error
self.error = error

if let pdErr = error as? PagerDutyError {
status = .error
self.error = pdErr
}
}
}

Expand Down