Skip to content

Commit 4002d85

Browse files
demo improvements
1 parent 8a278a1 commit 4002d85

File tree

6 files changed

+49
-19
lines changed

6 files changed

+49
-19
lines changed

Demo/GRDB Demo/GRDB Demo.xcodeproj/project.pbxproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,17 @@
437437
DEVELOPMENT_TEAM = ZGT7463CVJ;
438438
ENABLE_APP_SANDBOX = YES;
439439
ENABLE_HARDENED_RUNTIME = YES;
440+
ENABLE_INCOMING_NETWORK_CONNECTIONS = NO;
441+
ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES;
440442
ENABLE_PREVIEWS = YES;
443+
ENABLE_RESOURCE_ACCESS_AUDIO_INPUT = NO;
444+
ENABLE_RESOURCE_ACCESS_BLUETOOTH = NO;
445+
ENABLE_RESOURCE_ACCESS_CALENDARS = NO;
446+
ENABLE_RESOURCE_ACCESS_CAMERA = NO;
447+
ENABLE_RESOURCE_ACCESS_CONTACTS = NO;
448+
ENABLE_RESOURCE_ACCESS_LOCATION = NO;
449+
ENABLE_RESOURCE_ACCESS_PRINTING = NO;
450+
ENABLE_RESOURCE_ACCESS_USB = NO;
441451
ENABLE_USER_SELECTED_FILES = readonly;
442452
GENERATE_INFOPLIST_FILE = YES;
443453
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
@@ -481,7 +491,17 @@
481491
DEVELOPMENT_TEAM = ZGT7463CVJ;
482492
ENABLE_APP_SANDBOX = YES;
483493
ENABLE_HARDENED_RUNTIME = YES;
494+
ENABLE_INCOMING_NETWORK_CONNECTIONS = NO;
495+
ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES;
484496
ENABLE_PREVIEWS = YES;
497+
ENABLE_RESOURCE_ACCESS_AUDIO_INPUT = NO;
498+
ENABLE_RESOURCE_ACCESS_BLUETOOTH = NO;
499+
ENABLE_RESOURCE_ACCESS_CALENDARS = NO;
500+
ENABLE_RESOURCE_ACCESS_CAMERA = NO;
501+
ENABLE_RESOURCE_ACCESS_CONTACTS = NO;
502+
ENABLE_RESOURCE_ACCESS_LOCATION = NO;
503+
ENABLE_RESOURCE_ACCESS_PRINTING = NO;
504+
ENABLE_RESOURCE_ACCESS_USB = NO;
485505
ENABLE_USER_SELECTED_FILES = readonly;
486506
GENERATE_INFOPLIST_FILE = YES;
487507
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;

