@sprucelabs/spruce-calendar-components 26.0.21 → 26.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,12 +7,13 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
7
7
  protected sm: CalendarToolBeltStateMachine;
8
8
  private toolBeltVc;
9
9
  private vcs;
10
- private pendingContextUpdates;
10
+ protected pendingContextUpdates: Partial<CalendarToolBeltContext>;
11
11
  protected controlsVc: EventControlsCardViewController;
12
12
  private isLoaded;
13
13
  protected events: CalendarEventManager;
14
14
  protected shouldLoadToolsRightAway: boolean;
15
15
  private getPersonPromise?;
16
+ private lastEventId?;
16
17
  constructor();
17
18
  load(sm: CalendarToolBeltStateMachine): Promise<void>;
18
19
  getIsLoaded(): boolean;
@@ -22,7 +23,8 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
22
23
  protected get context(): CalendarToolBeltContext;
23
24
  protected get event(): import("@sprucelabs/heartwood-view-controllers").SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
24
25
  private deselectEvent;
25
- private handleDidUpdateContext;
26
+ private _handleWillUpdateContext;
27
+ private _handleDidUpdateContext;
26
28
  protected getContextWithPendingChanges(): CalendarToolBeltContext;
27
29
  clearPendingContextChanges(shouldEmitDidUpdate?: boolean): Promise<void>;
28
30
  addTool(options: AddToolOptions): Promise<CalendarTool>;
@@ -34,7 +36,7 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
34
36
  private _getPersonFromEvent;
35
37
  protected handleUpdateContextFromTool(updates: Partial<CalendarToolBeltContext>, fromToolId: string, options?: UpdateCalendarContextOptions): Promise<boolean>;
36
38
  removeTool(id: string): void;
37
- getPendingContextChanges(): Partial<CalendarToolBeltContext>;
39
+ getPendingContextUpdates(): Partial<CalendarToolBeltContext>;
38
40
  getVcForTool(toolId: string): CalendarTool | undefined;
39
41
  getControlsVc(): EventControlsCardViewController;
40
42
  destroy(): Promise<void>;
@@ -16,9 +16,11 @@ export default class AbstractCalendarEventToolBeltState {
16
16
  this.pendingContextUpdates = {};
17
17
  this.isLoaded = false;
18
18
  this.shouldLoadToolsRightAway = true;
19
- this.handleDidUpdateContext = this.handleDidUpdateContext.bind(this);
19
+ this._handleDidUpdateContext = this._handleDidUpdateContext.bind(this);
20
+ this._handleWillUpdateContext = this._handleWillUpdateContext.bind(this);
20
21
  }
21
22
  load(sm) {
23
+ var _a;
22
24
  return __awaiter(this, void 0, void 0, function* () {
23
25
  this.sm = sm;
24
26
  this.toolBeltVc = sm.getToolBeltVc();
@@ -36,7 +38,9 @@ export default class AbstractCalendarEventToolBeltState {
36
38
  lineIcon: 'send',
37
39
  position: 'bottom',
38
40
  });
39
- void this.sm.on('did-update-context', this.handleDidUpdateContext);
41
+ void this.sm.on('did-update-context', this._handleDidUpdateContext);
42
+ void this.sm.on('will-update-context', this._handleWillUpdateContext);
43
+ this.lastEventId = (_a = this.event) === null || _a === void 0 ? void 0 : _a.id;
40
44
  });
41
45
  }
42
46
  getIsLoaded() {
@@ -75,9 +79,18 @@ export default class AbstractCalendarEventToolBeltState {
75
79
  yield this.context.events.deselectEvent();
76
80
  });
77
81
  }
78
- handleDidUpdateContext(skipToolWithId) {
82
+ _handleWillUpdateContext({ updates, }) {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ const { event } = updates;
85
+ if (event && this.lastEventId !== event.id) {
86
+ this.pendingContextUpdates = {};
87
+ }
88
+ });
89
+ }
90
+ _handleDidUpdateContext(skipToolWithId) {
79
91
  return __awaiter(this, void 0, void 0, function* () {
80
92
  const context = this.getContextWithPendingChanges();
93
+ const { event } = context;
81
94
  if (!context.event) {
82
95
  return;
83
96
  }
@@ -87,6 +100,7 @@ export default class AbstractCalendarEventToolBeltState {
87
100
  }
88
101
  })));
89
102
  this.controlsVc.handleUpdateContext();
103
+ this.lastEventId = event === null || event === void 0 ? void 0 : event.id;
90
104
  });
91
105
  }
