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

GraphQL Migration #38

Merged
merged 10 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
17 changes: 11 additions & 6 deletions Example/Example/UIKit/MagicBellStoreViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MagicBellStoreViewController: UITableViewController,
NotificationStoreContentObserver,
NotificationStoreCountObserver {

private var isLoadingNextPage = false
private var isLoading = false

@IBOutlet weak var magicBellStoreItem: BadgeBarButtonItem!

Expand Down Expand Up @@ -62,7 +62,9 @@ class MagicBellStoreViewController: UITableViewController,
// swiftlint:disable empty_count
private func reloadStore() {
if store.count == 0 {
isLoading = true
store.refresh { result in
self.isLoading = false
switch result {
case .success:
// Observers will manage changes
Expand All @@ -78,7 +80,9 @@ class MagicBellStoreViewController: UITableViewController,
}

@objc private func refreshAction(sender: UIRefreshControl) {
isLoading = true
store.refresh { result in
self.isLoading = false
sender.endRefreshing()
switch result {
case .success:
Expand Down Expand Up @@ -138,7 +142,7 @@ class MagicBellStoreViewController: UITableViewController,
self.configureStore(predicate: StorePredicate(archived: true))
})
alert.addAction(UIAlertAction(title: "By Category", style: .default) { _ in
self.configureStore(predicate: StorePredicate(categories: ["order_created"]))
self.configureStore(predicate: StorePredicate(category: "order_created"))
})
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
Expand Down Expand Up @@ -226,7 +230,7 @@ class MagicBellStoreViewController: UITableViewController,

// MARK: UITableViewDelegate

// swiftlint:disable cyclomatic_complexity
// swiftlint:disable cyclomatic_complexity function_body_length
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)

Expand Down Expand Up @@ -304,15 +308,16 @@ class MagicBellStoreViewController: UITableViewController,

present(alert, animated: true, completion: nil)
}
// swiftlint:enable cyclomatic_complexity function_body_length

override func scrollViewDidScroll(_ scrollView: UIScrollView) {
if !isLoadingNextPage &&
if !isLoading &&
(scrollView.contentOffset.y > scrollView.contentSize.height - scrollView.bounds.size.height - 200) && store.hasNextPage {
isLoadingNextPage = true
isLoading = true
print("Load next page")
store.fetch { result in
print("Load completed")
self.isLoadingNextPage = false
self.isLoading = false
switch result {
case .success:
// Observers will manage changes
Expand Down
104 changes: 18 additions & 86 deletions MagicBell.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ let unreadNotifications = user.store.build(read: false)

let archviedNotifications = user.store.build(archived: true)

let billingNotifications = user.store.build(categories: ["billing"])
let billingNotifications = user.store.build(category: "billing")

let firstOrderNotifications = user.store.build(topics: ["order:001"])
let firstOrderNotifications = user.store.build(topic: "order:001")
```

These are the attributes of a notification store:
Expand Down Expand Up @@ -358,13 +358,13 @@ These are the available options:
| `read` | `true`, `false`, `nil` | `nil` | Filter by the `read` state (`nil` means unspecified) |
| `seen` | `true`, `false`, `nil` | `nil` | Filter by the `seen` state (`nil` means unspecified) |
| `archived` | `true`, `false` | `false` | Filter by the `archived` state |
| `categories` | `[String]` | `[]` | Filter by catregories |
| `topics` | `[String]` | `[]` | Filter by topics |
| `category ` | `String` | `nil` | Filter by catregory |
stigi marked this conversation as resolved.
Show resolved Hide resolved
| `topic` | `String` | `nil` | Filter by topic |

For example, use this predicate to fetch unread notifications of the `"important"` category:

```swift
let predicate = StorePredicate(read: .unread, categories: ["important"])
let predicate = StorePredicate(read: .unread, category: "important")
let store = user.store.build(predicate: predicate)
```

Expand Down Expand Up @@ -438,7 +438,7 @@ for notification in store {
}

// As an array
let notifications = store.notifications()
let notifications = store.notifications
```

Enumeration is also available:
Expand Down Expand Up @@ -600,4 +600,4 @@ user.

## Contributing

We welcome contributions of any kind. To do so, clone the repo, resolve dependencies via Carthage in the root folder by running the command `carthage update --use-xcframeworks --no-use-binaries`, and open `MagicBell.xcodeproj`.
We welcome contributions of any kind. To do so, clone the repo, resolve dependencies via Carthage in the root folder by running the command `carthage bootstrap --use-xcframeworks --no-use-binaries`, and open `MagicBell.xcodeproj`.
6 changes: 0 additions & 6 deletions Source/Common/Network/DataToDecodableMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ class DataToDecodableMapper<T>: Mapper<Data, T> where T: Decodable {

private var decoder = JSONDecoder()

init(iso8601: Bool = false) {
if iso8601 {
decoder.dateDecodingStrategy = .iso8601
}
}

override func map(_ from: Data) throws -> T {
do {
let value = try decoder.decode(T.self, from: from)
Expand Down
50 changes: 0 additions & 50 deletions Source/Common/Network/GraphQL/CursorPredicate.swift

This file was deleted.

61 changes: 0 additions & 61 deletions Source/Common/Network/GraphQL/GraphQLFragment.swift

This file was deleted.

18 changes: 0 additions & 18 deletions Source/Common/Network/GraphQL/GraphQLRepresentable.swift

This file was deleted.

38 changes: 0 additions & 38 deletions Source/Common/Network/GraphQL/GraphQLRequest.swift

This file was deleted.

27 changes: 0 additions & 27 deletions Source/Common/Network/GraphQL/GraphQLResponse.swift

This file was deleted.

21 changes: 0 additions & 21 deletions Source/Common/Network/GraphQL/PageInfo.swift

This file was deleted.

20 changes: 16 additions & 4 deletions Source/Common/Network/HttpClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@ import Foundation
import Harmony

protocol HttpClient {
func prepareURLRequest(path: String, externalId: String?, email: String?, hmac: String?, additionalHTTPHeaders: [String: String]?) -> URLRequest
func prepareURLRequest(path: String, externalId: String?, email: String?, hmac: String?, additionalHTTPHeaders: [String: String]?, queryItems: [URLQueryItem]?) -> URLRequest

func performRequest(_ urlRequest: URLRequest) -> Future<Data>
}

extension HttpClient {
func prepareURLRequest(path: String, externalId: String?, email: String?, hmac: String?) -> URLRequest {
prepareURLRequest(path: path, externalId: externalId, email: email, hmac: hmac, additionalHTTPHeaders: [:])
prepareURLRequest(path: path, externalId: externalId, email: email, hmac: hmac, additionalHTTPHeaders: nil, queryItems: nil)
}

func prepareURLRequest(path: String, externalId: String?, email: String?, hmac: String?, additionalHTTPHeaders: [String: String]?) -> URLRequest {
prepareURLRequest(path: path, externalId: externalId, email: email, hmac: hmac, additionalHTTPHeaders: additionalHTTPHeaders, queryItems: nil)
}

func prepareURLRequest(path: String, externalId: String?, email: String?, hmac: String?, queryItems: [URLQueryItem]?) -> URLRequest {
prepareURLRequest(path: path, externalId: externalId, email: email, hmac: hmac, additionalHTTPHeaders: nil, queryItems: queryItems)
}
}

Expand All @@ -34,8 +44,10 @@ class DefaultHttpClient: HttpClient {
self.environment = environment
}

func prepareURLRequest(path: String, externalId: String?, email: String?, hmac: String?, additionalHTTPHeaders: [String: String]?) -> URLRequest {
var urlRequest = URLRequest(url: environment.baseUrl.appendingPathComponent(path))
func prepareURLRequest(path: String, externalId: String?, email: String?, hmac: String?, additionalHTTPHeaders: [String: String]? = nil, queryItems: [URLQueryItem]? = nil) -> URLRequest {
var urlComponents = URLComponents(url:environment.baseUrl.appendingPathComponent(path), resolvingAgainstBaseURL: false)!
urlComponents.queryItems = queryItems
var urlRequest = URLRequest(url: urlComponents.url!)

urlRequest.addValue(environment.apiKey, forHTTPHeaderField: "X-MAGICBELL-API-KEY")

Expand Down
Loading
Loading