@sprucelabs/spruce-calendar-components 25.5.0 → 25.5.2

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.
@@ -272,7 +272,9 @@ class CalendarViewController extends CoreCalendarViewController {
272
272
  });
273
273
  }
274
274
  render() {
275
- return Object.assign(Object.assign({}, super.render()), { onLongPressEvent: () => this.getDevice().vibrate(), onLongPressView: () => this.getDevice().vibrate() });
275
+ var _a, _b;
276
+ const model = super.render();
277
+ return Object.assign(Object.assign({}, model), { onLongPressEvent: () => this.getDevice().vibrate(), onLongPressView: () => this.getDevice().vibrate(), shouldEnableSwipeNav: ((_b = (_a = model.people) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) === 1 });
276
278
  }
277
279
  }
278
280
  CalendarViewController.id = 'calendar';
@@ -39,6 +39,7 @@ export default class CalendarEventManager {
39
39
  getCalendars(): import("@sprucelabs/calendar-utils").SpruceSchemas.Calendar.v2021_05_19.Calendar[];
40
40
  addDraftEvent(event: CalendarEvent, shouldSelectEvent?: boolean): Promise<void>;
41
41
  addEvent(event: CalendarEvent): void;
42
+ addEvents(events: CalendarEvent[]): void;
42
43
  silentlySwapEvent(oldId: string, event: CalendarEvent): Promise<void>;
43
44
  handleDropEvent(id: string, updates: Partial<CalendarEvent>): Promise<boolean>;
44
45
  reset(): Promise<void>;
@@ -52,7 +53,7 @@ export default class CalendarEventManager {
52
53
  shouldUpdateAllEventsGoingForward?: boolean;
53
54
  shouldPersist?: boolean;
54
55
  }): void;
55
- loadEvents(startDate: number, endDate: number, peopleIds: string[]): Promise<void>;
56
+ loadEvents(startDate: number, endDate: number, peopleIds: string[]): Promise<import("@sprucelabs/calendar-utils").SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent[]>;
56
57
  setCalendarVisibility(calendarId: string, shouldBeVisible: boolean): Promise<void>;
57
58
  setupVcForEventType(vcId: string, typeSlug: string): Promise<void>;
58
59
  private assertValidCalendarId;
@@ -102,6 +102,10 @@ export default class CalendarEventManager {
102
102
  this.allEvents.push(Object.assign({}, event));
103
103
  this.calendarVc.addEvent(event);
104
104
  }
105
+ addEvents(events) {
106
+ this.allEvents.push(...events);
107
+ this.calendarVc.mixinEvents(events);
108
+ }
105
109
  silentlySwapEvent(oldId, event) {
106
110
  var _a;
107
111
  return __awaiter(this, void 0, void 0, function* () {
@@ -215,7 +219,6 @@ export default class CalendarEventManager {
215
219
  peopleIds,
216
220
  });
217
221
  yield this.calendarVc.renderOnce(() => __awaiter(this, void 0, void 0, function* () {
218
- this.replaceEventsInRange(events, startDate, endDate);
219
222
  if (!this.eventTypes) {
220
223
  this.eventTypes = yield this.events.getEventTypes();
221
224
  }
@@ -226,7 +229,9 @@ export default class CalendarEventManager {
226
229
  yield this.setupVcForEventType(type.viewControllerId, type.slug);
227
230
  }
228
231
  })));
232
+ this.replaceEventsInRange(events, startDate, endDate);
229
233
  }));
234
+ return events;
230
235
  });
231
236
  }