92
106
  getContextWithPendingChanges() {
@@ -96,7 +110,7 @@ export default class AbstractCalendarEventToolBeltState {
96
110
  return __awaiter(this, void 0, void 0, function* () {
97
111
  this.pendingContextUpdates = {};
98
112
  if (shouldEmitDidUpdate) {
99
- yield this.handleDidUpdateContext();
113
+ yield this._handleDidUpdateContext();
100
114
  }
101
115
  });
102
116
  }
@@ -190,7 +204,7 @@ export default class AbstractCalendarEventToolBeltState {
190
204
  return this.sm.updateContext(Object.assign({}, updates));
191
205
  }
192
206
  else {
193
- yield this.handleDidUpdateContext(fromToolId);
207
+ yield this._handleDidUpdateContext(fromToolId);
194
208
  }
195
209
  return false;
196
210
  });
@@ -204,7 +218,7 @@ export default class AbstractCalendarEventToolBeltState {
204
218
  this.vcs = this.vcs.filter(({ toolId }) => id !== toolId);
205
219
  this.toolBeltVc.removeTool(id);
206
220
  }
207
- getPendingContextChanges() {
221
+ getPendingContextUpdates() {
208
222
  return this.pendingContextUpdates;
209
223
  }
210
224
  getVcForTool(toolId) {
@@ -216,7 +230,7 @@ export default class AbstractCalendarEventToolBeltState {
216
230
  }
217
231
  destroy() {
218
232
  return __awaiter(this, void 0, void 0, function* () {
219
- yield this.sm.off('did-update-context', this.handleDidUpdateContext);
233
+ yield this.sm.off('did-update-context', this._handleDidUpdateContext);
220
234
  this.events.clearUpdateContextHandler();
221
235
  });
222
236
  }
@@ -131,6 +131,7 @@ class EventDateTimeToolViewController extends AbstractViewController {
131
131
  }
132
132
  handleUpdateContext(context) {
133
133
  return __awaiter(this, void 0, void 0, function* () {
134
+ console.log('eventDateTime.handleUpdateContext', context.event.timeBlocks[0].title, context.event.startDateTimeMs, this.getContext().event.startDateTimeMs);
134
135
  yield this.formVc.setValue('startDateTime', context.event.startDateTimeMs);
135
136
  this.calendarVc.setSelectedDates([this.getSelectedDate()]);
136
137
  });
@@ -7,12 +7,13 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
7
7
  protected sm: CalendarToolBeltStateMachine;
8
8
  private toolBeltVc;
9
9
  private vcs;
10
- private pendingContextUpdates;
10
+ protected pendingContextUpdates: Partial<CalendarToolBeltContext>;
11
11
  protected controlsVc: EventControlsCardViewController;
12
12
  private isLoaded;
13
13
  protected events: CalendarEventManager;
14
14
  protected shouldLoadToolsRightAway: boolean;
15
15
  private getPersonPromise?;
16
+ private lastEventId?;
16
17
  constructor();
17
18
  load(sm: CalendarToolBeltStateMachine): Promise<void>;
18
19
  getIsLoaded(): boolean;
@@ -22,7 +23,8 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
22
23
  protected get context(): CalendarToolBeltContext;
23
24
  protected get event(): import("@sprucelabs/heartwood-view-controllers").SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
24
25
  private deselectEvent;
25
- private handleDidUpdateContext;
26
+ private _handleWillUpdateContext;
27
+ private _handleDidUpdateContext;
26
28
  protected getContextWithPendingChanges(): CalendarToolBeltContext;
27
29
  clearPendingContextChanges(shouldEmitDidUpdate?: boolean): Promise<void>;
28
30
  addTool(options: AddToolOptions): Promise<CalendarTool>;
@@ -34,7 +36,7 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
34
36
  private _getPersonFromEvent;
35
37
  protected handleUpdateContextFromTool(updates: Partial<CalendarToolBeltContext>, fromToolId: string, options?: UpdateCalendarContextOptions): Promise<boolean>;
36
38
  removeTool(id: string): void;
37
- getPendingContextChanges(): Partial<CalendarToolBeltContext>;
39
+ getPendingContextUpdates(): Partial<CalendarToolBeltContext>;
38
40
  getVcForTool(toolId: string): CalendarTool | undefined;
39
41
  getControlsVc(): EventControlsCardViewController;
40
42
  destroy(): Promise<void>;
@@ -12,9 +12,11 @@ class AbstractCalendarEventToolBeltState {
12
12
  this.pendingContextUpdates = {};
13
13
  this.isLoaded = false;
14
14
  this.shouldLoadToolsRightAway = true;
15
- this.handleDidUpdateContext = this.handleDidUpdateContext.bind(this);
15
+ this._handleDidUpdateContext = this._handleDidUpdateContext.bind(this);
16
+ this._handleWillUpdateContext = this._handleWillUpdateContext.bind(this);
16
17
  }
17
18
  async load(sm) {
19
+ var _a;
18
20
  this.sm = sm;
19
21
  this.toolBeltVc = sm.getToolBeltVc();
20
22
  this.isLoaded = true;
@@ -31,7 +33,9 @@ class AbstractCalendarEventToolBeltState {
31
33
  lineIcon: 'send',
32
34
  position: 'bottom',
33
35
  });
34
- void this.sm.on('did-update-context', this.handleDidUpdateContext);
36
+ void this.sm.on('did-update-context', this._handleDidUpdateContext);
37
+ void this.sm.on('will-update-context', this._handleWillUpdateContext);
38
+ this.lastEventId = (_a = this.event) === null || _a === void 0 ? void 0 : _a.id;
35
39
  }
36
40
  getIsLoaded() {
37
41
  return this.isLoaded;
@@ -61,8 +65,15 @@ class AbstractCalendarEventToolBeltState {
61
65
  async deselectEvent() {
62
66
  await this.context.events.deselectEvent();
63
67
  }
64
- async handleDidUpdateContext(skipToolWithId) {
68
+ async _handleWillUpdateContext({ updates, }) {
69
+ const { event } = updates;
70
+ if (event && this.lastEventId !== event.id) {
71
+ this.pendingContextUpdates = {};
72
+ }
73
+ }
74
+ async _handleDidUpdateContext(skipToolWithId) {
65
75
  const context = this.getContextWithPendingChanges();
76
+ const { event } = context;
66
77
  if (!context.event) {
67
78
  return;
68
79
  }
@@ -72,6 +83,7 @@ class AbstractCalendarEventToolBeltState {
72
83
  }
73
84
  }));
74
85
  this.controlsVc.handleUpdateContext();
86
+ this.lastEventId = event === null || event === void 0 ? void 0 : event.id;
75
87
  }
76
88
  getContextWithPendingChanges() {
77
89
  return Object.assign({}, this.sm.getContext(this.pendingContextUpdates));
@@ -79,7 +91,7 @@ class AbstractCalendarEventToolBeltState {
79
91
  async clearPendingContextChanges(shouldEmitDidUpdate = true) {
80
92
  this.pendingContextUpdates = {};
81
93
  if (shouldEmitDidUpdate) {
82
- await this.handleDidUpdateContext();
94
+ await this._handleDidUpdateContext();
83
95
  }
84
96
  }
85
97
  async addTool(options) {
@@ -159,7 +171,7 @@ class AbstractCalendarEventToolBeltState {
159
171
  return this.sm.updateContext(Object.assign({}, updates));
160
172
  }
161
173
  else {
162
- await this.handleDidUpdateContext(fromToolId);
174
+ await this._handleDidUpdateContext(fromToolId);
163
175
  }
164
176
  return false;
165
177
  }
@@ -172,7 +184,7 @@ class AbstractCalendarEventToolBeltState {
172
184
  this.vcs = this.vcs.filter(({ toolId }) => id !== toolId);
173
185
  this.toolBeltVc.removeTool(id);
174
186
  }
175
- getPendingContextChanges() {
187
+ getPendingContextUpdates() {
176
188
  return this.pendingContextUpdates;
177
189
  }
178
190
  getVcForTool(toolId) {
@@ -183,7 +195,7 @@ class AbstractCalendarEventToolBeltState {
183
195
  return this.controlsVc;
184
196
  }
185
197
  async destroy() {
186
- await this.sm.off('did-update-context', this.handleDidUpdateContext);
198
+ await this.sm.off('did-update-context', this._handleDidUpdateContext);
187
199
  this.events.clearUpdateContextHandler();
188
200
  }
189
201
  }
@@ -119,6 +119,7 @@ class EventDateTimeToolViewController extends heartwood_view_controllers_1.Abstr
119
119
  }));
120
120
  }
121
121
  async handleUpdateContext(context) {
122
+ console.log('eventDateTime.handleUpdateContext', context.event.timeBlocks[0].title, context.event.startDateTimeMs, this.getContext().event.startDateTimeMs);
122
123
  await this.formVc.setValue('startDateTime', context.event.startDateTimeMs);
123
124
  this.calendarVc.setSelectedDates([this.getSelectedDate()]);
124
125
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-calendar-components",
3
3
  "description": "Calendar components for working with calendars and Sprucebot.",
4
- "version": "26.0.21",
4
+ "version": "26.0.23",
5
5
  "skill": {
6
6
  "namespace": "calendar"
7
7
  },