@sprucelabs/spruce-calendar-components 22.4.13 → 22.6.0

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.
@@ -57,6 +57,12 @@ export default class RootSkillViewController extends AbstractSkillViewController
57
57
  getCalendarSelectVc(): import("../viewControllers/CalendarSelectTool.vc").default | undefined;
58
58
  getCalendarVc(): CalendarViewController;
59
59
  load(options: SkillViewControllerLoadOptions<Args>): Promise<void>;
60
+ private setupEventListeners;
61
+ private handleDidCancelEvent;
62
+ private handleDidCreateOrUpdate;
63
+ private loadEventStore;
64
+ private loadPeople;
65
+ private loadScope;
60
66
  private syncPeopleOnCalendar;
61
67
  private syncOffsetWithLocale;
62
68
  private loadEvents;
@@ -287,28 +287,16 @@ export default class RootSkillViewController extends AbstractSkillViewController
287
287
  yield this.sm.updateContext(Object.assign(Object.assign({}, options), { people: this.people, events: this.events }));
288
288
  this.client = yield this.connectToApi();
289
289
  const { scope, locale, args, router } = options;
290
- yield locale.on('did-change-timezones', () => {
291
- return this.syncOffsetWithLocale(locale);
292
- });
293
- const [location] = yield Promise.all([
294
- scope.getCurrentLocation(),
295
- this.loadLoggedInPerson(),
290
+ yield Promise.all([
291
+ this.setupEventListeners(),
292
+ locale.on('did-change-timezones', () => {
293
+ return this.syncOffsetWithLocale(locale);
294
+ }),
295
+ this.loadScope(scope),
296
296
  ]);
297
- this.organizationId = location === null || location === void 0 ? void 0 : location.organizationId;
298
- this.locationId = location === null || location === void 0 ? void 0 : location.id;
299
297
  try {
300
298
  yield this.preferences.load(this.organizationId);
301
- yield this.people.on('did-update', this.syncPeopleOnCalendar.bind(this));
302
- yield this.people.load({
303
- loggedInPerson: this.person,
304
- locationId: this.locationId,
305
- organizationId: this.organizationId,
306
- });
307
- yield this.remoteEventStore.load({
308
- locationId: this.locationId,
309
- organizationId: this.organizationId,
310
- });
311
- yield this.events.load();
299
+ yield Promise.all([this.loadPeople(), this.loadEventStore()]);
312
300
  }
313
301
  catch (err) {
314
302
  yield this.alert({
@@ -326,6 +314,68 @@ export default class RootSkillViewController extends AbstractSkillViewController
326
314
  yield this.waitUntilDoneSaving();
327
315
  });
328
316
  }
317
+ setupEventListeners() {
318
+ return __awaiter(this, void 0, void 0, function* () {
319
+ yield Promise.all([
320
+ this.client.on('calendar.did-create-calendar-event::v2021_05_19', this.handleDidCreateOrUpdate.bind(this)),
321
+ this.client.on('calendar.did-update-calendar-event::v2021_05_19', this.handleDidCreateOrUpdate.bind(this)),
322
+ this.client.on('calendar.did-cancel-calendar-event::v2021_05_19', this.handleDidCancelEvent.bind(this)),
323
+ ]);
324
+ });
325
+ }
326
+ handleDidCancelEvent({ target }) {
327
+ return __awaiter(this, void 0, void 0, function* () {
328
+ const { calendarEventId } = target;
329
+ if (this.events.hasEvent(calendarEventId)) {
330
+ yield this.events.removeEvent(calendarEventId, { shouldPersist: false });
331
+ }
332
+ });
333
+ }
334
+ handleDidCreateOrUpdate({ payload, target, }) {
335
+ return __awaiter(this, void 0, void 0, function* () {
336
+ const { calendarEvent } = payload;
337
+ const { locationId } = target;
338
+ if (calendarEvent.style !== 'draft' && locationId === this.locationId) {
339
+ if (this.events.hasEvent(calendarEvent.id)) {
340
+ this.events.updateEvent(calendarEvent.id, Object.assign(Object.assign({}, calendarEvent), { shouldPersist: false }));
341
+ }
342
+ else {
343
+ this.events.addEvent(calendarEvent);
344
+ }
345
+ }
346
+ });
347
+ }
348
+ loadEventStore() {
349
+ return __awaiter(this, void 0, void 0, function* () {
350
+ yield this.remoteEventStore.load({
351
+ locationId: this.locationId,
352
+ organizationId: this.organizationId,
353
+ });
354
+ yield this.events.load();
355
+ });
356
+ }
357
+ loadPeople() {
358
+ return __awaiter(this, void 0, void 0, function* () {
359
+ yield Promise.all([
360
+ this.people.on('did-update', this.syncPeopleOnCalendar.bind(this)),
361
+ this.people.load({
362
+ loggedInPerson: this.person,
363
+ locationId: this.locationId,
364
+ organizationId: this.organizationId,
365
+ }),
366
+ ]);
367
+ });
368
+ }
369
+ loadScope(scope) {
370
+ return __awaiter(this, void 0, void 0, function* () {
371
+ const [location] = yield Promise.all([
372
+ scope.getCurrentLocation(),
373
+ this.loadLoggedInPerson(),
374
+ ]);
375
+ this.organizationId = location === null || location === void 0 ? void 0 : location.organizationId;
376
+ this.locationId = location === null || location === void 0 ? void 0 : location.id;
377
+ });
378
+ }
329
379
  syncPeopleOnCalendar() {
330
380
  const visiblePeople = this.people.getVisiblePeople();
331
381
  this.calendarVc.setPeople(visiblePeople);
@@ -39,17 +39,21 @@ export default class CalendarEventManager {
39
39
  getEventsByGroupId(groupId: string): import("@sprucelabs/calendar-utils").SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent[];
40
40
  getCalendars(): import("@sprucelabs/calendar-utils").SpruceSchemas.Calendar.v2021_05_19.Calendar[];
41
41
  addDraftEvent(event: CalendarEvent, shouldSelectEvent?: boolean): Promise<void>;
42
+ addEvent(event: 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>;
45
46
  restoreEventToDraftOnStateLoadError(): Promise<void>;
46
47
  getVisibleCalendarIds(): string[];
47
- removeEvent(id: string): Promise<void>;
48
+ removeEvent(id: string, options?: {
49
+ shouldPersist?: boolean;
50
+ }): Promise<void>;
48
51
  makeCalendarVisible(calendarId: string): Promise<void>;
49
52
  makeCalendarHidden(calendarId: string): Promise<void>;
50
53
  updateEvent(id: string, updates: Partial<CalendarEvent> & {
51
54
  dateToUpdate?: number;
52
55
  shouldUpdateAllEventsGoingForward?: boolean;
56
+ shouldPersist?: boolean;
53
57
  }): void;
54
58
  loadEvents(startDate: number, endDate: number, peopleIds: string[]): Promise<void>;
55
59
  setCalendarVisibility(calendarId: string, shouldBeVisible: boolean): Promise<void>;
@@ -7,6 +7,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
10
21
  import { calendarEventSchema, } from '@sprucelabs/heartwood-view-controllers';
11
22
  import { assertOptions, normalizeSchemaValues } from '@sprucelabs/schema';
12
23
  import SpruceError from '../errors/SpruceError.js';
@@ -89,6 +100,10 @@ export default class CalendarEventManager {
89
100
  }
90
101
  });
91
102
  }
103
+ addEvent(event) {
104
+ this.allEvents.push(Object.assign({}, event));
105
+ this.calendarVc.addEvent(event);
106
+ }
92
107
  silentlySwapEvent(oldId, event) {
93
108
  var _a;
94
109
  return __awaiter(this, void 0, void 0, function* () {
@@ -129,12 +144,15 @@ export default class CalendarEventManager {
129
144
  getVisibleCalendarIds() {
130
145
  return this.visibleCalendarIds;
131
146
  }
132
- removeEvent(id) {
147
+ removeEvent(id, options) {
133
148
  var _a;
134
149
  return __awaiter(this, void 0, void 0, function* () {
135
150
  this.allEvents = this.allEvents.filter((e) => e.id !== id);
136
151
  const event = this.calendarVc.getEvent(id);
137
152
  this.calendarVc.removeEvent(id);
153
+ if ((options === null || options === void 0 ? void 0 : options.shouldPersist) === false) {
154
+ return;
155
+ }
138
156
  try {
139
157
  yield this.events.cancelEvent(event.id);
140
158
  }
@@ -168,14 +186,15 @@ export default class CalendarEventManager {
168
186
  }
169
187
  updateEvent(id, updates) {
170
188
  var _a;
171
- this.calendarVc.updateEvent(id, updates);
189
+ const { shouldPersist } = updates, rest = __rest(updates, ["shouldPersist"]);
190
+ this.calendarVc.updateEvent(id, Object.assign(Object.assign({}, rest), { shouldPersist }));
172
191
  const idx = this.allEvents.findIndex((e) => e.id === id);
173
- this.allEvents[idx] = Object.assign(Object.assign({}, this.allEvents[idx]), updates);
192
+ this.allEvents[idx] = Object.assign(Object.assign({}, this.allEvents[idx]), rest);
174
193
  this.refreshShifts();
175
194
  if (this.shouldUpdateContextOnNextSave &&
176
195
  ((_a = this.sm.getContext().event) === null || _a === void 0 ? void 0 : _a.id) === id) {
177
196
  this.shouldIgnoreNextContextUpdate = true;
178
- void this.updateEventInContext(updates);
197
+ void this.updateEventInContext(rest);
179
198
  }
180
199
  this.shouldUpdateContextOnNextSave = true;
181
200
  }
@@ -69,7 +69,9 @@ export default class CalendarViewController extends CoreCalendarViewController {
69
69
  }>;
70
70
  getIsSwappingEvent(): boolean;
71
71
  private swapEvent;
72
- updateEvent(id: string, updates: Partial<UpdateEvent>): any;
72
+ updateEvent(id: string, updates: Partial<UpdateEvent> & {
73
+ shouldPersist?: boolean;
74
+ }): any;
73
75
  private persist;
74
76
  getPeople(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarPerson[];
75
77
  render(): {
@@ -171,9 +171,12 @@ export default class CalendarViewController extends CoreCalendarViewController {
171
171
  });
172
172
  }
173
173
  updateEvent(id, updates) {
174
+ const { shouldPersist } = updates, rest = __rest(updates, ["shouldPersist"]);
174
175
  try {
175
- const updated = super.updateEvent(id, Object.assign(Object.assign({}, updates), { isBusy: true }));
176
- void this.persist(updated);
176
+ const updated = super.updateEvent(id, Object.assign(Object.assign({}, rest), { isBusy: true }));
177
+ if (shouldPersist !== false) {
178
+ void this.persist(updated);
179
+ }
177
180
  return updated;
178
181
  // eslint-disable-next-line no-empty
179
182
  }
@@ -57,6 +57,12 @@ export default class RootSkillViewController extends AbstractSkillViewController
57
57
  getCalendarSelectVc(): import("../viewControllers/CalendarSelectTool.vc").default | undefined;
58
58
  getCalendarVc(): CalendarViewController;
59
59
  load(options: SkillViewControllerLoadOptions<Args>): Promise<void>;
60
+ private setupEventListeners;
61
+ private handleDidCancelEvent;
62
+ private handleDidCreateOrUpdate;
63
+ private loadEventStore;
64
+ private loadPeople;
65
+ private loadScope;
60
66
  private syncPeopleOnCalendar;
61
67
  private syncOffsetWithLocale;
62
68
  private loadEvents;
@@ -250,28 +250,16 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
250
250
  await this.sm.updateContext(Object.assign(Object.assign({}, options), { people: this.people, events: this.events }));
251
251
  this.client = await this.connectToApi();
252
252
  const { scope, locale, args, router } = options;
253
- await locale.on('did-change-timezones', () => {
254
- return this.syncOffsetWithLocale(locale);
255
- });
256
- const [location] = await Promise.all([
257
- scope.getCurrentLocation(),
258
- this.loadLoggedInPerson(),
253
+ await Promise.all([
254
+ this.setupEventListeners(),
255
+ locale.on('did-change-timezones', () => {
256
+ return this.syncOffsetWithLocale(locale);
257
+ }),
258
+ this.loadScope(scope),
259
259
  ]);
260
- this.organizationId = location === null || location === void 0 ? void 0 : location.organizationId;
261
- this.locationId = location === null || location === void 0 ? void 0 : location.id;
262
260
  try {
263
261
  await this.preferences.load(this.organizationId);
264
- await this.people.on('did-update', this.syncPeopleOnCalendar.bind(this));
265
- await this.people.load({
266
- loggedInPerson: this.person,
267
- locationId: this.locationId,
268
- organizationId: this.organizationId,
269
- });
270
- await this.remoteEventStore.load({
271
- locationId: this.locationId,
272
- organizationId: this.organizationId,
273
- });
274
- await this.events.load();
262
+ await Promise.all([this.loadPeople(), this.loadEventStore()]);
275
263
  }
276
264
  catch (err) {
277
265
  await this.alert({
@@ -288,6 +276,56 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
288
276
  this.setSelectedDateInDateSelectVc(startDate);
289
277
  await this.waitUntilDoneSaving();
290
278
  }
279
+ async setupEventListeners() {
280
+ await Promise.all([
281
+ this.client.on('calendar.did-create-calendar-event::v2021_05_19', this.handleDidCreateOrUpdate.bind(this)),
282
+ this.client.on('calendar.did-update-calendar-event::v2021_05_19', this.handleDidCreateOrUpdate.bind(this)),
283
+ this.client.on('calendar.did-cancel-calendar-event::v2021_05_19', this.handleDidCancelEvent.bind(this)),
284
+ ]);
285
+ }
286
+ async handleDidCancelEvent({ target }) {
287
+ const { calendarEventId } = target;
288
+ if (this.events.hasEvent(calendarEventId)) {
289
+ await this.events.removeEvent(calendarEventId, { shouldPersist: false });
290
+ }
291
+ }
292
+ async handleDidCreateOrUpdate({ payload, target, }) {
293
+ const { calendarEvent } = payload;
294
+ const { locationId } = target;
295
+ if (calendarEvent.style !== 'draft' && locationId === this.locationId) {
296
+ if (this.events.hasEvent(calendarEvent.id)) {
297
+ this.events.updateEvent(calendarEvent.id, Object.assign(Object.assign({}, calendarEvent), { shouldPersist: false }));
298
+ }
299
+ else {
300
+ this.events.addEvent(calendarEvent);
301
+ }
302
+ }
303
+ }
304
+ async loadEventStore() {
305
+ await this.remoteEventStore.load({
306
+ locationId: this.locationId,
307
+ organizationId: this.organizationId,
308
+ });
309
+ await this.events.load();
310
+ }
311
+ async loadPeople() {
312
+ await Promise.all([
313
+ this.people.on('did-update', this.syncPeopleOnCalendar.bind(this)),
314
+ this.people.load({
315
+ loggedInPerson: this.person,
316
+ locationId: this.locationId,
317
+ organizationId: this.organizationId,
318
+ }),
319
+ ]);
320
+ }
321
+ async loadScope(scope) {
322
+ const [location] = await Promise.all([
323
+ scope.getCurrentLocation(),
324
+ this.loadLoggedInPerson(),
325
+ ]);
326
+ this.organizationId = location === null || location === void 0 ? void 0 : location.organizationId;
327
+ this.locationId = location === null || location === void 0 ? void 0 : location.id;
328
+ }
291
329
  syncPeopleOnCalendar() {
292
330
  const visiblePeople = this.people.getVisiblePeople();
293
331
  this.calendarVc.setPeople(visiblePeople);
@@ -39,17 +39,21 @@ export default class CalendarEventManager {
39
39
  getEventsByGroupId(groupId: string): import("@sprucelabs/calendar-utils").SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent[];
40
40
  getCalendars(): import("@sprucelabs/calendar-utils").SpruceSchemas.Calendar.v2021_05_19.Calendar[];
41
41
  addDraftEvent(event: CalendarEvent, shouldSelectEvent?: boolean): Promise<void>;
42
+ addEvent(event: 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>;
45
46
  restoreEventToDraftOnStateLoadError(): Promise<void>;
46
47
  getVisibleCalendarIds(): string[];
47
- removeEvent(id: string): Promise<void>;
48
+ removeEvent(id: string, options?: {
49
+ shouldPersist?: boolean;
50
+ }): Promise<void>;
48
51
  makeCalendarVisible(calendarId: string): Promise<void>;
49
52
  makeCalendarHidden(calendarId: string): Promise<void>;
50
53
  updateEvent(id: string, updates: Partial<CalendarEvent> & {
51
54
  dateToUpdate?: number;
52
55
  shouldUpdateAllEventsGoingForward?: boolean;
56
+ shouldPersist?: boolean;
53
57
  }): void;
54
58
  loadEvents(startDate: number, endDate: number, peopleIds: string[]): Promise<void>;
55
59
  setCalendarVisibility(calendarId: string, shouldBeVisible: boolean): Promise<void>;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
15
  };
@@ -83,6 +94,10 @@ class CalendarEventManager {
83
94
  await this.updateEventInContext(event);
84
95
  }
85
96
  }
97
+ addEvent(event) {
98
+ this.allEvents.push(Object.assign({}, event));
99
+ this.calendarVc.addEvent(event);
100
+ }
86
101
  async silentlySwapEvent(oldId, event) {
87
102
  var _a;
88
103
  const events = this.getEvents().filter((e) => e.id !== oldId);
@@ -115,11 +130,14 @@ class CalendarEventManager {
115
130
  getVisibleCalendarIds() {
116
131
  return this.visibleCalendarIds;
117
132
  }
118
- async removeEvent(id) {
133
+ async removeEvent(id, options) {
119
134
  var _a;
120
135
  this.allEvents = this.allEvents.filter((e) => e.id !== id);
121
136
  const event = this.calendarVc.getEvent(id);
122
137
  this.calendarVc.removeEvent(id);
138
+ if ((options === null || options === void 0 ? void 0 : options.shouldPersist) === false) {
139
+ return;
140
+ }
123
141
  try {
124
142
  await this.events.cancelEvent(event.id);
125
143
  }
@@ -148,14 +166,15 @@ class CalendarEventManager {
148
166
  }
149
167
  updateEvent(id, updates) {
150
168
  var _a;
151
- this.calendarVc.updateEvent(id, updates);
169
+ const { shouldPersist } = updates, rest = __rest(updates, ["shouldPersist"]);
170
+ this.calendarVc.updateEvent(id, Object.assign(Object.assign({}, rest), { shouldPersist }));
152
171
  const idx = this.allEvents.findIndex((e) => e.id === id);
153
- this.allEvents[idx] = Object.assign(Object.assign({}, this.allEvents[idx]), updates);
172
+ this.allEvents[idx] = Object.assign(Object.assign({}, this.allEvents[idx]), rest);
154
173
  this.refreshShifts();
155
174
  if (this.shouldUpdateContextOnNextSave &&
156
175
  ((_a = this.sm.getContext().event) === null || _a === void 0 ? void 0 : _a.id) === id) {
157
176
  this.shouldIgnoreNextContextUpdate = true;
158
- void this.updateEventInContext(updates);
177
+ void this.updateEventInContext(rest);
159
178
  }
160
179
  this.shouldUpdateContextOnNextSave = true;
161
180
  }
@@ -69,7 +69,9 @@ export default class CalendarViewController extends CoreCalendarViewController {
69
69
  }>;
70
70
  getIsSwappingEvent(): boolean;
71
71
  private swapEvent;
72
- updateEvent(id: string, updates: Partial<UpdateEvent>): any;
72
+ updateEvent(id: string, updates: Partial<UpdateEvent> & {
73
+ shouldPersist?: boolean;
74
+ }): any;
73
75
  private persist;
74
76
  getPeople(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarPerson[];
75
77
  render(): {
@@ -152,9 +152,12 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
152
152
  this.enableAnimation();
153
153
  }
154
154
  updateEvent(id, updates) {
155
+ const { shouldPersist } = updates, rest = __rest(updates, ["shouldPersist"]);
155
156
  try {
156
- const updated = super.updateEvent(id, Object.assign(Object.assign({}, updates), { isBusy: true }));
157
- void this.persist(updated);
157
+ const updated = super.updateEvent(id, Object.assign(Object.assign({}, rest), { isBusy: true }));
158
+ if (shouldPersist !== false) {
159
+ void this.persist(updated);
160
+ }
158
161
  return updated;
159
162
  // eslint-disable-next-line no-empty
160
163
  }
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": "22.4.13",
4
+ "version": "22.6.0",
5
5
  "skill": {
6
6
  "namespace": "calendar"
7
7
  },