2020-12-05 14:09:34 +01:00
//
// A d d F e e d l y A c c o u n t V i e w . s w i f t
// M u l t i p l a t f o r m m a c O S
//
// C r e a t e d b y S t u a r t B r e c k e n r i d g e o n 0 5 / 1 2 / 2 0 2 0 .
// C o p y r i g h t © 2 0 2 0 R a n c h e r o S o f t w a r e . A l l r i g h t s r e s e r v e d .
//
import SwiftUI
import Account
import RSCore
import RSWeb
import Secrets
struct AddFeedlyAccountView : View {
@ Environment ( \ . presentationMode ) var presentationMode
@ StateObject private var model = AddFeedlyViewModel ( )
var body : some View {
2020-12-05 15:58:11 +01:00
#if os ( macOS )
macBody
#else
NavigationView {
iosBody
}
#endif
}
#if os ( iOS )
var iosBody : some View {
2020-12-07 12:22:35 +01:00
List {
Section ( header : formHeader , footer : formFooter , content : {
Button ( action : {
model . authenticateFeedly ( )
} , label : {
HStack {
Spacer ( )
Text ( " Add Account " )
Spacer ( )
}
} )
} )
} . navigationBarItems ( leading :
Button ( action : {
presentationMode . wrappedValue . dismiss ( )
} , label : {
Text ( " Cancel " )
} )
)
. navigationBarTitleDisplayMode ( . inline )
. navigationTitle ( Text ( AccountType . feedly . localizedAccountName ( ) ) )
. listStyle ( InsetGroupedListStyle ( ) )
2020-12-05 15:58:11 +01:00
}
#endif
#if os ( macOS )
var macBody : some View {
2020-12-05 14:09:34 +01:00
VStack {
HStack ( spacing : 16 ) {
VStack ( alignment : . leading ) {
AccountType . feedly . image ( )
. resizable ( )
. frame ( width : 50 , height : 50 )
Spacer ( )
}
VStack ( alignment : . leading , spacing : 8 ) {
Text ( " Sign in to your Feedly account. " )
. font ( . headline )
HStack {
2021-06-01 01:01:01 +02:00
Text ( " Don’ t have a Feedly account? " )
2020-12-05 14:09:34 +01:00
. font ( . callout )
Button ( action : {
2020-12-06 00:58:20 +01:00
model . presentSignUpOption ( . feedly )
2020-12-05 14:09:34 +01:00
} , label : {
Text ( " Sign up here. " ) . font ( . callout )
} ) . buttonStyle ( LinkButtonStyle ( ) )
}
Spacer ( )
HStack ( spacing : 8 ) {
Spacer ( )
Button ( action : {
presentationMode . wrappedValue . dismiss ( )
} , label : {
Text ( " Cancel " )
. frame ( width : 60 )
} ) . keyboardShortcut ( . cancelAction )
Button ( action : {
2020-12-06 00:58:20 +01:00
model . authenticateFeedly ( )
2020-12-05 14:09:34 +01:00
presentationMode . wrappedValue . dismiss ( )
} , label : {
Text ( " Sign In " )
. frame ( width : 60 )
} )
. keyboardShortcut ( . defaultAction )
. disabled ( AccountManager . shared . activeAccounts . filter ( { $0 . type = = . cloudKit } ) . count > 0 )
}
}
}
}
. padding ( )
. frame ( minWidth : 400 , maxWidth : 400 , maxHeight : 150 )
. alert ( isPresented : $ model . showError , content : {
Alert ( title : Text ( " Sign In Error " ) , message : Text ( model . accountUpdateError . description ) , dismissButton : . cancel ( ) )
} )
}
2020-12-05 15:58:11 +01:00
#endif
2020-12-07 12:22:35 +01:00
var formHeader : some View {
HStack {
Spacer ( )
VStack ( alignment : . center ) {
AccountType . feedly . image ( )
. resizable ( )
. frame ( width : 50 , height : 50 )
}
Spacer ( )
} . padding ( . vertical )
}
var formFooter : some View {
HStack {
Spacer ( )
VStack ( spacing : 8 ) {
2021-06-01 01:01:01 +02:00
Text ( " Sign in to your Feedly account and sync your feeds across your devices. Your username and password will be encrypted and stored in Keychain. \n \n Don’ t have an Feedly account? " ) . foregroundColor ( . secondary )
2020-12-07 12:22:35 +01:00
Button ( action : {
model . presentSignUpOption ( . feedly )
} , label : {
Text ( " Sign Up Here " ) . foregroundColor ( . blue ) . multilineTextAlignment ( . center )
} )
}
. multilineTextAlignment ( . center )
. font ( . caption )
Spacer ( )
} . padding ( . vertical )
}
2020-12-05 15:58:11 +01:00
2020-12-05 14:09:34 +01:00
}
struct AddFeedlyAccountView_Previews : PreviewProvider {
static var previews : some View {
AddFeedlyAccountView ( )
}
}