Filter widget snapshots through the shared package rule
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
75a6a5bd79
commit
c8a36c161f
@@ -1,5 +1,6 @@
|
|||||||
import WidgetKit
|
import WidgetKit
|
||||||
import AppIntents
|
import AppIntents
|
||||||
|
import CalendarrCore
|
||||||
|
|
||||||
struct CalendarrEntry: TimelineEntry {
|
struct CalendarrEntry: TimelineEntry {
|
||||||
let date: Date
|
let date: Date
|
||||||
@@ -37,22 +38,9 @@ struct CalendarrTimelineProvider: AppIntentTimelineProvider {
|
|||||||
// MARK: – Filtering
|
// MARK: – Filtering
|
||||||
|
|
||||||
private func filtered(_ snapshot: WidgetSnapshot?, by config: CalendarSelectionIntent) -> WidgetSnapshot? {
|
private func filtered(_ snapshot: WidgetSnapshot?, by config: CalendarSelectionIntent) -> WidgetSnapshot? {
|
||||||
guard let snapshot else { return nil }
|
// The rule lives in CalendarrCore so the watch provider cannot drift
|
||||||
let ids = (config.selectedCalendars ?? []).map { $0.id }
|
// from this one. Nothing selected means "show all calendars".
|
||||||
guard !ids.isEmpty else { return snapshot } // nothing selected = show all
|
snapshot?.filtered(toCalendarKeys: Set((config.selectedCalendars ?? []).map(\.id)))
|
||||||
let keep = Set(ids)
|
|
||||||
// Filtering narrows the events but not the window: the snapshot still
|
|
||||||
// speaks for the same range, it just has fewer calendars in it.
|
|
||||||
return WidgetSnapshot(
|
|
||||||
writtenAt: snapshot.writtenAt,
|
|
||||||
coverageStart: snapshot.coverageStart,
|
|
||||||
coverageEnd: snapshot.coverageEnd,
|
|
||||||
isLoggedIn: snapshot.isLoggedIn,
|
|
||||||
writerVersion: snapshot.writerVersion,
|
|
||||||
events: snapshot.events.filter { keep.contains($0.calendarKey) },
|
|
||||||
theme: snapshot.theme,
|
|
||||||
language: snapshot.language
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user