Demo/GRDB Demo/GRDB Demo/Data/Todo.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import PowerSync
66
let todosTable = Table(
77
name: "todos",
88
columns: [
9-
.text("name"),
9+
.text("description"),
1010
.text("list_id"),
1111
// Conversion should automatically be handled by GRDB
1212
.integer("completed"),
@@ -16,7 +16,7 @@ let todosTable = Table(
1616

1717
struct Todo: Codable, Equatable, Identifiable, FetchableRecord, PersistableRecord {
1818
var id: String
19-
var name: String
19+
var description: String
2020
var listId: String
2121
var isCompleted: Bool
2222
var completedAt: Date?
@@ -25,15 +25,15 @@ struct Todo: Codable, Equatable, Identifiable, FetchableRecord, PersistableRecor
2525

2626
enum CodingKeys: String, CodingKey {
2727
case id
28-
case name
28+
case description
2929
case listId = "list_id"
3030
case isCompleted = "completed"
3131
case completedAt = "completed_at"
3232
}
3333

3434
enum Columns {
3535
static let id = Column(CodingKeys.id)
36-
static let name = Column(CodingKeys.name)
36+
static let description = Column(CodingKeys.description)
3737
static let listId = Column(CodingKeys.listId)
3838
static let isCompleted = Column(CodingKeys.isCompleted)
3939
static let completedAt = Column(CodingKeys.completedAt)

Demo/GRDB Demo/GRDB Demo/Models/TodosViewModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct ListsTodosRequest: ValueObservationQueryable {
1212
func fetch(_ database: Database) throws -> [Todo] {
1313
try Todo
1414
.filter(Todo.Columns.listId == list.id)
15-
.order(Todo.Columns.name)
15+
.order(Todo.Columns.description)
1616
.order(Todo.Columns.isCompleted)
1717
.fetchAll(database)
1818
}
@@ -36,7 +36,7 @@ class TodoViewModel {
3636
try grdb.write { database in
3737
try Todo(
3838
id: UUID().uuidString,
39-
name: name,
39+
description: name,
4040
listId: listId,
4141
isCompleted: false
4242
).insert(database)

Demo/GRDB Demo/GRDB Demo/Screens/StatusIndicatorView.swift

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,27 @@ struct StatusIndicatorView<Content: View>: View {
99
}
1010

1111
@State var statusImageName: String = "wifi.slash"
12-
@State private var showErrorAlert = false
12+
@State var directionStatusImageName: String?
1313

1414
let content: () -> Content
1515

1616
var body: some View {
1717
content()
1818
.toolbar {
19-
ToolbarItem(placement: .navigationBarTrailing) {
19+
ToolbarItem(placement: .automatic) {
2020
Button {
21-
if powerSync.currentStatus.anyError != nil {
22-
showErrorAlert = true
21+
if let error = powerSync.currentStatus.anyError {
22+
viewModels.errorViewModel.report("\(error)")
2323
}
2424
} label: {
25-
Image(systemName: statusImageName)
25+
ZStack {
26+
// Network status
27+
Image(systemName: statusImageName)
28+
// Upload/Download status
29+
if let name = directionStatusImageName {
30+
Image(systemName: name)
31+
}
32+
}
2633
}
2734
.contextMenu {
2835
if powerSync.currentStatus.connected || powerSync.currentStatus.connecting {
@@ -43,13 +50,6 @@ struct StatusIndicatorView<Content: View>: View {
4350
}
4451
}
4552
}
46-
.alert(isPresented: $showErrorAlert) {
47-
Alert(
48-
title: Text("Error"),
49-
message: Text(String("\(powerSync.currentStatus.anyError ?? "Unknown error")")),
50-
dismissButton: .default(Text("OK"))
51-
)
52-
}
5353
.task {
5454
do {
5555
for try await status in powerSync.currentStatus.asFlow() {
@@ -62,6 +62,14 @@ struct StatusIndicatorView<Content: View>: View {
6262
} else {
6363
statusImageName = "wifi.slash"
6464
}
65+
66+
if status.downloading {
67+
directionStatusImageName = "chevron.down.2"
68+
} else if status.uploading {
69+
directionStatusImageName = "chevron.up.2"
70+
} else {
71+
directionStatusImageName = nil
72+
}
6573
}
6674
} catch {
6775
print("Could not monitor status")

Demo/GRDB Demo/GRDB Demo/Screens/signin/SigninScreen.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ struct SigninScreen: View {
3838
VStack(spacing: 16) {
3939
TextField("Email", text: $email)
4040
.textFieldStyle(RoundedBorderTextFieldStyle())
41+
#if os (iOS) || os (tvOS) || targetEnvironment(macCatalyst)
4142
.autocapitalization(.none)
4243
.keyboardType(.emailAddress)
44+
#endif
4345
.focused($emailFieldFocused)
4446

4547
SecureField("Password", text: $password)

Demo/GRDB Demo/GRDB Demo/Screens/todos/TodoItemView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct TodoItemView: View {
1616
var body: some View {
1717
VStack {
1818
HStack {
19-
Text(todo.name).font(.title)
19+
Text(todo.description).font(.title)
2020
Spacer()
2121
Button {
2222
try? viewModels.todoViewModel.toggleCompleted(todo: todo)

0 commit comments

Comments
 (0)