mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Fix account selection showing wrong sheet upon selection
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// SettingsAddAccountModel.swift
|
||||
// Multiplatform iOS
|
||||
//
|
||||
// Created by Rizwan on 09/07/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
|
||||
class SettingsAddAccountModel: ObservableObject {
|
||||
|
||||
struct SettingsAddAccount: Identifiable {
|
||||
var id: Int { accountType.rawValue }
|
||||
|
||||
let name: String
|
||||
let accountType: AccountType
|
||||
|
||||
var image: RSImage {
|
||||
AppAssets.image(for: accountType)!
|
||||
}
|
||||
}
|
||||
|
||||
@Published var accounts: [SettingsAddAccount] = []
|
||||
@Published var isAddPresented = false
|
||||
@Published var selectedAccountType: AccountType? = nil {
|
||||
didSet {
|
||||
selectedAccountType != nil ? (isAddPresented = true) : (isAddPresented = false)
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
self.accounts = [
|
||||
SettingsAddAccount(name: Account.defaultLocalAccountName, accountType: .onMyMac),
|
||||
SettingsAddAccount(name: "Feedbin", accountType: .feedbin)
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,36 +10,27 @@ import SwiftUI
|
||||
import Account
|
||||
|
||||
struct SettingsAddAccountView: View {
|
||||
@State private var isAddPresented = false
|
||||
@State private var selectedAccountType: AccountType = .onMyMac
|
||||
@StateObject private var model = SettingsAddAccountModel()
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
Button(action: {
|
||||
self.selectedAccountType = AccountType.onMyMac
|
||||
self.isAddPresented = true
|
||||
}) {
|
||||
SettingsAccountLabelView(
|
||||
accountImage: AppAssets.image(for: .onMyMac),
|
||||
accountLabel: Account.defaultLocalAccountName
|
||||
)
|
||||
}
|
||||
Button(action: {
|
||||
self.selectedAccountType = AccountType.feedbin
|
||||
self.isAddPresented = true
|
||||
}) {
|
||||
SettingsAccountLabelView(
|
||||
accountImage: AppAssets.image(for: .feedbin),
|
||||
accountLabel: "Feedbin"
|
||||
)
|
||||
ForEach(model.accounts) { account in
|
||||
Button(action: {
|
||||
model.selectedAccountType = account.accountType
|
||||
}) {
|
||||
SettingsAccountLabelView(
|
||||
accountImage: account.image,
|
||||
accountLabel: account.name
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
.sheet(isPresented: $isAddPresented) {
|
||||
if selectedAccountType == .onMyMac {
|
||||
.sheet(isPresented: $model.isAddPresented) {
|
||||
if model.selectedAccountType == .onMyMac {
|
||||
SettingsLocalAccountView()
|
||||
}
|
||||
if selectedAccountType == .feedbin {
|
||||
if model.selectedAccountType == .feedbin {
|
||||
SettingsFeedbinAccountView()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user