Add subscriptions import/export navigation link with list
- refactors export/import action sheet to be a new screen with list options
This commit is contained in:
parent
75b9264d44
commit
cb409728aa
|
@ -44,8 +44,6 @@ enum FeedsSettingsError: LocalizedError, Equatable {
|
||||||
}
|
}
|
||||||
|
|
||||||
class FeedsSettingsModel: ObservableObject {
|
class FeedsSettingsModel: ObservableObject {
|
||||||
@Published var showingImportActionSheet = false
|
|
||||||
@Published var showingExportActionSheet = false
|
|
||||||
@Published var exportingFilePath = ""
|
@Published var exportingFilePath = ""
|
||||||
@Published var feedsSettingsError: FeedsSettingsError? {
|
@Published var feedsSettingsError: FeedsSettingsError? {
|
||||||
didSet {
|
didSet {
|
||||||
|
@ -54,25 +52,12 @@ class FeedsSettingsModel: ObservableObject {
|
||||||
}
|
}
|
||||||
@Published var showError: Bool = false
|
@Published var showError: Bool = false
|
||||||
|
|
||||||
func onTapExportOPML(action: ((Account?) -> Void)) {
|
func checkForActiveAccount() -> Bool {
|
||||||
if AccountManager.shared.accounts.count == 1 {
|
if AccountManager.shared.activeAccounts.count == 0 {
|
||||||
action(AccountManager.shared.accounts.first)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
showingExportActionSheet = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func onTapImportOPML(action: ((Account?) -> Void)) {
|
|
||||||
switch AccountManager.shared.activeAccounts.count {
|
|
||||||
case 0:
|
|
||||||
feedsSettingsError = .noActiveAccount
|
feedsSettingsError = .noActiveAccount
|
||||||
return
|
return false
|
||||||
case 1:
|
|
||||||
action(AccountManager.shared.activeAccounts.first)
|
|
||||||
default:
|
|
||||||
showingImportActionSheet = true
|
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateExportURL(for account: Account) -> URL? {
|
func generateExportURL(for account: Account) -> URL? {
|
||||||
|
|
|
@ -46,6 +46,15 @@ class SettingsModel: ObservableObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var activeAccounts: [Account] {
|
||||||
|
get {
|
||||||
|
AccountManager.shared.sortedActiveAccounts
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Init
|
// MARK: Init
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
|
|
@ -75,20 +75,31 @@ struct SettingsView: View {
|
||||||
|
|
||||||
var importExport: some View {
|
var importExport: some View {
|
||||||
Section(header: Text("Feeds"), content: {
|
Section(header: Text("Feeds"), content: {
|
||||||
|
if viewModel.activeAccounts.count > 1 {
|
||||||
|
NavigationLink("Import Subscriptions", destination: importOptions)
|
||||||
|
}
|
||||||
|
else {
|
||||||
Button(action:{
|
Button(action:{
|
||||||
feedsSettingsModel.onTapImportOPML(action: importOPML)
|
if feedsSettingsModel.checkForActiveAccount() {
|
||||||
|
importOPML(account: viewModel.activeAccounts.first)
|
||||||
|
}
|
||||||
}) {
|
}) {
|
||||||
Text("Import Subscriptions")
|
Text("Import Subscriptions")
|
||||||
.actionSheet(isPresented: $feedsSettingsModel.showingImportActionSheet, content: importActionSheet)
|
|
||||||
.foregroundColor(.primary)
|
.foregroundColor(.primary)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if viewModel.accounts.count > 1 {
|
||||||
|
NavigationLink("Export Subscriptions", destination: exportOptions)
|
||||||
|
}
|
||||||
|
else {
|
||||||
Button(action:{
|
Button(action:{
|
||||||
feedsSettingsModel.onTapExportOPML(action: exportOPML)
|
exportOPML(account: viewModel.accounts.first)
|
||||||
}) {
|
}) {
|
||||||
Text("Export Subscriptions")
|
Text("Export Subscriptions")
|
||||||
.actionSheet(isPresented: $feedsSettingsModel.showingExportActionSheet, content: exportActionSheet)
|
|
||||||
.foregroundColor(.primary)
|
.foregroundColor(.primary)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.alert(isPresented: $feedsSettingsModel.showError) {
|
.alert(isPresented: $feedsSettingsModel.showError) {
|
||||||
Alert(
|
Alert(
|
||||||
|
@ -98,33 +109,38 @@ struct SettingsView: View {
|
||||||
feedsSettingsModel.feedsSettingsError = FeedsSettingsError.none
|
feedsSettingsModel.feedsSettingsError = FeedsSettingsError.none
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func importActionSheet() -> ActionSheet {
|
var importOptions: some View {
|
||||||
var buttons = viewModel.accounts.map { (account) -> ActionSheet.Button in
|
List {
|
||||||
ActionSheet.Button.default(Text(account.nameForDisplay)) {
|
Section(header: Text("Choose an account to receive the imported feeds and folders"), content: {
|
||||||
importOPML(account: account)
|
ForEach(0..<viewModel.activeAccounts.count, id: \.hashValue , content: { i in
|
||||||
|
Button {
|
||||||
|
importOPML(account: viewModel.activeAccounts[i])
|
||||||
|
} label: {
|
||||||
|
Text(viewModel.activeAccounts[i].nameForDisplay)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
buttons.append(.cancel())
|
.listStyle(InsetGroupedListStyle())
|
||||||
return ActionSheet(
|
.navigationBarTitle("Import Subscriptions", displayMode: .inline)
|
||||||
title: Text("Choose an account to receive the imported feeds and folders"),
|
|
||||||
buttons: buttons
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func exportActionSheet() -> ActionSheet {
|
var exportOptions: some View {
|
||||||
var buttons = viewModel.accounts.map { (account) -> ActionSheet.Button in
|
List {
|
||||||
ActionSheet.Button.default(Text(account.nameForDisplay)) {
|
Section(header: Text("Choose an account with the subscriptions to export"), content: {
|
||||||
exportOPML(account: account)
|
ForEach(0..<viewModel.accounts.count, id: \.hashValue , content: { i in
|
||||||
|
Button {
|
||||||
|
exportOPML(account: viewModel.accounts[i])
|
||||||
|
} label: {
|
||||||
|
Text(viewModel.accounts[i].nameForDisplay)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
buttons.append(.cancel())
|
.listStyle(InsetGroupedListStyle())
|
||||||
return ActionSheet(
|
.navigationBarTitle("Export Subscriptions", displayMode: .inline)
|
||||||
title: Text("Choose an account with the subscriptions to export"),
|
|
||||||
buttons: buttons
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var timeline: some View {
|
var timeline: some View {
|
||||||
|
|
Loading…
Reference in New Issue