Skip to content

Commit ba2b1f2

Browse files
Update Project and Fix Location Edit Bug (#8)
1 parent 9d60f51 commit ba2b1f2

15 files changed

Lines changed: 265 additions & 151 deletions

File tree

.github/workflows/build-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: Check Swift version
3232
run: swift --version
3333
- name: Build and test
34-
run: xcodebuild test -scheme Xpense -destination 'platform=iOS Simulator,OS=15.0,name=iPhone 12'
34+
run: xcodebuild test -scheme Xpense -destination 'platform=iOS Simulator,name=iPhone 13 Pro'
3535
macoswebservice:
3636
name: macOS Web Service ${{ matrix.configuration }}
3737
runs-on: macos-11

App/Xpense/Account Subsystem/Edit Account/EditAccount.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ struct EditAccount: View {
3131
presentationMode.wrappedValue.dismiss()
3232
}
3333
}
34-
}.onAppear(perform: viewModel.updateStates)
34+
}.onAppear {
35+
Task {
36+
viewModel.updateStates()
37+
}
38+
}
3539
.navigationTitle(viewModel.id == nil ? "Add Account" : "Edit Account")
3640
.toolbar {
3741
SaveButton(viewModel: viewModel) {
@@ -93,7 +97,7 @@ private struct DeleteButton: View {
9397
Task {
9498
try await viewModel.delete()
9599

96-
DispatchQueue.main.async {
100+
Task(priority: .userInitiated) {
97101
onSuccess?()
98102
}
99103
}

App/Xpense/Account Subsystem/Edit Account/EditAccountViewModel.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ class EditAccountViewModel: ObservableObject {
4747
}
4848

4949

50+
@MainActor
51+
private func showDeleteProgressView(_ showDeleteProgressView: Bool) {
52+
self.showDeleteProgressView = showDeleteProgressView
53+
}
54+
5055
/// Updates the `EditViews`'s state like the name based on the `id`
56+
@MainActor
5157
func updateStates() {
5258
guard let account = model?.account(id) else {
5359
self.name = ""
@@ -65,12 +71,12 @@ class EditAccountViewModel: ObservableObject {
6571

6672
let account = Account(id: self.id, name: self.name, userID: userId)
6773

68-
self.showSaveProgressView = true
74+
await showDeleteProgressView(true)
6975

7076
try await model.save(account)
7177

72-
self.updateStates()
73-
self.showSaveProgressView = false
78+
await self.updateStates()
79+
await showDeleteProgressView(false)
7480
}
7581

7682
/// Deletes the `Account` that is currently edited
@@ -79,12 +85,12 @@ class EditAccountViewModel: ObservableObject {
7985
throw XpenseServiceError.deleteFailed(Account.self)
8086
}
8187

82-
self.showDeleteProgressView = true
88+
await showDeleteProgressView(true)
8389

8490
try await model.delete(account: id)
8591

86-
self.updateStates()
87-
self.showDeleteProgressView = false
92+
await self.updateStates()
93+
await showDeleteProgressView(false)
8894
}
8995
}
9096

App/Xpense/Account Subsystem/Edit Account/SaveButton.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct SaveButton<M: SaveButtonViewModel>: View {
4747
Task {
4848
try await viewModel.save()
4949

50-
DispatchQueue.main.async {
50+
Task(priority: .userInitiated) {
5151
onSuccess?()
5252
}
5353
}

App/Xpense/Location Subsystem/EditLocationView.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,7 @@ struct EditLocationView: View {
4242
}
4343
.font(.largeTitle)
4444
.foregroundColor(.red)
45-
}
46-
.navigationBarTitleDisplayMode(.inline)
47-
.onAppear {
48-
if let coordinate = coordinate {
49-
coordinateRegion.center = coordinate
50-
coordinateRegion.span = LocationView.Defaults.span
51-
}
52-
}
45+
}.ignoresSafeArea(edges: .bottom)
5346
.toolbar {
5447
ToolbarItem(placement: .cancellationAction) {
5548
Button("Cancel") {
@@ -63,6 +56,13 @@ struct EditLocationView: View {
6356
}
6457
}
6558
}
59+
.onAppear {
60+
if let coordinate = coordinate {
61+
coordinateRegion.center = coordinate
62+
coordinateRegion.span = LocationView.Defaults.span
63+
}
64+
}
65+
.navigationBarTitleDisplayMode(.inline)
6666
}
6767
}
6868
}

App/Xpense/Transaction Subsystem/Edit Transaction/EditTransaction.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ struct EditTransaction: View {
3636
var body: some View {
3737
NavigationView {
3838
self.form
39-
.onAppear(perform: viewModel.updateStates)
39+
.onAppear {
40+
Task {
41+
viewModel.updateStates()
42+
}
43+
}
4044
.navigationBarTitle(navigationTitle, displayMode: .inline)
4145
.toolbar {
4246
ToolbarItem(placement: .primaryAction) {

App/Xpense/Transaction Subsystem/Edit Transaction/EditTransactionViewModel.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ class EditTransactionViewModel: ObservableObject {
5757
}
5858

5959

60+
@MainActor
61+
private func showSaveProgressView(_ showSaveProgressView: Bool) {
62+
self.showSaveProgressView = showSaveProgressView
63+
}
64+
6065
/// Updates the `EditTransaction`'s state like the name based on the `id`
66+
@MainActor
6167
func updateStates() {
6268
guard let transaction = model?.transaction(id), !loaded else {
6369
return
@@ -92,12 +98,12 @@ class EditTransactionViewModel: ObservableObject {
9298
location: Coordinate(location),
9399
account: selectedAccount)
94100

95-
self.showSaveProgressView = true
101+
await showSaveProgressView(true)
96102

97103
try await model.save(transaction)
98104

99-
self.updateStates()
100-
self.showSaveProgressView = false
105+
await self.updateStates()
106+
await showSaveProgressView(false)
101107
}
102108
}
103109

App/Xpense/User Subsystem/Login/ViewModel/LoginViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class LoginViewModel: ObservableObject {
107107
try await model?.signUp(username, password: password)
108108
}
109109

110-
DispatchQueue.main.async {
110+
Task(priority: .userInitiated) {
111111
self.loadingInProcess = false
112112
}
113113
}

Shared/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Shared/Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ let package = Package(
2323
.library(name: "RESTfulXpenseModel", targets: ["RESTfulXpenseModel"])
2424
],
2525
dependencies: [
26-
.package(url: "https://github.com/apple/swift-argument-parser", from: "0.4.4"),
27-
.package(url: "https://github.com/apple/swift-crypto.git", from: "1.1.6")
26+
.package(url: "https://github.com/apple/swift-argument-parser", from: "0.4.0"),
27+
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "3.0.0")
2828
],
2929
targets: [
3030
.executableTarget(

0 commit comments

Comments
 (0)