mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
refactor(calendar): group calendars by accounts in settings
Calendars in the "Select Calendars" settings section are now grouped by their source account with color indicators, making it possible to distinguish calendars that share the same name across different accounts. Each account group header includes a toggle to select or deselect all calendars in that group.
This commit is contained in:
parent
6bc3af0431
commit
d39c61c475
5 changed files with 74 additions and 10 deletions
|
|
@ -2905,18 +2905,48 @@ struct CalendarSettings: View {
|
|||
}
|
||||
|
||||
Section(header: Text("Select Calendars")) {
|
||||
ForEach(calendarManager.allCalendars, id: \.id) { calendar in
|
||||
Toggle(isOn: Binding(
|
||||
get: { calendarManager.getCalendarSelected(calendar) },
|
||||
set: { isSelected in
|
||||
Task {
|
||||
await calendarManager.setCalendarSelected(calendar, isSelected: isSelected)
|
||||
let grouped = Dictionary(grouping: calendarManager.allCalendars, by: \.accountName)
|
||||
let sortedAccounts = grouped.keys.sorted()
|
||||
|
||||
ForEach(sortedAccounts, id: \.self) { account in
|
||||
let accountCalendars = grouped[account] ?? []
|
||||
let allAccountSelected = accountCalendars.allSatisfy { calendarManager.getCalendarSelected($0) }
|
||||
|
||||
Section(header: HStack {
|
||||
Text(account)
|
||||
Spacer()
|
||||
Toggle("", isOn: Binding(
|
||||
get: { allAccountSelected },
|
||||
set: { isSelected in
|
||||
Task {
|
||||
await calendarManager.setCalendarsSelected(accountCalendars, isSelected: isSelected)
|
||||
}
|
||||
}
|
||||
))
|
||||
.labelsHidden()
|
||||
.toggleStyle(.switch)
|
||||
.controlSize(.mini)
|
||||
.disabled(!showCalendar)
|
||||
}) {
|
||||
ForEach(accountCalendars, id: \.id) { calendar in
|
||||
Toggle(isOn: Binding(
|
||||
get: { calendarManager.getCalendarSelected(calendar) },
|
||||
set: { isSelected in
|
||||
Task {
|
||||
await calendarManager.setCalendarSelected(calendar, isSelected: isSelected)
|
||||
}
|
||||
}
|
||||
)) {
|
||||
HStack(spacing: 8) {
|
||||
Circle()
|
||||
.fill(Color(calendar.color))
|
||||
.frame(width: 8, height: 8)
|
||||
Text(calendar.title)
|
||||
}
|
||||
}
|
||||
.disabled(!showCalendar)
|
||||
}
|
||||
)) {
|
||||
Text(calendar.title)
|
||||
}
|
||||
.disabled(!showCalendar)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue