Skip to content

Commit

Permalink
Merge branch 'master' into feature/209-due-by-table
Browse files Browse the repository at this point in the history
  • Loading branch information
krugerk authored Dec 31, 2024
2 parents 532b51f + b0466d5 commit 24fac1c
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion BeeKit/Managers/DataPointManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public actor DataPointManager {
}

private func deleteDatapoint(goal: Goal, datapoint : DataPoint) async throws {
let _ = try await requestManager.delete(url: "api/v1/users/{username}/goals/\(goal.slug)/datapoints/\(datapoint.id)", parameters: nil)
let _ = try await requestManager.delete(url: "api/v1/users/{username}/goals/\(goal.slug)/datapoints/\(datapoint.id)")
}

private func postDatapoint(goal : Goal, params : [String : String]) async throws {
Expand Down
6 changes: 3 additions & 3 deletions BeeKit/Managers/GoalManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public actor GoalManager {
return
}

let responseObject = try await requestManager.get(url: "api/v1/users/\(username)/goals.json", parameters: nil)!
let responseObject = try await requestManager.get(url: "api/v1/users/\(username)/goals.json")!
let response = JSON(responseObject)
self.updateGoalsFromJson(response) // TODO: Return failure info

Expand All @@ -72,7 +72,7 @@ public actor GoalManager {
public func refreshGoal(_ goalID: NSManagedObjectID) async throws {
let goal = try modelContext.existingObject(with: goalID) as! Goal

let responseObject = try await requestManager.get(url: "/api/v1/users/\(currentUserManager.username!)/goals/\(goal.slug)?datapoints_count=5", parameters: nil)
let responseObject = try await requestManager.get(url: "/api/v1/users/\(currentUserManager.username!)/goals/\(goal.slug)?datapoints_count=5")
let goalJSON = JSON(responseObject!)

// The goal may have changed during the network operation, reload latest version
Expand All @@ -85,7 +85,7 @@ public actor GoalManager {
}

public func forceAutodataRefresh(_ goal: Goal) async throws {
let _ = try await requestManager.get(url: "/api/v1/users/\(currentUserManager.username!)/goals/\(goal.slug)/refresh_graph.json", parameters: nil)
let _ = try await requestManager.get(url: "/api/v1/users/\(currentUserManager.username!)/goals/\(goal.slug)/refresh_graph.json")
}

private func updateGoalsFromJson(_ responseJSON: JSON) {
Expand Down
10 changes: 5 additions & 5 deletions BeeKit/Managers/RequestManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class RequestManager {
public let baseURLString = Config().baseURLString
private let logger = Logger(subsystem: "com.beeminder.beeminder", category: "RequestManager")

func rawRequest(url: String, method: HTTPMethod, parameters: [String: Any]?, headers: HTTPHeaders) async throws -> Any? {
func rawRequest(url: String, method: HTTPMethod, parameters: [String: Any]? = nil, headers: HTTPHeaders) async throws -> Any? {

var urlWithSubstitutions = url
if url.contains("{username}") {
Expand Down Expand Up @@ -78,20 +78,20 @@ public class RequestManager {
}
}

public func get(url: String, parameters: [String: Any]?) async throws -> Any? {
public func get(url: String, parameters: [String: Any]? = nil) async throws -> Any? {
return try await rawRequest(url: url, method: .get, parameters: parameters, headers: authenticationHeaders())
}


public func put(url: String, parameters: [String: Any]?) async throws -> Any? {
public func put(url: String, parameters: [String: Any]? = nil) async throws -> Any? {
return try await rawRequest(url: url, method: .patch, parameters: parameters, headers: authenticationHeaders())
}

public func post(url: String, parameters: [String: Any]?) async throws -> Any? {
public func post(url: String, parameters: [String: Any]? = nil) async throws -> Any? {
return try await rawRequest(url: url, method: .post, parameters: parameters, headers: authenticationHeaders())
}

public func delete(url: String, parameters: [String: Any]?) async throws -> Any? {
public func delete(url: String, parameters: [String: Any]? = nil) async throws -> Any? {
return try await rawRequest(url: url, method: .delete, parameters: parameters, headers: authenticationHeaders())
}

Expand Down
2 changes: 1 addition & 1 deletion BeeKit/Managers/VersionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class VersionManager {
}

private func checkIfUpdateRequired() async throws -> Bool {
let responseJSON = try await requestManager.get(url: "api/private/app_versions.json", parameters: nil)
let responseJSON = try await requestManager.get(url: "api/private/app_versions.json")

guard let response = JSON(responseJSON!).dictionary else {
throw VersionError.invalidServerResponse
Expand Down
4 changes: 2 additions & 2 deletions BeeSwift/Components/DatapointTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit

import BeeKit

protocol DatapointTableViewControllerDelegate {
protocol DatapointTableViewControllerDelegate: AnyObject {
func datapointTableViewController(_ datapointTableViewController: DatapointTableViewController, didSelectDatapoint datapoint: BeeDataPoint)
}

Expand All @@ -20,7 +20,7 @@ class DatapointTableViewController : UIViewController, UITableViewDelegate, UITa
fileprivate var datapointsTableView = DatapointsTableView()


public var delegate : DatapointTableViewControllerDelegate?
public weak var delegate : DatapointTableViewControllerDelegate?

public var datapoints : [BeeDataPoint] = [] {
didSet {
Expand Down
2 changes: 1 addition & 1 deletion BeeSwift/EditDatapointViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class EditDatapointViewController: UIViewController, UITextFieldDelegate {
hud.mode = .indeterminate

do {
let _ = try await ServiceLocator.requestManager.delete(url: "api/v1/users/{username}/goals/\(self.goal.slug)/datapoints/\(self.datapoint.id).json", parameters: nil)
let _ = try await ServiceLocator.requestManager.delete(url: "api/v1/users/{username}/goals/\(self.goal.slug)/datapoints/\(self.datapoint.id).json")
try await ServiceLocator.goalManager.refreshGoal(self.goal.objectID)

hud.mode = .customView
Expand Down
5 changes: 3 additions & 2 deletions BeeSwift/Gallery/GalleryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayou
make.left.equalTo(10)
make.right.equalTo(-10)
}
self.deadbeatView.isHidden = true

stackView.addArrangedSubview(self.outofdateView)
self.outofdateView.accessibilityIdentifier = "outofdateView"
Expand Down Expand Up @@ -289,8 +290,8 @@ class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayou


func updateDeadbeatVisibility() {
guard let user = currentUserManager.user(context: viewContext) else { return }
self.deadbeatView.isHidden = !user.deadbeat
let isKnownDeadbeat = currentUserManager.user(context: viewContext)?.deadbeat == true
self.deadbeatView.isHidden = !isKnownDeadbeat
}

private let lastUpdatedDateFormatter: RelativeDateTimeFormatter = {
Expand Down
12 changes: 8 additions & 4 deletions BeeSwift/GoalViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GoalViewController: UIViewController, UIScrollViewDelegate, DatapointTabl
fileprivate var valueStepper = UIStepper()
fileprivate var valueDecimalRemnant : Double = 0.0
fileprivate var goalImageScrollView = UIScrollView()
fileprivate var pollTimer : Timer?
fileprivate var lastUpdatedTimer: Timer?
fileprivate var countdownLabel = BSLabel()
fileprivate let dueByLabel = BSLabel()
fileprivate var scrollView = UIScrollView()
Expand Down Expand Up @@ -73,8 +73,7 @@ class GoalViewController: UIViewController, UIScrollViewDelegate, DatapointTabl
}

self.updateLastUpdatedLabel()
Timer.scheduledTimer(timeInterval: 60, target: self, selector: #selector(GoalViewController.updateLastUpdatedLabel), userInfo: nil, repeats: true)

lastUpdatedTimer = Timer.scheduledTimer(timeInterval: 60, target: self, selector: #selector(GoalViewController.updateLastUpdatedLabel), userInfo: nil, repeats: true)

self.view.addSubview(self.scrollView)
self.scrollView.snp.makeConstraints { (make) -> Void in
Expand Down Expand Up @@ -322,6 +321,12 @@ class GoalViewController: UIViewController, UIScrollViewDelegate, DatapointTabl
self.commentTextField.iq.distanceFromKeyboard = addDataPointAdditionalKeyboardDistance
}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
lastUpdatedTimer?.invalidate()
lastUpdatedTimer = nil
}

@objc func onGoalsUpdatedNotification() {
updateInterfaceToMatchGoal()
}
Expand Down Expand Up @@ -540,7 +545,6 @@ class GoalViewController: UIViewController, UIScrollViewDelegate, DatapointTabl
}
}


private extension DateFormatter {
private static let urtextDateFormatter: DateFormatter = {
let formatter = DateFormatter()
Expand Down

0 comments on commit 24fac1c

Please sign in to comment.