@@ -11,21 +11,25 @@ import WidgetKit
1111
1212struct BeeminderGoalCountdownWidgetProvider : AppIntentTimelineProvider {
1313 func placeholder( in _: Context ) -> BeeminderGoalCountdownWidgetEntry {
14- let goalDTO = usersGoals. randomElement ( )
15-
16- return . init( date: Date ( ) ,
17- configuration: GoalCountdownConfigurationAppIntent ( ) ,
18- updatedAt: Date ( ) . addingTimeInterval ( - 60 * 1000 ) . timeIntervalSince1970,
19- username: username,
20- goalDTO: goalDTO)
14+ . init( date: Date ( ) ,
15+ configuration: GoalCountdownConfigurationAppIntent ( ) ,
16+ updatedAt: Date ( ) . addingTimeInterval ( - 60 * 1000 ) . timeIntervalSince1970,
17+ username: " username " ,
18+ goalDTO: BeeminderGoalCountdownGoalDTO ( name: " goal1 " ,
19+ limSum: " +3 in 3 days " ,
20+ countdownColor: Color . cyan,
21+ lastTouch: " " ) )
2122 }
2223
2324 func snapshot( for _: GoalCountdownConfigurationAppIntent , in context: Context ) async -> BeeminderGoalCountdownWidgetEntry {
2425 placeholder ( in: context)
2526 }
2627
2728 func timeline( for configuration: GoalCountdownConfigurationAppIntent , in _: Context ) async -> Timeline < BeeminderGoalCountdownWidgetEntry > {
28- let goal = usersGoals. first { $0. name. caseInsensitiveCompare ( configuration. goalName) == . orderedSame }
29+ var goal : BeeminderGoalCountdownGoalDTO ? {
30+ guard let goalName = configuration. goalName else { return nil }
31+ return usersGoals. first { $0. name. caseInsensitiveCompare ( goalName) == . orderedSame }
32+ }
2933
3034 let updatedAt : TimeInterval ? = {
3135 guard let lastTouch = goal? . lastTouch else { return nil }
@@ -38,7 +42,7 @@ struct BeeminderGoalCountdownWidgetProvider: AppIntentTimelineProvider {
3842 return date? . timeIntervalSince1970
3943 } ( )
4044
41- let entries : [ BeeminderGoalCountdownWidgetEntry ] = [
45+ let entries : [ BeeminderGoalCountdownWidgetEntry ] = await [
4246 BeeminderGoalCountdownWidgetEntry ( date: Date ( ) ,
4347 configuration: configuration,
4448 updatedAt: updatedAt,
@@ -52,10 +56,12 @@ struct BeeminderGoalCountdownWidgetProvider: AppIntentTimelineProvider {
5256
5357private extension BeeminderGoalCountdownWidgetProvider {
5458 private var username : String ? {
55- ServiceLocator . currentUserManager. username
59+ get async {
60+ await ServiceLocator . currentUserManager. username
61+ }
5662 }
5763
58- private var usersGoals : [ BeeminderGoalCountdownGoalDTO ] {
64+ var usersGoals : [ BeeminderGoalCountdownGoalDTO ] {
5965 ServiceLocator . goalManager
6066 . staleGoals ( context: ServiceLocator . persistentContainer. viewContext) ?
6167 . sorted ( using: SortDescriptor ( \. urgencyKey) )
@@ -99,7 +105,7 @@ struct BeeminderGoalCountdownWidgetEntry: TimelineEntry {
99105 // let goal: Goal?
100106 let goalDTO : BeeminderGoalCountdownGoalDTO ?
101107
102- var userProvidedGoalName : String {
108+ var userProvidedGoalName : String ? {
103109 configuration. goalName
104110 }
105111
@@ -148,7 +154,7 @@ struct BeeminderGoalCountdownWidgetEntryView: View {
148154 Spacer ( )
149155 Spacer ( )
150156
151- Text ( entry. userProvidedGoalName)
157+ Text ( entry. userProvidedGoalName ?? " Edit Widget " )
152158 . font ( . title)
153159 . frame ( width: . infinity)
154160 . minimumScaleFactor ( 0.2 )
@@ -177,7 +183,7 @@ struct BeeminderGoalCountdownWidgetEntryView: View {
177183
178184 Spacer ( )
179185
180- Text ( entry. userProvidedGoalName)
186+ Text ( entry. userProvidedGoalName ?? " Edit Widget " )
181187 . font ( . title)
182188 . frame ( width: . infinity)
183189 . minimumScaleFactor ( 0.2 )
0 commit comments