@@ -29,24 +29,16 @@ struct CalendarsTab: View {
29
29
Spacer ( )
30
30
}
31
31
VStack ( spacing: 15 ) {
32
- Form {
33
- List {
34
- ForEach ( Array ( self . calendarsBySource. keys) , id: \. self) { source in
35
- Section ( header: Text ( source) ) {
36
- ForEach ( self . calendarsBySource [ source] !, id: \. ID) { calendar in
37
- CalendarRow ( title: calendar. title, isSelected: self . selectedCalendarIDs. contains ( calendar. ID) , color: Color ( calendar. color) ) {
38
- if self . selectedCalendarIDs. contains ( calendar. ID) {
39
- self . selectedCalendarIDs. removeAll { $0 == calendar. ID }
40
- } else {
41
- self . selectedCalendarIDs. append ( calendar. ID)
42
- }
43
- }
44
- }
32
+ List {
33
+ ForEach ( Array ( self . calendarsBySource. keys) , id: \. self) { source in
34
+ Section ( header: Text ( source) ) {
35
+ ForEach ( self . calendarsBySource [ source] !, id: \. ID) { calendar in
36
+ CalendarRow ( calendar: calendar)
45
37
}
46
38
}
47
- } . listStyle ( SidebarListStyle ( ) )
48
- }
49
- } . border ( Color . gray )
39
+ }
40
+ } . listStyle ( SidebarListStyle ( ) )
41
+ }
50
42
Divider ( )
51
43
52
44
VStack ( alignment: . leading) {
@@ -75,9 +67,9 @@ struct CalendarsTab: View {
75
67
}
76
68
} . padding ( . horizontal, 10 )
77
69
}
78
- } . onReceive ( timer) { _ in loadCalendarList ( ) }
70
+ } . padding ( )
71
+ . onReceive ( timer) { _ in loadCalendarList ( ) }
79
72
. onDisappear { timer. upstream. connect ( ) . cancel ( ) }
80
- . padding ( )
81
73
}
82
74
83
75
func changeEventStoreProvider( _ provider: EventStoreProvider ) {
@@ -121,24 +113,31 @@ struct AddAccountModal: View {
121
113
}
122
114
123
115
struct CalendarRow : View {
124
- var title : String
125
- var isSelected : Bool
126
- var color : Color
127
- var action : ( ) -> Void
116
+ var calendar : MBCalendar
117
+ @State var isSelected : Bool
118
+
119
+ init ( calendar: MBCalendar ) {
120
+ self . calendar = calendar
121
+ isSelected = Defaults [ . selectedCalendarIDs] . contains ( calendar. ID)
122
+ }
128
123
129
124
var body : some View {
130
- HStack {
131
- Button ( action: self . action) {
132
- Section {
133
- if self . isSelected {
134
- Image ( nsImage: NSImage ( named: NSImage . menuOnStateTemplateName) !)
135
- } else {
136
- Image ( nsImage: NSImage ( named: NSImage . addTemplateName) !)
137
- }
138
- } . frame ( width: 20 , height: 17 )
125
+ Toggle ( isOn: $isSelected) {
126
+ HStack {
127
+ Text ( " " )
128
+ Circle ( ) . fill ( Color ( calendar. color) ) . frame ( width: 10 , height: 10 )
129
+ Text ( calendar. title)
139
130
}
140
- Circle ( ) . fill ( self . color) . frame ( width: 8 , height: 8 )
141
- Text ( self . title)
142
- } . frame ( minWidth: 0 , maxWidth: . infinity, minHeight: 0 , maxHeight: . infinity, alignment: . topLeading)
131
+ }
132
+ . onAppear {
133
+ isSelected = Defaults [ . selectedCalendarIDs] . contains ( calendar. ID)
134
+ }
135
+ . onReceive ( [ self . isSelected] . publisher. first ( ) ) { newValue in
136
+ if newValue {
137
+ Defaults [ . selectedCalendarIDs] . append ( calendar. ID)
138
+ } else {
139
+ Defaults [ . selectedCalendarIDs] . removeAll { $0 == calendar. ID }
140
+ }
141
+ }
143
142
}
144
143
}
0 commit comments