2019-06-14 00:53:17 +00:00
// P r e f e r e n c e s V i e w . s w i f t
// T u s k e r
//
// C r e a t e d b y S h a d o w f a c t s o n 6 / 1 3 / 1 9 .
// C o p y r i g h t © 2 0 1 9 S h a d o w f a c t s . A l l r i g h t s r e s e r v e d .
//
import SwiftUI
2020-01-19 03:43:10 +00:00
struct PreferencesView : View {
@ ObservedObject var localData = LocalData . shared
2019-09-16 17:12:23 +00:00
@ State private var showingLogoutConfirmation = false
2020-01-19 16:52:06 +00:00
2019-06-14 00:53:17 +00:00
var body : some View {
// w o r k a r o u n d : t h e n a v i g a t i o n v i e w i s p r o v i d e d b y M y P r o f i l e T a b l e V i e w C o n t r o l l e r s o t h a t i t c a n i n j e c t t h e D o n e b u t t o n
// N a v i g a t i o n V i e w {
List {
2019-09-16 17:12:23 +00:00
Section {
2020-01-19 03:43:10 +00:00
ForEach ( localData . accounts , id : \ . accessToken ) { ( account ) in
Button ( action : {
NotificationCenter . default . post ( name : . activateAccount , object : nil , userInfo : [ " account " : account ] )
} ) {
HStack {
Text ( account . username )
. foregroundColor ( . primary )
Spacer ( )
2020-01-19 16:52:06 +00:00
if account = = self . localData . getMostRecentAccount ( ) {
2020-01-19 03:43:10 +00:00
Image ( systemName : " checkmark " )
. renderingMode ( . template )
. foregroundColor ( . secondary )
}
}
}
}
2019-09-16 17:12:23 +00:00
Button ( action : {
2020-01-19 03:43:10 +00:00
NotificationCenter . default . post ( name : . addAccount , object : nil )
2019-09-16 17:12:23 +00:00
} ) {
2020-01-19 03:43:10 +00:00
Text ( " Add Account... " )
}
2020-01-19 16:52:06 +00:00
if localData . getMostRecentAccount ( ) != nil {
2020-01-19 03:43:10 +00:00
Button ( action : {
self . showingLogoutConfirmation = true
} ) {
Text ( " Logout from current " )
} . alert ( isPresented : $ showingLogoutConfirmation ) {
Alert ( title : Text ( " Are you sure you want to logout? " ) , message : nil , primaryButton : . destructive ( Text ( " Logout " ) , action : self . logoutPressed ) , secondaryButton : . cancel ( ) )
}
2019-09-16 17:12:23 +00:00
}
2019-06-14 00:53:17 +00:00
}
2019-09-16 17:12:23 +00:00
Section {
NavigationLink ( destination : AppearancePrefsView ( ) ) {
Text ( " Appearance " )
}
NavigationLink ( destination : BehaviorPrefsView ( ) ) {
Text ( " Behavior " )
}
NavigationLink ( destination : WellnessPrefsView ( ) ) {
Text ( " Digital Wellness " )
}
NavigationLink ( destination : AdvancedPrefsView ( ) ) {
Text ( " Advanced " )
}
2019-06-14 00:53:17 +00:00
}
}
2019-08-06 03:08:00 +00:00
. listStyle ( GroupedListStyle ( ) )
2019-06-14 00:53:17 +00:00
. navigationBarTitle ( Text ( " Preferences " ) , displayMode : . inline )
2019-08-03 00:05:47 +00:00
. onDisappear {
// t o d o : t h i s o n D i s a p p e a r c a l l b a c k i s n o t c a l l e d i n b e t a 4 , c h e c k a g a i n i n b e t a 5
NotificationCenter . default . post ( name : . preferencesChanged , object : nil )
}
2019-06-14 00:53:17 +00:00
// }
}
2019-09-16 17:12:23 +00:00
func logoutPressed ( ) {
NotificationCenter . default . post ( name : . userLoggedOut , object : nil )
}
2019-06-14 00:53:17 +00:00
}
#if DEBUG
struct PreferencesView_Previews : PreviewProvider {
static var previews : some View {
2020-01-19 03:43:10 +00:00
return PreferencesView ( )
2019-06-14 00:53:17 +00:00
}
}
#endif