2020-07-04 15:36:41 +02:00
|
|
|
//
|
|
|
|
// AddFolderView.swift
|
|
|
|
// NetNewsWire
|
|
|
|
//
|
|
|
|
// Created by Alex Faber on 04/07/2020.
|
|
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import Account
|
|
|
|
import RSCore
|
|
|
|
|
|
|
|
struct AddFolderView: View {
|
|
|
|
|
|
|
|
@ObservedObject private var viewModel = AddFolderModel()
|
2020-08-13 18:04:39 +02:00
|
|
|
@Binding var isPresented: Bool
|
2020-07-04 15:36:41 +02:00
|
|
|
|
2020-08-12 15:04:56 +02:00
|
|
|
var body: some View {
|
2020-07-04 15:36:41 +02:00
|
|
|
#if os(iOS)
|
|
|
|
iosForm
|
|
|
|
.onReceive(viewModel.$shouldDismiss, perform: {
|
|
|
|
dismiss in
|
|
|
|
if dismiss == true {
|
2020-08-13 18:04:39 +02:00
|
|
|
isPresented = false
|
2020-07-04 15:36:41 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
#else
|
|
|
|
macForm
|
|
|
|
.onReceive(viewModel.$shouldDismiss, perform: { dismiss in
|
|
|
|
if dismiss == true {
|
2020-08-13 18:04:39 +02:00
|
|
|
isPresented = false
|
2020-07-04 15:36:41 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#if os(iOS)
|
2020-08-13 16:25:34 +02:00
|
|
|
var iosForm: some View {
|
2020-07-04 15:36:41 +02:00
|
|
|
NavigationView {
|
|
|
|
Form {
|
|
|
|
Section {
|
|
|
|
TextField("Name", text: $viewModel.folderName)
|
|
|
|
}
|
|
|
|
Section {
|
|
|
|
accountPicker
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.navigationTitle("Add Folder")
|
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
|
|
.navigationBarItems(
|
|
|
|
leading:Button("Cancel", action: {
|
2020-08-13 18:04:39 +02:00
|
|
|
isPresented = false
|
2020-07-04 15:36:41 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
.help("Cancel Adding Folder"),
|
|
|
|
trailing:Button("Add", action: {
|
|
|
|
viewModel.addFolder()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.disabled(viewModel.folderName.isEmpty)
|
|
|
|
.help("Save Adding Folder")
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if os(macOS)
|
2020-08-13 16:25:34 +02:00
|
|
|
var macForm: some View {
|
2020-07-04 15:36:41 +02:00
|
|
|
Form {
|
|
|
|
HStack {
|
|
|
|
Spacer()
|
2020-07-09 20:31:37 +02:00
|
|
|
Image(rsImage: AppAssets.faviconTemplateImage)
|
2020-07-04 15:36:41 +02:00
|
|
|
.resizable()
|
|
|
|
.renderingMode(.template)
|
|
|
|
.frame(width: 30, height: 30)
|
|
|
|
Text("Add a Folder")
|
|
|
|
.font(.title)
|
|
|
|
Spacer()
|
|
|
|
}
|
2020-07-09 20:31:37 +02:00
|
|
|
|
|
|
|
LazyVGrid(columns: [GridItem(.fixed(75), spacing: 10, alignment: .trailing),GridItem(.fixed(400), spacing: 0, alignment: .leading) ], alignment: .leading, spacing: 10, pinnedViews: [], content:{
|
|
|
|
Text("Name:").bold()
|
|
|
|
TextField("Name", text: $viewModel.folderName)
|
|
|
|
.textFieldStyle(RoundedBorderTextFieldStyle())
|
|
|
|
.help("The name of the folder you want to create")
|
|
|
|
Text("Account:").bold()
|
|
|
|
accountPicker
|
|
|
|
.help("Pick the account you want to create a folder in.")
|
|
|
|
})
|
2020-07-04 15:36:41 +02:00
|
|
|
buttonStack
|
|
|
|
}
|
2020-07-09 20:31:37 +02:00
|
|
|
.frame(maxWidth: 485)
|
|
|
|
.padding(12)
|
2020-07-04 15:36:41 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
var accountPicker: some View {
|
|
|
|
Picker("Account:", selection: $viewModel.selectedAccountIndex, content: {
|
|
|
|
ForEach(0..<viewModel.accounts.count, id: \.self, content: { index in
|
|
|
|
Text("\(viewModel.accounts[index].account?.nameForDisplay ?? "")").tag(index)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var buttonStack: some View {
|
|
|
|
HStack {
|
|
|
|
if viewModel.showProgressIndicator == true {
|
|
|
|
ProgressView()
|
|
|
|
.frame(width: 25, height: 25)
|
|
|
|
.help("Adding Folder")
|
|
|
|
}
|
|
|
|
Spacer()
|
|
|
|
Button("Cancel", action: {
|
2020-08-13 18:04:39 +02:00
|
|
|
isPresented = false
|
2020-07-04 15:36:41 +02:00
|
|
|
})
|
|
|
|
.help("Cancel Adding Folder")
|
|
|
|
|
|
|
|
Button("Add", action: {
|
|
|
|
viewModel.addFolder()
|
|
|
|
})
|
|
|
|
.disabled(viewModel.folderName.isEmpty)
|
|
|
|
.help("Add Folder")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|