this repo has no description

Select account when added

+14 -7
+14 -7
AtProtoBackup/ContentView.swift
··· 15 15 @State private var inputText = "" 16 16 @State private var isLoading = false 17 17 @State private var errorMessage: String? 18 + @State private var selectedAccount: PersistentIdentifier? 18 19 19 20 var body: some View { 20 21 NavigationSplitView { 21 - List { 22 + List(selection: $selectedAccount) { 22 23 ForEach(items) { item in 23 - NavigationLink { 24 - AccountDetailView(account: item) 25 - } label: { 26 - AccountListItemView(account: item) 27 - } 24 + AccountListItemView(account: item) 25 + .tag(item.id) 28 26 } 29 27 .onDelete(perform: deleteItems) 30 28 } ··· 44 42 } 45 43 } 46 44 } detail: { 47 - Text("Select an item") 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 + } 48 51 } 49 52 .onAppear { 50 53 discoverAndAddBackedUpAccounts() ··· 96 99 let account = Account(did: parsed.did, handle: inputText, pds: parsed.pds, jsonResponse: jsonData) 97 100 modelContext.insert(account) 98 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)") 99 106 } 100 107 showingAlert = false 101 108 inputText = ""