232
237
  setCalendarVisibility(calendarId, shouldBeVisible) {
@@ -29,6 +29,7 @@ export default class RootSkillViewController extends AbstractSkillViewController
29
29
  protected remoteVc: RemoteViewControllerFactory;
30
30
  protected draftEvent?: CalendarEvent;
31
31
  private loadEventInterval?;
32
+ private shouldIgnoreNextDeselectEvent;
32
33
  constructor(options: ViewControllerOptions);
33
34
  getScope: () => ScopeFlag[];
34
35
  private createToolBeltStates;
@@ -63,6 +64,7 @@ export default class RootSkillViewController extends AbstractSkillViewController
63
64
  getCalendarSelectVc(): import("../tools/CalendarSelectTool.vc").default | undefined;
64
65
  getCalendarVc(): CalendarViewController;
65
66
  load(options: SkillViewControllerLoadOptions<RootArgs>): Promise<void>;
67
+ private optionallyLoadCachedEvents;
66
68
  private handleStateChange;
67
69
  destroy(): Promise<void>;
68
70
  private setupCalendarEventListeners;
@@ -75,6 +77,7 @@ export default class RootSkillViewController extends AbstractSkillViewController
75
77
  private syncOffsetWithLocale;
76
78
  protected loadEvents(options?: LoadEventOptions): Promise<void>;
77
79
  private _loadEvents;
80
+ private cacheEvents;
78
81
  protected transitionToRoot(): Promise<void>;
79
82
  private loadLoggedInPerson;
80
83
  private getVisibleEvents;
@@ -18,6 +18,7 @@ import { RootToolBeltState } from '../toolBelt/states/RootToolBeltState.js';
18
18
  class RootSkillViewController extends AbstractSkillViewController {
19
19
  constructor(options) {
20
20
  super(options);
21
+ this.shouldIgnoreNextDeselectEvent = false;
21
22
  this.getScope = () => ['employed', 'location'];
22
23
  this.toolBeltVc = this.ToolBeltVc();
23
24
  this.calendarVc = this.CalendarVc();
@@ -215,7 +216,9 @@ class RootSkillViewController extends AbstractSkillViewController {
215
216
  }
216
217
  handleDeselectEvent() {
217
218
  return __awaiter(this, void 0, void 0, function* () {
218
- if (this.calendarVc.getIsSwappingEvent()) {
219
+ if (this.shouldIgnoreNextDeselectEvent ||
220
+ this.calendarVc.getIsSwappingEvent()) {
221
+ this.shouldIgnoreNextDeselectEvent = false;
219
222
  return;
220
223
  }
221
224
  yield this.resetToRootState();
@@ -231,8 +234,8 @@ class RootSkillViewController extends AbstractSkillViewController {
231
234
  this.makeDateSelectMatchSelectedDateFromCalendar();
232
235
  this.syncPeopleOnCalendar();
233
236
  yield this.transitionPromise;
234
- yield this.events.reset();
235
237
  yield this.calendarVc.deselectEvent();
238
+ yield this.events.reset();
236
239
  delete this.transitionPromise;
237
240
  });
238
241
  }
@@ -258,6 +261,9 @@ class RootSkillViewController extends AbstractSkillViewController {
258
261
  var _a, _b;
259
262
  return __awaiter(this, void 0, void 0, function* () {
260
263
  const { event } = options;
264
+ if (this.events.getSelectedEvent()) {
265
+ this.shouldIgnoreNextDeselectEvent = true;
266
+ }
261
267
  yield this.events.selectEvent(event.id);
262
268
  this.toolBeltVc.open({ shouldStayOpen: true });
263
269
  try {
@@ -358,13 +364,13 @@ class RootSkillViewController extends AbstractSkillViewController {
358
364
  const { startDate = this.dates.getStartOfDay(), visiblePeopleIds } = args;
359
365
  yield this.calendarVc.renderOnce(() => __awaiter(this, void 0, void 0, function* () {
360
366
  this.syncOffsetWithLocale(locale);
361
- yield this.events.setCurrentDate(startDate);
362
- yield this.transitionToRoot();
367
+ this.optionallyLoadCachedEvents();
363
368
  if (visiblePeopleIds) {
364
369
  yield this.people.setVisibilityMode('custom');
365
370
  yield this.people.setVisiblePeopleIds(visiblePeopleIds);
366
371
  }
367
372
  }));
373
+ yield this.transitionToRoot();
368
374
  if (RootSkillViewController.shouldUpdateOnInterval) {
369
375
  this.loadEventInterval = setInterval(() => {
370
376
  return this.loadEvents({
@@ -373,9 +379,16 @@ class RootSkillViewController extends AbstractSkillViewController {
373
379
  }, RootSkillViewController.refreshInterval);
374
380
  }
375
381
  yield this.client.on('connection-status-change', this.handleStateChange);
382
+ yield this.events.setCurrentDate(startDate);
376
383
  yield this.waitUntilDoneSaving();
377
384
  });
378
385
  }
386
+ optionallyLoadCachedEvents() {
387
+ const events = this.getDevice().getCachedValue('calendarEvents');
388
+ if (events) {
389
+ this.events.addEvents(events);
390
+ }
391
+ }
379
392
  handleStateChange(options) {
380
393
  return __awaiter(this, void 0, void 0, function* () {
381
394
  const { status } = options.payload;
@@ -463,6 +476,7 @@ class RootSkillViewController extends AbstractSkillViewController {
463
476
  }
464
477
  loadEvents(options) {
465
478
  return __awaiter(this, void 0, void 0, function* () {
479
+ console.log('loading events');
466
480
  this.loadEventsPromise = this._loadEvents(options);
467
481
  yield this.loadEventsPromise;
468
482
  });
@@ -475,8 +489,9 @@ class RootSkillViewController extends AbstractSkillViewController {
475
489
  const date = this.getStartDate();
476
490
  const startDate = this.dates.getStartOfDay(date);
477
491
  const endDate = this.dates.getEndOfDay(date);
478
- yield this.events.loadEvents(startDate, endDate, this.people.getTeam().map((t) => t.id));
492
+ const events = yield this.events.loadEvents(startDate, endDate, this.people.getTeam().map((t) => t.id));
479
493
  yield this.people.emitDidUpdate();
494
+ this.cacheEvents(events);
480
495
  }
481
496
  }
482
497
  catch (err) {
@@ -493,6 +508,9 @@ class RootSkillViewController extends AbstractSkillViewController {
493
508
  }
494
509
  });
495
510
  }
511
+ cacheEvents(events) {
512
+ this.getDevice().setCachedValue('calendarEvents', events);
513
+ }
496
514
  transitionToRoot() {
497
515
  return __awaiter(this, void 0, void 0, function* () {
498
516
  yield this.sm.transitionTo(this.toolBeltStates.root);
@@ -60,9 +60,10 @@ class EventTitleToolViewController extends AbstractViewController {
60
60
  }
61
61
  handleUpdateContext(context) {
62
62
  return __awaiter(this, void 0, void 0, function* () {
63
+ const firstBlock = context.event.timeBlocks[0];
63
64
  yield this.formVc.setValues({
64
- title: context.event.timeBlocks[0].title,
65
- subtitle: context.event.timeBlocks[0].subtitle,
65
+ title: firstBlock.title,
66
+ subtitle: firstBlock.subtitle,
66
67
  });
67
68
  });
68
69
  }
@@ -29,6 +29,7 @@ export default class RootSkillViewController extends AbstractSkillViewController
29
29
  protected remoteVc: RemoteViewControllerFactory;
30
30
  protected draftEvent?: CalendarEvent;
31
31
  private loadEventInterval?;
32
+ private shouldIgnoreNextDeselectEvent;
32
33
  constructor(options: ViewControllerOptions);
33
34
  getScope: () => ScopeFlag[];
34
35
  private createToolBeltStates;
@@ -63,6 +64,7 @@ export default class RootSkillViewController extends AbstractSkillViewController
63
64
  getCalendarSelectVc(): import("../tools/CalendarSelectTool.vc").default | undefined;
64
65
  getCalendarVc(): CalendarViewController;
65
66
  load(options: SkillViewControllerLoadOptions<RootArgs>): Promise<void>;
67
+ private optionallyLoadCachedEvents;
66
68
  private handleStateChange;
67
69
  destroy(): Promise<void>;
68
70
  private setupCalendarEventListeners;
@@ -75,6 +77,7 @@ export default class RootSkillViewController extends AbstractSkillViewController
75
77
  private syncOffsetWithLocale;
76
78
  protected loadEvents(options?: LoadEventOptions): Promise<void>;
77
79
  private _loadEvents;
80
+ private cacheEvents;
78
81
  protected transitionToRoot(): Promise<void>;
79
82
  private loadLoggedInPerson;
80
83
  private getVisibleEvents;
@@ -14,6 +14,7 @@ const RootToolBeltState_1 = require("../toolBelt/states/RootToolBeltState");
14
14
  class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkillViewController {
15
15
  constructor(options) {
16
16
  super(options);
17
+ this.shouldIgnoreNextDeselectEvent = false;
17
18
  this.getScope = () => ['employed', 'location'];
18
19
  this.toolBeltVc = this.ToolBeltVc();
19
20
  this.calendarVc = this.CalendarVc();
@@ -190,7 +191,9 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
190
191
  return (_a = this.calendarVc.getStartDate()) !== null && _a !== void 0 ? _a : this.dates.date();
191
192
  }
192
193
  async handleDeselectEvent() {
193
- if (this.calendarVc.getIsSwappingEvent()) {
194
+ if (this.shouldIgnoreNextDeselectEvent ||
195
+ this.calendarVc.getIsSwappingEvent()) {
196
+ this.shouldIgnoreNextDeselectEvent = false;
194
197
  return;
195
198
  }
196
199
  await this.resetToRootState();
@@ -204,8 +207,8 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
204
207
  this.makeDateSelectMatchSelectedDateFromCalendar();
205
208
  this.syncPeopleOnCalendar();
206
209
  await this.transitionPromise;
207
- await this.events.reset();
208
210
  await this.calendarVc.deselectEvent();
211
+ await this.events.reset();
209
212
  delete this.transitionPromise;
210
213
  }
211
214
  ToolBeltVc() {
@@ -227,6 +230,9 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
227
230
  async handleClickEvent(options) {
228
231
  var _a, _b;
229
232
  const { event } = options;
233
+ if (this.events.getSelectedEvent()) {
234
+ this.shouldIgnoreNextDeselectEvent = true;
235
+ }
230
236
  await this.events.selectEvent(event.id);
231
237
  this.toolBeltVc.open({ shouldStayOpen: true });
232
238
  try {
@@ -317,13 +323,13 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
317
323
  const { startDate = this.dates.getStartOfDay(), visiblePeopleIds } = args;
318
324
  await this.calendarVc.renderOnce(async () => {
319
325
  this.syncOffsetWithLocale(locale);
320
- await this.events.setCurrentDate(startDate);
321
- await this.transitionToRoot();
326
+ this.optionallyLoadCachedEvents();
322
327
  if (visiblePeopleIds) {
323
328
  await this.people.setVisibilityMode('custom');
324
329
  await this.people.setVisiblePeopleIds(visiblePeopleIds);
325
330
  }
326
331
  });
332
+ await this.transitionToRoot();
327
333
  if (RootSkillViewController.shouldUpdateOnInterval) {
328
334
  this.loadEventInterval = setInterval(() => {
329
335
  return this.loadEvents({
@@ -332,8 +338,15 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
332
338
  }, RootSkillViewController.refreshInterval);
333
339
  }
334
340
  await this.client.on('connection-status-change', this.handleStateChange);
341
+ await this.events.setCurrentDate(startDate);
335
342
  await this.waitUntilDoneSaving();
336
343
  }
344
+ optionallyLoadCachedEvents() {
345
+ const events = this.getDevice().getCachedValue('calendarEvents');
346
+ if (events) {
347
+ this.events.addEvents(events);
348
+ }
349
+ }
337
350
  async handleStateChange(options) {
338
351
  const { status } = options.payload;
339
352
  if (status === 'connected') {
@@ -404,6 +417,7 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
404
417
  this.calendarVc.setTimezoneOffsetMs(offset * 60 * 1000);
405
418
  }
406
419
  async loadEvents(options) {
420
+ console.log('loading events');
407
421
  this.loadEventsPromise = this._loadEvents(options);
408
422
  await this.loadEventsPromise;
409
423
  }
@@ -414,8 +428,9 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
414
428
  const date = this.getStartDate();
415
429
  const startDate = this.dates.getStartOfDay(date);
416
430
  const endDate = this.dates.getEndOfDay(date);
417
- await this.events.loadEvents(startDate, endDate, this.people.getTeam().map((t) => t.id));
431
+ const events = await this.events.loadEvents(startDate, endDate, this.people.getTeam().map((t) => t.id));
418
432
  await this.people.emitDidUpdate();
433
+ this.cacheEvents(events);
419
434
  }
420
435
  }
421
436
  catch (err) {
@@ -431,6 +446,9 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
431
446
  });
432
447
  }
433
448
  }
449
+ cacheEvents(events) {
450
+ this.getDevice().setCachedValue('calendarEvents', events);
451
+ }
434
452
  async transitionToRoot() {
435
453
  await this.sm.transitionTo(this.toolBeltStates.root);
436
454
  }
@@ -50,9 +50,10 @@ class EventTitleToolViewController extends heartwood_view_controllers_1.Abstract
50
50
  });
51
51
  }
52
52
  async handleUpdateContext(context) {
53
+ const firstBlock = context.event.timeBlocks[0];
53
54
  await this.formVc.setValues({
54
- title: context.event.timeBlocks[0].title,
55
- subtitle: context.event.timeBlocks[0].subtitle,
55
+ title: firstBlock.title,
56
+ subtitle: firstBlock.subtitle,
56
57
  });
57
58
  }
58
59
  getFormVc() {
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": "25.5.0",
4
+ "version": "25.5.2",
5
5
  "skill": {
6
6
  "namespace": "calendar"
7
7
  },