tangled
alpha
login
or
join now
coreyja.com
/
backup-blue
1
fork
atom
this repo has no description
1
fork
atom
overview
issues
pulls
pipelines
Select account when added
Corey Alexander
4 months ago
27a9e49b
f88d5ddf
+14
-7
1 changed file
expand all
collapse all
unified
split
AtProtoBackup
ContentView.swift
+14
-7
AtProtoBackup/ContentView.swift
···
15
@State private var inputText = ""
16
@State private var isLoading = false
17
@State private var errorMessage: String?
0
18
19
var body: some View {
20
NavigationSplitView {
21
-
List {
22
ForEach(items) { item in
23
-
NavigationLink {
24
-
AccountDetailView(account: item)
25
-
} label: {
26
-
AccountListItemView(account: item)
27
-
}
28
}
29
.onDelete(perform: deleteItems)
30
}
···
44
}
45
}
46
} detail: {
47
-
Text("Select an item")
0
0
0
0
0
48
}
49
.onAppear {
50
discoverAndAddBackedUpAccounts()
···
96
let account = Account(did: parsed.did, handle: inputText, pds: parsed.pds, jsonResponse: jsonData)
97
modelContext.insert(account)
98
print("[ContentView] Account inserted into modelContext")
0
0
0
0
99
}
100
showingAlert = false
101
inputText = ""
···
15
@State private var inputText = ""
16
@State private var isLoading = false
17
@State private var errorMessage: String?
18
+
@State private var selectedAccount: PersistentIdentifier?
19
20
var body: some View {
21
NavigationSplitView {
22
+
List(selection: $selectedAccount) {
23
ForEach(items) { item in
24
+
AccountListItemView(account: item)
25
+
.tag(item.id)
0
0
0
26
}
27
.onDelete(perform: deleteItems)
28
}
···
42
}
43
}
44
} detail: {
45
+
if let selectedId = selectedAccount,
46
+
let account = items.first(where: { $0.id == selectedId }) {
47
+
AccountDetailView(account: account)
48
+
} else {
49
+
Text("Select an item")
50
+
}
51
}
52
.onAppear {
53
discoverAndAddBackedUpAccounts()
···
99
let account = Account(did: parsed.did, handle: inputText, pds: parsed.pds, jsonResponse: jsonData)
100
modelContext.insert(account)
101
print("[ContentView] Account inserted into modelContext")
102
+
103
+
// Auto-select the newly added account
104
+
selectedAccount = account.id
105
+
print("[ContentView] Auto-selected new account: \(account.id)")
106
}
107
showingAlert = false
108
inputText = ""