-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
50 medium widget #334
Open
aking618
wants to merge
21
commits into
mikaelacaron:dev
Choose a base branch
from
aking618:50-medium-widget
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
50 medium widget #334
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ab5ae85
Create basic medium view
aking618 e9e00fa
Fetch data into widget
aking618 812dea3
Load vehicles as configuarable options
aking618 1e0a141
Resolve swiftlint warnings
aking618 53fcf4e
Finish views for widget | Clean up Widget classes/structs
aking618 e546242
Move network calls into static functions
aking618 a9b96e1
Update gallery placeholder
aking618 c488c50
Create app group
aking618 7154d5e
Share user id with widget
aking618 d4da607
Add empty state for widget
aking618 fe7a950
Sort events by date
aking618 518ce0c
Entitlement clean up
aking618 dc273fb
Merge remote-tracking branch 'origin/dev' into 50-medium-widget
aking618 4a09d94
Merge remote-tracking branch 'origin/dev' into 50-medium-widget
aking618 b2f3448
Removing hanging entitlement file
aking618 d3e4605
Add doc comments to user default extension
aking618 272d553
Update entitlements reference for widget
aking618 5743a8b
Merge remote-tracking branch 'origin/dev' into 50-medium-widget
aking618 117ce4f
Widget respects Firebase Auth current user | Removed shared UserDefaults
aking618 0d05d65
Remove extra space
aking618 e601402
Reconnect firestore to widget
aking618 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Basic-Car-Maintenance-Widget/Basic-Car-Maintenance-WidgetExtension.entitlements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.developer.applesignin</key> | ||
<array> | ||
<string></string> | ||
</array> | ||
<key>keychain-access-groups</key> | ||
<array> | ||
<string>$(AppIdentifierPrefix)com.mikaelacaron.Shared</string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// Array+Demo.swift | ||
// Basic-Car-Maintenance | ||
// | ||
// https://github.com/mikaelacaron/Basic-Car-Maintenance | ||
// See LICENSE for license information. | ||
// | ||
|
||
extension Array where Element == MaintenanceEvent { | ||
static var demo: [MaintenanceEvent] { | ||
[ | ||
MaintenanceEvent( | ||
vehicleID: "", | ||
title: "Tire Rotation", | ||
date: .now, | ||
notes: "New shiny tires were installed." | ||
), | ||
MaintenanceEvent( | ||
vehicleID: "", | ||
title: "Oil Change", | ||
date: .now.advanced(by: -36000), | ||
notes: "The cabin air filter was also replaced." | ||
) | ||
] | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Basic-Car-Maintenance-Widget/Extensions/ConfiguartionAppIntent+Demo.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// ConfiguartionAppIntent+Demo.swift | ||
// Basic-Car-Maintenance | ||
// | ||
// https://github.com/mikaelacaron/Basic-Car-Maintenance | ||
// See LICENSE for license information. | ||
// | ||
|
||
extension ConfigurationAppIntent { | ||
static var demo: ConfigurationAppIntent { | ||
let intent = ConfigurationAppIntent() | ||
intent.selectedVehicle = VehicleAppEntity( | ||
id: "", | ||
displayString: "Hot Wheels", | ||
data: .init(name: "Kia Soul", make: "Kia", model: "Soul", year: "2015") | ||
) | ||
return intent | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>KeychainAccessGroup</key> | ||
<string>$(AppIdentifierPrefix)com.mikaelacaron.Shared</string> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question herea bout the format (as the widget extension question There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
<key>NSExtension</key> | ||
<dict> | ||
<key>NSExtensionPointIdentifier</key> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// | ||
// DataService.swift | ||
// Basic-Car-Maintenance | ||
// | ||
// https://github.com/mikaelacaron/Basic-Car-Maintenance | ||
// See LICENSE for license information. | ||
// | ||
|
||
import Firebase | ||
import FirebaseAuth | ||
|
||
enum DataService { | ||
/// Fetches maintenance events for the selected vehicle from Firestore. | ||
/// - Parameter vehichleID: The ID of the selected vehicle. | ||
/// - Returns: A list of maintenance events or an error if the fetch fails. | ||
/// | ||
/// Example usage: | ||
/// ```swift | ||
/// Task { | ||
/// let result = await DataService.fetchMaintenanceEvents(for: "vehicle123") | ||
/// | ||
/// switch result { | ||
/// case .success(let events): | ||
/// print("Fetched \(events.count) maintenance events.") | ||
/// case .failure(let error): | ||
/// print("Failed to fetch maintenance events with error: \(error.localizedDescription)") | ||
/// } | ||
/// } | ||
/// ``` | ||
static func fetchMaintenanceEvents(for vehichleID: String?) async -> Result<[MaintenanceEvent], Error> { | ||
guard let vehichleID else { | ||
return .failure(FetchError.noVehicleSelected) | ||
} | ||
|
||
do { | ||
let docRef = Firestore | ||
.firestore() | ||
.collection("\(FirestoreCollection.vehicles)/\(vehichleID)/\(FirestoreCollection.maintenanceEvents)") | ||
let snapshot = try await docRef.getDocuments() | ||
let events = snapshot.documents.compactMap { | ||
try? $0.data(as: MaintenanceEvent.self) | ||
}.sorted { $0.date > $1.date } | ||
|
||
return .success(events) | ||
} catch { | ||
return .failure(error) | ||
} | ||
} | ||
|
||
/// Fetches vehicles for the current user from Firestore. | ||
/// - Returns: A list of vehicles or an error if the fetch fails. | ||
/// | ||
/// Example usage: | ||
/// ```swift | ||
/// Task { | ||
/// let result = await DataService.fetchVehicles() | ||
/// | ||
/// switch result { | ||
/// case .success(let vehicles): | ||
/// print("Fetched \(vehicles.count) vehicles.") | ||
/// case .failure(let error): | ||
/// print("Failed to fetch vehicles with error: \(error.localizedDescription)") | ||
/// } | ||
/// } | ||
/// ``` | ||
static func fetchVehicles() async -> Result<[Vehicle], Error> { | ||
guard let userID = Auth.auth().currentUser?.uid else { | ||
return .failure(FetchError.unauthenticated) | ||
} | ||
|
||
let docRef = Firestore | ||
.firestore() | ||
.collection(FirestoreCollection.vehicles) | ||
.whereField(FirestoreField.userID, isEqualTo: userID) | ||
|
||
do { | ||
let snapshot = try await docRef.getDocuments() | ||
let vehicles = snapshot.documents.compactMap { | ||
try? $0.data(as: Vehicle.self) | ||
} | ||
return .success(vehicles) | ||
} catch { | ||
return .failure(error) | ||
} | ||
} | ||
} | ||
|
||
/// Errors that can occur when fetching maintenance events. | ||
enum FetchError: LocalizedError { | ||
case unauthenticated | ||
case noVehicleSelected | ||
|
||
var errorDescription: String { | ||
switch self { | ||
case .unauthenticated: | ||
"You are not logged in. Please log in to continue." | ||
case .noVehicleSelected: | ||
"No vehicle selected. Please select a vehicle to continue." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// VehicleAppEntity.swift | ||
// Basic-Car-Maintenance | ||
// | ||
// https://github.com/mikaelacaron/Basic-Car-Maintenance | ||
// See LICENSE for license information. | ||
// | ||
|
||
import Foundation | ||
import AppIntents | ||
|
||
struct VehicleAppEntity: AppEntity { | ||
var id: String | ||
var displayString: String | ||
var data: Vehicle | ||
|
||
var displayRepresentation: DisplayRepresentation { | ||
DisplayRepresentation(title: "\(displayString)") | ||
} | ||
|
||
static var typeDisplayRepresentation = TypeDisplayRepresentation(name: "Maintenance Vehicle") | ||
static var defaultQuery = VehicleAppEntityQuery() | ||
|
||
init(id: String, displayString: String, data: Vehicle) { | ||
self.id = id | ||
self.displayString = displayString | ||
self.data = data | ||
} | ||
} | ||
|
||
struct VehicleAppEntityQuery: EntityQuery { | ||
func entities( | ||
for identifiers: [VehicleAppEntity.ID] | ||
) async throws -> [VehicleAppEntity] { | ||
let result = await DataService.fetchVehicles() | ||
|
||
let vehicles = try result.get() | ||
return vehicles.map { | ||
VehicleAppEntity( | ||
id: $0.id ?? UUID().uuidString, | ||
displayString: $0.name, | ||
data: $0 | ||
) | ||
} | ||
} | ||
|
||
func suggestedEntities() async throws -> [VehicleAppEntity] { | ||
return try await entities(for: []) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this entitlement do? also should this be
.Shared
? as opposed to matching the bundle ID with the app nameand should there be a
.
between$(AppIdentifierPrefix)
andcom.mikaelacaron.Shared
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
.
is included in$(AppIdentifierPrefix)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change the
Shared
portion. It was a standard that I saw other devs using online.