@burdenoff/microfe-calendar 2026.1123.3 → 2026.1124.1

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.
Files changed (192) hide show
  1. package/dist/components/AgendaView.js.map +1 -1
  2. package/dist/generated/wspace-operations.d.ts +596 -0
  3. package/dist/generated/wspace-operations.js +190 -85
  4. package/dist/generated/wspace-operations.js.map +1 -1
  5. package/dist/translations/en.d.ts +292 -0
  6. package/dist/v2/CalendarPageV2.js +87 -14
  7. package/dist/v2/CalendarPageV2.js.map +1 -1
  8. package/dist/v2/colors.d.ts +23 -0
  9. package/dist/v2/colors.js +92 -0
  10. package/dist/v2/colors.js.map +1 -0
  11. package/dist/v2/data/enums.d.ts +6 -0
  12. package/dist/v2/data/enums.js +10 -0
  13. package/dist/v2/data/enums.js.map +1 -0
  14. package/dist/v2/data/errors.d.ts +4 -0
  15. package/dist/v2/data/errors.js +17 -0
  16. package/dist/v2/data/errors.js.map +1 -0
  17. package/dist/v2/data/invalidation.js +19 -0
  18. package/dist/v2/data/invalidation.js.map +1 -0
  19. package/dist/v2/data/normalize.js +181 -16
  20. package/dist/v2/data/normalize.js.map +1 -1
  21. package/dist/v2/data/serialWrites.d.ts +17 -0
  22. package/dist/v2/data/serialWrites.js +21 -0
  23. package/dist/v2/data/serialWrites.js.map +1 -0
  24. package/dist/v2/data/useCalendarsV2.d.ts +10 -1
  25. package/dist/v2/data/useCalendarsV2.js +68 -16
  26. package/dist/v2/data/useCalendarsV2.js.map +1 -1
  27. package/dist/v2/data/useEventActions.d.ts +49 -0
  28. package/dist/v2/data/useEventActions.js +399 -0
  29. package/dist/v2/data/useEventActions.js.map +1 -0
  30. package/dist/v2/data/useEventForPeek.d.ts +17 -0
  31. package/dist/v2/data/useEventForPeek.js +29 -0
  32. package/dist/v2/data/useEventForPeek.js.map +1 -0
  33. package/dist/v2/data/useEventSearchV2.d.ts +15 -0
  34. package/dist/v2/data/useEventSearchV2.js +80 -0
  35. package/dist/v2/data/useEventSearchV2.js.map +1 -0
  36. package/dist/v2/data/useEventsInRangeV2.js +78 -0
  37. package/dist/v2/data/useEventsInRangeV2.js.map +1 -0
  38. package/dist/v2/data/useFreeBusy.d.ts +5 -0
  39. package/dist/v2/data/useFreeBusy.js +83 -0
  40. package/dist/v2/data/useFreeBusy.js.map +1 -0
  41. package/dist/v2/data/useKeyedLoad.js +47 -0
  42. package/dist/v2/data/useKeyedLoad.js.map +1 -0
  43. package/dist/v2/data/useRoomsV2.d.ts +28 -0
  44. package/dist/v2/data/useRoomsV2.js +45 -0
  45. package/dist/v2/data/useRoomsV2.js.map +1 -0
  46. package/dist/v2/day/DayPanel.d.ts +6 -0
  47. package/dist/v2/day/DayPanel.js +215 -0
  48. package/dist/v2/day/DayPanel.js.map +1 -0
  49. package/dist/v2/day/daySummary.d.ts +37 -0
  50. package/dist/v2/day/daySummary.js +37 -0
  51. package/dist/v2/day/daySummary.js.map +1 -0
  52. package/dist/v2/dialogs/CalendarDialogsV2.d.ts +1 -0
  53. package/dist/v2/dialogs/CalendarDialogsV2.js +17 -0
  54. package/dist/v2/dialogs/CalendarDialogsV2.js.map +1 -0
  55. package/dist/v2/dialogs/ShortcutsDialog.d.ts +4 -0
  56. package/dist/v2/dialogs/ShortcutsDialog.js +42 -0
  57. package/dist/v2/dialogs/ShortcutsDialog.js.map +1 -0
  58. package/dist/v2/events/eventLook.d.ts +46 -0
  59. package/dist/v2/events/eventLook.js +35 -0
  60. package/dist/v2/events/eventLook.js.map +1 -0
  61. package/dist/v2/events/eventModel.d.ts +92 -0
  62. package/dist/v2/events/eventModel.js +116 -0
  63. package/dist/v2/events/eventModel.js.map +1 -0
  64. package/dist/v2/events/localChanges.d.ts +4 -0
  65. package/dist/v2/events/localChanges.js +23 -0
  66. package/dist/v2/events/localChanges.js.map +1 -0
  67. package/dist/v2/format.d.ts +67 -0
  68. package/dist/v2/format.js +112 -0
  69. package/dist/v2/format.js.map +1 -0
  70. package/dist/v2/grid/AllDayRow.d.ts +20 -0
  71. package/dist/v2/grid/AllDayRow.js +94 -0
  72. package/dist/v2/grid/AllDayRow.js.map +1 -0
  73. package/dist/v2/grid/EventBlock.d.ts +21 -0
  74. package/dist/v2/grid/EventBlock.js +112 -0
  75. package/dist/v2/grid/EventBlock.js.map +1 -0
  76. package/dist/v2/grid/GridParts.d.ts +40 -0
  77. package/dist/v2/grid/GridParts.js +204 -0
  78. package/dist/v2/grid/GridParts.js.map +1 -0
  79. package/dist/v2/grid/QuickCreate.d.ts +1 -0
  80. package/dist/v2/grid/QuickCreate.js +175 -0
  81. package/dist/v2/grid/QuickCreate.js.map +1 -0
  82. package/dist/v2/grid/TimeGrid.d.ts +1 -0
  83. package/dist/v2/grid/TimeGrid.js +179 -0
  84. package/dist/v2/grid/TimeGrid.js.map +1 -0
  85. package/dist/v2/grid/geometry.d.ts +72 -0
  86. package/dist/v2/grid/geometry.js +85 -0
  87. package/dist/v2/grid/geometry.js.map +1 -0
  88. package/dist/v2/grid/layout.d.ts +24 -0
  89. package/dist/v2/grid/layout.js +77 -0
  90. package/dist/v2/grid/layout.js.map +1 -0
  91. package/dist/v2/grid/useGridDrag.d.ts +42 -0
  92. package/dist/v2/grid/useGridDrag.js +181 -0
  93. package/dist/v2/grid/useGridDrag.js.map +1 -0
  94. package/dist/v2/grid/useSlotCursor.d.ts +32 -0
  95. package/dist/v2/grid/useSlotCursor.js +57 -0
  96. package/dist/v2/grid/useSlotCursor.js.map +1 -0
  97. package/dist/v2/grid/workingHours.d.ts +21 -0
  98. package/dist/v2/grid/workingHours.js +101 -0
  99. package/dist/v2/grid/workingHours.js.map +1 -0
  100. package/dist/v2/hooks/useAvailableHeight.d.ts +2 -0
  101. package/dist/v2/hooks/useAvailableHeight.js +25 -0
  102. package/dist/v2/hooks/useAvailableHeight.js.map +1 -0
  103. package/dist/v2/hooks/useCalendarShortcuts.d.ts +9 -0
  104. package/dist/v2/hooks/useCalendarShortcuts.js +60 -0
  105. package/dist/v2/hooks/useCalendarShortcuts.js.map +1 -0
  106. package/dist/v2/hooks/useDebouncedValue.d.ts +1 -0
  107. package/dist/v2/hooks/useDebouncedValue.js +12 -0
  108. package/dist/v2/hooks/useDebouncedValue.js.map +1 -0
  109. package/dist/v2/hooks/useMediaQuery.d.ts +5 -0
  110. package/dist/v2/hooks/useMediaQuery.js +17 -0
  111. package/dist/v2/hooks/useMediaQuery.js.map +1 -0
  112. package/dist/v2/hooks/useNow.d.ts +2 -0
  113. package/dist/v2/hooks/useNow.js +31 -0
  114. package/dist/v2/hooks/useNow.js.map +1 -0
  115. package/dist/v2/limits.d.ts +6 -0
  116. package/dist/v2/limits.js +5 -0
  117. package/dist/v2/limits.js.map +1 -0
  118. package/dist/v2/list/EventListRow.d.ts +10 -0
  119. package/dist/v2/list/EventListRow.js +109 -0
  120. package/dist/v2/list/EventListRow.js.map +1 -0
  121. package/dist/v2/list/ListViewV2.d.ts +12 -0
  122. package/dist/v2/list/ListViewV2.js +90 -0
  123. package/dist/v2/list/ListViewV2.js.map +1 -0
  124. package/dist/v2/month/MonthView.d.ts +1 -0
  125. package/dist/v2/month/MonthView.js +324 -0
  126. package/dist/v2/month/MonthView.js.map +1 -0
  127. package/dist/v2/month/monthLayout.d.ts +39 -0
  128. package/dist/v2/month/monthLayout.js +29 -0
  129. package/dist/v2/month/monthLayout.js.map +1 -0
  130. package/dist/v2/page/CalendarChrome.d.ts +2 -0
  131. package/dist/v2/page/CalendarChrome.js +295 -0
  132. package/dist/v2/page/CalendarChrome.js.map +1 -0
  133. package/dist/v2/page/CalendarPageContext.d.ts +92 -0
  134. package/dist/v2/page/CalendarPageContext.js +11 -0
  135. package/dist/v2/page/CalendarPageContext.js.map +1 -0
  136. package/dist/v2/page/pageHelpers.d.ts +19 -0
  137. package/dist/v2/page/pageHelpers.js +39 -0
  138. package/dist/v2/page/pageHelpers.js.map +1 -0
  139. package/dist/v2/page/useCalendarPageModel.d.ts +2 -0
  140. package/dist/v2/page/useCalendarPageModel.js +198 -0
  141. package/dist/v2/page/useCalendarPageModel.js.map +1 -0
  142. package/dist/v2/page/viewState.d.ts +70 -0
  143. package/dist/v2/page/viewState.js +47 -0
  144. package/dist/v2/page/viewState.js.map +1 -0
  145. package/dist/v2/peek/EventPeek.d.ts +2 -0
  146. package/dist/v2/peek/EventPeek.js +92 -0
  147. package/dist/v2/peek/EventPeek.js.map +1 -0
  148. package/dist/v2/peek/PeekEvent.d.ts +4 -0
  149. package/dist/v2/peek/PeekEvent.js +443 -0
  150. package/dist/v2/peek/PeekEvent.js.map +1 -0
  151. package/dist/v2/peek/PeekParts.d.ts +14 -0
  152. package/dist/v2/peek/PeekParts.js +75 -0
  153. package/dist/v2/peek/PeekParts.js.map +1 -0
  154. package/dist/v2/prefs/calendarPrefs.d.ts +2 -2
  155. package/dist/v2/prefs/calendarPrefs.js +35 -34
  156. package/dist/v2/prefs/calendarPrefs.js.map +1 -1
  157. package/dist/v2/rail/CalendarRail.d.ts +3 -0
  158. package/dist/v2/rail/CalendarRail.js +284 -0
  159. package/dist/v2/rail/CalendarRail.js.map +1 -0
  160. package/dist/v2/rail/railStatus.d.ts +54 -0
  161. package/dist/v2/rail/railStatus.js +84 -0
  162. package/dist/v2/rail/railStatus.js.map +1 -0
  163. package/dist/v2/rail/syncWords.d.ts +10 -0
  164. package/dist/v2/rail/syncWords.js +75 -0
  165. package/dist/v2/rail/syncWords.js.map +1 -0
  166. package/dist/v2/rail/useMonthEventDates.d.ts +4 -0
  167. package/dist/v2/rail/useMonthEventDates.js +30 -0
  168. package/dist/v2/rail/useMonthEventDates.js.map +1 -0
  169. package/dist/v2/routes.js +4 -1
  170. package/dist/v2/routes.js.map +1 -1
  171. package/dist/v2/search/SearchResults.d.ts +1 -0
  172. package/dist/v2/search/SearchResults.js +88 -0
  173. package/dist/v2/search/SearchResults.js.map +1 -0
  174. package/dist/v2/search/searchModel.d.ts +20 -0
  175. package/dist/v2/search/searchModel.js +22 -0
  176. package/dist/v2/search/searchModel.js.map +1 -0
  177. package/dist/v2/state/calendarV2Store.d.ts +4 -1
  178. package/dist/v2/state/calendarV2Store.js +3 -1
  179. package/dist/v2/state/calendarV2Store.js.map +1 -1
  180. package/dist/v2/state/useCalendarV2Navigation.d.ts +1 -0
  181. package/dist/v2/state/useCalendarV2Navigation.js +4 -1
  182. package/dist/v2/state/useCalendarV2Navigation.js.map +1 -1
  183. package/dist/v2/states/CalendarStates.d.ts +18 -0
  184. package/dist/v2/states/CalendarStates.js +122 -0
  185. package/dist/v2/states/CalendarStates.js.map +1 -0
  186. package/dist/v2/styles.d.ts +32 -0
  187. package/dist/v2/styles.js +10 -0
  188. package/dist/v2/styles.js.map +1 -0
  189. package/dist/v2/time/calendarTime.js +121 -35
  190. package/dist/v2/time/calendarTime.js.map +1 -1
  191. package/dist/v2/types.d.ts +22 -2
  192. package/package.json +1 -1
@@ -0,0 +1,399 @@
1
+ import { CalendarV2CreateEventDocument as e, CalendarV2CreateReminderDocument as t, CalendarV2DeleteEventDocument as n, CalendarV2DuplicateEventDocument as r, CalendarV2EventIcsDocument as i, CalendarV2RespondToEventDocument as a, CalendarV2RestoreEventDocument as o, CalendarV2TriggerSyncDocument as s, CalendarV2UpdateEventTimesDocument as c } from "../../generated/wspace-operations.js";
2
+ import { myPart as l } from "../events/eventModel.js";
3
+ import { formatDay as u, formatDuration as d, formatInstantRange as f, formatInstantTime as ee } from "../format.js";
4
+ import { instantToZoned as p } from "../time/calendarTime.js";
5
+ import { REMINDER_IN_APP as m, RSVP_STATUS as h, SCOPE_ALL_EVENTS as te } from "./enums.js";
6
+ import { graphQLErrorCode as ne } from "./errors.js";
7
+ import { invalidateCalendarEvents as g } from "./invalidation.js";
8
+ import { SerialWrites as _ } from "./serialWrites.js";
9
+ import { useCallback as v, useEffect as re, useMemo as y, useRef as b, useState as x } from "react";
10
+ import { useConfirm as S, useNotify as C } from "@burdenoff/fe-libs/ui";
11
+ import { useApolloClient as w } from "@apollo/client/react";
12
+ function ie(e, t) {
13
+ return e.guests.filter((e) => !e.organizer && e.userId !== t).length;
14
+ }
15
+ function T(e, t) {
16
+ let n = p(e, t.timeZone).date;
17
+ return u(n, t.format, "mid");
18
+ }
19
+ function E(e, t) {
20
+ if (typeof document > "u" || typeof URL.createObjectURL != "function") return !1;
21
+ let n = URL.createObjectURL(new Blob([e], { type: "text/calendar;charset=utf-8" })), r = document.createElement("a");
22
+ return r.href = n, r.download = t, r.rel = "noopener", document.body.appendChild(r), r.click(), r.remove(), setTimeout(() => URL.revokeObjectURL(n), 1e3), !0;
23
+ }
24
+ function D(e) {
25
+ return `${e.normalize("NFKD").replace(/[^\p{L}\p{N}]+/gu, "-").replace(/^-+|-+$/g, "").slice(0, 60).toLowerCase() || "event"}.ics`;
26
+ }
27
+ function O(l) {
28
+ let O = w(), k = C(), A = S(), [j, M] = x(/* @__PURE__ */ new Map()), [N, ae] = x(/* @__PURE__ */ new Set()), [P, F] = x(/* @__PURE__ */ new Map()), [I] = x(() => new _()), L = b({
29
+ times: /* @__PURE__ */ new Set(),
30
+ answers: /* @__PURE__ */ new Set()
31
+ }), R = b(l);
32
+ re(() => {
33
+ R.current = l;
34
+ });
35
+ let z = v((e, t) => {
36
+ M((n) => {
37
+ let r = new Map(n);
38
+ return t ? r.set(e, t) : r.delete(e), r;
39
+ });
40
+ }, []), B = v((e, t) => {
41
+ ae((n) => {
42
+ let r = new Set(n);
43
+ return t ? r.add(e) : r.delete(e), r;
44
+ });
45
+ }, []), V = v((e, t) => {
46
+ F((n) => {
47
+ let r = new Map(n);
48
+ return t ? r.set(e, t) : r.delete(e), r;
49
+ });
50
+ }, []), H = v(async (e, t) => {
51
+ await O.mutate({
52
+ mutation: c,
53
+ variables: {
54
+ id: e,
55
+ input: {
56
+ startTime: t.start.toISOString(),
57
+ endTime: t.end.toISOString()
58
+ }
59
+ }
60
+ });
61
+ }, [O]), U = v(async (e, t, r) => {
62
+ await O.mutate({
63
+ mutation: n,
64
+ variables: {
65
+ id: e,
66
+ holdSeconds: t,
67
+ scope: r ?? null
68
+ }
69
+ });
70
+ }, [O]), W = v((e, t) => {
71
+ let { tr: n } = R.current, r = ne(t), i = r === "FORBIDDEN" || r === "UNAUTHORIZED" ? n("calendar.v2.actionForbidden", "You don’t have permission to change this event.") : r === "NOT_FOUND" ? n("calendar.v2.actionGone", "It may have been deleted or moved by someone else.") : n("calendar.v2.actionRetry", "Nothing was changed. Try again in a moment.");
72
+ k({
73
+ title: e,
74
+ description: i,
75
+ tone: "error"
76
+ });
77
+ }, [k]), G = v(async (e, t, n) => {
78
+ let r = R.current, i = {
79
+ start: e.start,
80
+ end: e.end
81
+ }, a = `times:${e.id}`, o = I.claim(a), s = L.current.times;
82
+ s.delete(e.id), z(e.id, t);
83
+ try {
84
+ await I.run(a, () => H(e.id, t));
85
+ } catch (t) {
86
+ if (!I.isNewest(a, o)) return;
87
+ z(e.id, null), W(n === "move" ? r.tr("calendar.v2.moveFailed", "Couldn’t move “{{title}}”", { title: e.title }) : r.tr("calendar.v2.resizeFailed", "Couldn’t change “{{title}}”", { title: e.title }), t);
88
+ return;
89
+ }
90
+ if (I.isNewest(a, o) && s.add(e.id), g(), !I.isNewest(a, o)) return;
91
+ let c = Math.round((t.end.getTime() - t.start.getTime()) / 6e4), l = n === "move" ? r.tr("calendar.v2.moved", "Moved “{{title}}” to {{day}}, {{time}}.", {
92
+ title: e.title,
93
+ day: T(t.start, r),
94
+ time: f(t.start, t.end, r.timeZone, r.format)
95
+ }) : r.tr("calendar.v2.resized", "“{{title}}” now ends at {{time}} ({{length}}).", {
96
+ title: e.title,
97
+ time: ee(t.end, r.timeZone, r.format),
98
+ length: d(c, r.durationWords)
99
+ });
100
+ k({
101
+ title: l,
102
+ tone: "success",
103
+ undoneTitle: r.tr("calendar.v2.movedBack", "Put back."),
104
+ undoFailedTitle: r.tr("calendar.v2.moveBackFailed", "Couldn’t put it back."),
105
+ undo: async () => {
106
+ let t = I.claim(a);
107
+ s.delete(e.id), z(e.id, i);
108
+ try {
109
+ await I.run(a, () => H(e.id, i));
110
+ } catch (n) {
111
+ throw I.isNewest(a, t) && z(e.id, null), n;
112
+ }
113
+ I.isNewest(a, t) && s.add(e.id), g();
114
+ }
115
+ });
116
+ }, [
117
+ W,
118
+ k,
119
+ z,
120
+ H,
121
+ I
122
+ ]), K = v(async (e) => {
123
+ let t = R.current;
124
+ if (e.isRecurring) {
125
+ if (!await A({
126
+ title: t.tr("calendar.v2.deleteSeriesTitle", "Delete every event in “{{title}}”?", { title: e.title }),
127
+ description: t.tr("calendar.v2.deleteSeriesBody", "This is a repeating event. Every event in the series is deleted, and its guests are told. This can’t be undone."),
128
+ tone: "danger",
129
+ confirmLabel: t.tr("calendar.v2.deleteSeries", "Delete the series"),
130
+ cancelLabel: t.tr("calendar.v2.keep", "Keep it")
131
+ })) return;
132
+ B(e.id, !0);
133
+ try {
134
+ await U(e.id, 0, te);
135
+ } catch (n) {
136
+ B(e.id, !1), W(t.tr("calendar.v2.deleteFailed", "Couldn’t delete “{{title}}”", { title: e.title }), n);
137
+ return;
138
+ }
139
+ g(), k({
140
+ title: t.tr("calendar.v2.deletedSeries", "Deleted every event in “{{title}}”.", { title: e.title }),
141
+ tone: "success"
142
+ });
143
+ return;
144
+ }
145
+ B(e.id, !0);
146
+ try {
147
+ await U(e.id, 8);
148
+ } catch (n) {
149
+ B(e.id, !1), W(t.tr("calendar.v2.deleteFailed", "Couldn’t delete “{{title}}”", { title: e.title }), n);
150
+ return;
151
+ }
152
+ g();
153
+ let n = ie(e, t.me);
154
+ k({
155
+ title: t.tr("calendar.v2.deleted", "Deleted “{{title}}”.", { title: e.title }),
156
+ description: n === 0 ? void 0 : n === 1 ? t.tr("calendar.v2.deletedTellOne", "Its guest hears it’s cancelled when this closes.") : t.tr("calendar.v2.deletedTellMany", "{{count}} guests hear it’s cancelled when this closes.", { count: n }),
157
+ tone: "success",
158
+ duration: 8e3,
159
+ undoneTitle: t.tr("calendar.v2.restored", "Restored. Nobody was told."),
160
+ undoFailedTitle: t.tr("calendar.v2.restoreFailed", "Too late to undo: it’s deleted."),
161
+ undo: async () => {
162
+ await O.mutate({
163
+ mutation: o,
164
+ variables: { id: e.id }
165
+ }), B(e.id, !1), g();
166
+ }
167
+ });
168
+ }, [
169
+ O,
170
+ A,
171
+ U,
172
+ W,
173
+ k,
174
+ B
175
+ ]), q = v(async (e, t) => {
176
+ let n = R.current, r = P.get(e.id) ?? e.myResponse ?? "NO_RESPONSE";
177
+ if (r === t) return;
178
+ let i = `answer:${e.id}`, o = (t) => I.run(i, async () => {
179
+ await O.mutate({
180
+ mutation: a,
181
+ variables: {
182
+ eventId: e.id,
183
+ status: h[t]
184
+ }
185
+ });
186
+ }), s = I.claim(i), c = L.current.answers;
187
+ c.delete(e.id), V(e.id, t);
188
+ try {
189
+ await o(t);
190
+ } catch (t) {
191
+ if (!I.isNewest(i, s)) return;
192
+ V(e.id, null), W(n.tr("calendar.v2.answerFailed", "Couldn’t send your answer to “{{title}}”", { title: e.title }), t);
193
+ return;
194
+ }
195
+ if (I.isNewest(i, s) && c.add(e.id), g(), !I.isNewest(i, s)) return;
196
+ let l = t === "ACCEPTED" ? n.tr("calendar.v2.answeredYes", "You’re going to “{{title}}”. The organiser is told.", { title: e.title }) : t === "TENTATIVE" ? n.tr("calendar.v2.answeredMaybe", "You’re a maybe for “{{title}}”.", { title: e.title }) : n.tr("calendar.v2.answeredNo", "You declined “{{title}}”.", { title: e.title });
197
+ k({
198
+ title: l,
199
+ description: t === "DECLINED" && !n.showDeclined ? n.tr("calendar.v2.declinedHidden", "It’s hidden now. “Show events I declined” is in Calendar settings.") : void 0,
200
+ tone: "success",
201
+ undoneTitle: n.tr("calendar.v2.answerUndone", "Your answer is back as it was."),
202
+ undo: async () => {
203
+ let t = I.claim(i);
204
+ c.delete(e.id), V(e.id, r);
205
+ try {
206
+ await o(r);
207
+ } catch (n) {
208
+ throw I.isNewest(i, t) && V(e.id, null), n;
209
+ }
210
+ I.isNewest(i, t) && c.add(e.id), g();
211
+ }
212
+ });
213
+ }, [
214
+ P,
215
+ O,
216
+ W,
217
+ k,
218
+ V,
219
+ I
220
+ ]), J = v(async (e) => {
221
+ let t = R.current, n = null;
222
+ try {
223
+ n = (await O.mutate({
224
+ mutation: r,
225
+ variables: {
226
+ eventId: e.id,
227
+ newStartTime: e.start.toISOString()
228
+ }
229
+ })).data?.duplicateEvent.id ?? null;
230
+ } catch (n) {
231
+ W(t.tr("calendar.v2.duplicateFailed", "Couldn’t copy “{{title}}”", { title: e.title }), n);
232
+ return;
233
+ }
234
+ g(), k({
235
+ title: t.tr("calendar.v2.duplicated", "Made a copy of “{{title}}” at the same time.", { title: e.title }),
236
+ description: t.tr("calendar.v2.duplicatedHint", "Drag it where you want it, or open it to change it."),
237
+ tone: "success",
238
+ undoneTitle: t.tr("calendar.v2.copyRemoved", "The copy is gone."),
239
+ undo: n ? async () => {
240
+ n && (await U(n, 0), g());
241
+ } : void 0
242
+ });
243
+ }, [
244
+ O,
245
+ U,
246
+ W,
247
+ k
248
+ ]), Y = v(async (n) => {
249
+ let r = R.current, i = null;
250
+ try {
251
+ i = (await O.mutate({
252
+ mutation: e,
253
+ variables: { input: {
254
+ calendarId: n.calendarId,
255
+ title: n.title,
256
+ startTime: n.start.toISOString(),
257
+ endTime: n.end.toISOString(),
258
+ allDay: n.allDay,
259
+ eventType: "MEETING",
260
+ timezone: r.timeZone
261
+ } }
262
+ })).data?.createEvent.id ?? null;
263
+ } catch (e) {
264
+ return W(r.tr("calendar.v2.createFailed", "Couldn’t add “{{title}}”", { title: n.title }), e), !1;
265
+ }
266
+ let a = !1;
267
+ if (i && r.defaultReminder !== null) try {
268
+ await O.mutate({
269
+ mutation: t,
270
+ variables: { input: {
271
+ eventId: i,
272
+ minutesBefore: r.defaultReminder,
273
+ channel: m
274
+ } }
275
+ });
276
+ } catch {
277
+ a = !0;
278
+ }
279
+ g();
280
+ let o = p(n.start, r.timeZone).date;
281
+ return k({
282
+ title: r.tr("calendar.v2.created", "Added “{{title}}”, {{day}} {{time}}.", {
283
+ title: n.title,
284
+ day: u(o, r.format, "short"),
285
+ time: n.allDay ? r.tr("calendar.v2.allDayLower", "all day") : f(n.start, n.end, r.timeZone, r.format)
286
+ }),
287
+ description: a ? r.tr("calendar.v2.reminderMissed", "Its reminder wasn’t added. Open the event to add one.") : void 0,
288
+ tone: a ? "warning" : "success",
289
+ undoneTitle: r.tr("calendar.v2.createUndone", "Removed."),
290
+ undo: i ? async () => {
291
+ i && (await U(i, 0), g());
292
+ } : void 0
293
+ }), !0;
294
+ }, [
295
+ O,
296
+ U,
297
+ W,
298
+ k
299
+ ]), X = v(async (e) => {
300
+ let t = R.current;
301
+ try {
302
+ let t = (await O.query({
303
+ query: i,
304
+ variables: { eventId: e.id },
305
+ fetchPolicy: "network-only"
306
+ })).data?.exportEventToIcs;
307
+ if (!t || !E(t, D(e.title))) throw Error("No file");
308
+ } catch {
309
+ k({
310
+ title: t.tr("calendar.v2.icsFailed", "Couldn’t download “{{title}}”", { title: e.title }),
311
+ description: t.tr("calendar.v2.actionRetry", "Nothing was changed. Try again in a moment."),
312
+ tone: "error"
313
+ });
314
+ }
315
+ }, [O, k]), Z = v(async (e, t) => {
316
+ let n = R.current;
317
+ try {
318
+ await navigator.clipboard.writeText(e), k({
319
+ title: t,
320
+ tone: "success"
321
+ });
322
+ } catch {
323
+ k({
324
+ title: n.tr("calendar.v2.copyFailed", "Couldn’t copy. Select the text and copy it instead."),
325
+ tone: "error"
326
+ });
327
+ }
328
+ }, [k]), Q = v(async (e) => {
329
+ let t = R.current;
330
+ if (e.sync) {
331
+ try {
332
+ await O.mutate({
333
+ mutation: s,
334
+ variables: { syncId: e.sync.id }
335
+ });
336
+ } catch (n) {
337
+ W(t.tr("calendar.v2.checkFailed", "Couldn’t check “{{name}}” now", { name: e.name }), n);
338
+ return;
339
+ }
340
+ t.reloadCalendars(), g(), k({
341
+ title: t.tr("calendar.v2.checked", "Checked “{{name}}” for changes.", { name: e.name }),
342
+ tone: "success"
343
+ });
344
+ }
345
+ }, [
346
+ O,
347
+ W,
348
+ k
349
+ ]), $ = v((e) => {
350
+ let t = new Map(e.map((e) => [e.id, e])), n = new Set(L.current.times), r = new Set(L.current.answers);
351
+ L.current.times.clear(), L.current.answers.clear(), M((e) => {
352
+ if (e.size === 0) return e;
353
+ let r = !1, i = new Map(e);
354
+ for (let [a, o] of e) {
355
+ let e = t.get(a);
356
+ (n.has(a) || e && e.start.getTime() === o.start.getTime() && e.end.getTime() === o.end.getTime()) && (i.delete(a), r = !0);
357
+ }
358
+ return r ? i : e;
359
+ }), F((e) => {
360
+ if (e.size === 0) return e;
361
+ let n = !1, i = new Map(e);
362
+ for (let [a, o] of e) (r.has(a) || t.get(a)?.myResponse === o) && (i.delete(a), n = !0);
363
+ return n ? i : e;
364
+ });
365
+ }, []);
366
+ return y(() => ({
367
+ overrides: j,
368
+ removedIds: N,
369
+ answers: P,
370
+ changeTimes: G,
371
+ remove: K,
372
+ respond: q,
373
+ duplicate: J,
374
+ quickCreate: Y,
375
+ downloadIcs: X,
376
+ copyText: Z,
377
+ checkSyncNow: Q,
378
+ settle: $
379
+ }), [
380
+ P,
381
+ G,
382
+ Q,
383
+ Z,
384
+ X,
385
+ J,
386
+ j,
387
+ Y,
388
+ K,
389
+ N,
390
+ q,
391
+ $
392
+ ]);
393
+ }
394
+ function k(e, t, n) {
395
+ return l(e, n) === "organizer" ? null : t.get(e.id) ?? e.myResponse;
396
+ }
397
+ export { k as answerFor, D as icsFileName, O as useEventActions };
398
+
399
+ //# sourceMappingURL=useEventActions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEventActions.js","names":["guestsToTell","event","guest","me","dayWords","day","instantToZoned","instant","context","formatDay","saveFile","url","text","link","name","icsFileName","title","useEventActions","client","useApolloClient","notify","useNotify","confirm","useConfirm","overrides","setOverrides","useState","removedIds","setRemovedIds","answers","setAnswers","writes","SerialWrites","confirmedRef","useRef","contextRef","setOverride","useCallback","next","current","times","id","setRemoved","removed","setAnswer","answer","updateTimes","CalendarV2UpdateEventTimesDocument","deleteNow","CalendarV2DeleteEventDocument","scope","failed","code","graphQLErrorCode","error","description","tr","changeTimes","ctx","before","key","ticket","confirmed","kind","invalidateCalendarEvents","minutes","formatInstantRange","formatInstantTime","formatDuration","undoTicket","remove","SCOPE_ALL_EVENTS","guests","CalendarV2RestoreEventDocument","respond","send","CalendarV2RespondToEventDocument","RSVP_STATUS","status","duplicate","copyId","CalendarV2DuplicateEventDocument","quickCreate","createdId","CalendarV2CreateEventDocument","input","reminderMissed","CalendarV2CreateReminderDocument","REMINDER_IN_APP","downloadIcs","CalendarV2EventIcsDocument","copyText","done","checkSyncNow","calendar","CalendarV2TriggerSyncDocument","settle","byId","events","confirmedTimes","confirmedAnswers","changed","loaded","useMemo","answerFor","myPart"],"sources":["../../../src/v2/data/useEventActions.ts"],"sourcesContent":["/**\n * What the redesigned calendar does to events (BOFF-15698 A1), each with its Undo:\n *\n * - **Move and resize** (drag, Shift + arrows): `updateEvent` with the new times; Undo is a\n * second `updateEvent` with the old ones (§6 B6). The event shows at its new place at once\n * (`overrides`) and goes back if the service refuses.\n * - **Delete**: `deleteEvent(holdSeconds: 8)`. The service holds the delete for 8 seconds and\n * tells the guests only when the window ends (decision 7); Undo is `restoreEvent`. A repeating\n * series takes no hold: it asks first, then deletes every event (`ALL_EVENTS`), with no Undo.\n * - **Answer an invitation**: `respondToEvent`; Undo answers as before.\n * - **Duplicate**: `duplicateEvent` at the same time; Undo deletes the copy.\n * - **Quick create**: `createEvent` (and the person's default reminder); Undo deletes it.\n *\n * Moves and answers to one event go one at a time (`SerialWrites`): a second one given before\n * the first finished waits for it, so the service ends with the latest, and only the newest\n * one's outcome shows (an older one failing late doesn't undo the newer one on the page).\n * Every change reloads the views (`invalidateCalendarEvents`). A change shows here until the\n * service confirms it; after that, the next reload (which starts after the confirmation) is\n * the truth, even when it no longer holds the event or someone has changed it since.\n */\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { useApolloClient } from '@apollo/client/react';\nimport { useConfirm, useNotify, type DateValue } from '@burdenoff/fe-libs/ui';\nimport {\n CalendarV2CreateEventDocument,\n CalendarV2CreateReminderDocument,\n CalendarV2DeleteEventDocument,\n CalendarV2DuplicateEventDocument,\n CalendarV2EventIcsDocument,\n CalendarV2RespondToEventDocument,\n CalendarV2RestoreEventDocument,\n CalendarV2TriggerSyncDocument,\n CalendarV2UpdateEventTimesDocument,\n type CalendarV2CreateEventMutation,\n type CalendarV2CreateEventMutationVariables,\n type CalendarV2CreateReminderMutation,\n type CalendarV2CreateReminderMutationVariables,\n type CalendarV2DeleteEventMutation,\n type CalendarV2DeleteEventMutationVariables,\n type CalendarV2DuplicateEventMutation,\n type CalendarV2DuplicateEventMutationVariables,\n type CalendarV2EventIcsQuery,\n type CalendarV2EventIcsQueryVariables,\n type CalendarV2RespondToEventMutation,\n type CalendarV2RespondToEventMutationVariables,\n type CalendarV2RestoreEventMutation,\n type CalendarV2RestoreEventMutationVariables,\n type CalendarV2TriggerSyncMutation,\n type CalendarV2TriggerSyncMutationVariables,\n type CalendarV2UpdateEventTimesMutation,\n type CalendarV2UpdateEventTimesMutationVariables,\n} from '../../generated/wspace-operations';\nimport { myPart } from '../events/eventModel';\nimport {\n formatDay,\n formatDuration,\n formatInstantRange,\n formatInstantTime,\n type CalendarFormat,\n type DurationWords,\n} from '../format';\nimport type { UpdateScope } from '../../generated/wspace-types';\nimport type { EventTimes } from '../grid/geometry';\nimport { instantToZoned } from '../time/calendarTime';\nimport type { CalendarEventV2, CalendarV2, EventResponseV2 } from '../types';\nimport { EVENT_TYPE_MEETING, REMINDER_IN_APP, RSVP_STATUS, SCOPE_ALL_EVENTS } from './enums';\nimport { graphQLErrorCode } from './errors';\nimport { invalidateCalendarEvents } from './invalidation';\nimport { SerialWrites } from './serialWrites';\n\n/** The Undo window of a delete, in seconds: the service holds it this long (B6). */\nexport const DELETE_HOLD_SECONDS = 8;\n\nexport type Tr = (\n key: string,\n fallback: string,\n params?: Record<string, string | number>\n) => string;\n\n/** What the page knows that the messages need. */\nexport interface EventActionsContext {\n tr: Tr;\n format: CalendarFormat;\n durationWords: DurationWords;\n timeZone: string;\n me: string | null;\n showDeclined: boolean;\n defaultReminder: number | null;\n /** Loads the whole calendar list again (every page), e.g. after a sync was checked. */\n reloadCalendars: () => void;\n}\n\nexport type Answer = 'ACCEPTED' | 'TENTATIVE' | 'DECLINED';\n\nexport interface QuickCreateInput {\n calendarId: string;\n title: string;\n start: Date;\n end: Date;\n allDay: boolean;\n}\n\nexport interface EventActions {\n /** Event times shown before the service confirms a move (by event id). */\n overrides: ReadonlyMap<string, EventTimes>;\n /** Events deleted here, hidden until the views reload without them. */\n removedIds: ReadonlySet<string>;\n /** Answers given here, shown before the views reload. */\n answers: ReadonlyMap<string, EventResponseV2>;\n changeTimes: (event: CalendarEventV2, next: EventTimes, kind: 'move' | 'resize') => Promise<void>;\n remove: (event: CalendarEventV2) => Promise<void>;\n respond: (event: CalendarEventV2, answer: Answer) => Promise<void>;\n duplicate: (event: CalendarEventV2) => Promise<void>;\n quickCreate: (input: QuickCreateInput) => Promise<boolean>;\n downloadIcs: (event: CalendarEventV2) => Promise<void>;\n copyText: (text: string, done: string) => Promise<void>;\n checkSyncNow: (calendar: CalendarV2) => Promise<void>;\n /** Drops changes the reloaded events now show (the service confirmed them). */\n settle: (events: readonly CalendarEventV2[]) => void;\n}\n\nfunction guestsToTell(event: CalendarEventV2, me: string | null): number {\n return event.guests.filter((guest) => !guest.organizer && guest.userId !== me).length;\n}\n\n/** The whole day of an instant, for messages: \"Wednesday 18 Nov\". */\nfunction dayWords(instant: Date, context: EventActionsContext): string {\n const day: DateValue = instantToZoned(instant, context.timeZone).date;\n return formatDay(day, context.format, 'mid');\n}\n\nfunction saveFile(text: string, name: string): boolean {\n if (typeof document === 'undefined' || typeof URL.createObjectURL !== 'function') return false;\n const url = URL.createObjectURL(new Blob([text], { type: 'text/calendar;charset=utf-8' }));\n const link = document.createElement('a');\n link.href = url;\n link.download = name;\n link.rel = 'noopener';\n document.body.appendChild(link);\n link.click();\n link.remove();\n setTimeout(() => URL.revokeObjectURL(url), 1000);\n return true;\n}\n\n/** A file name from an event's title: letters, digits and dashes. */\nexport function icsFileName(title: string): string {\n const base = title\n .normalize('NFKD')\n .replace(/[^\\p{L}\\p{N}]+/gu, '-')\n .replace(/^-+|-+$/g, '')\n .slice(0, 60)\n .toLowerCase();\n return `${base || 'event'}.ics`;\n}\n\nexport function useEventActions(context: EventActionsContext): EventActions {\n const client = useApolloClient();\n const notify = useNotify();\n const confirm = useConfirm();\n const [overrides, setOverrides] = useState<ReadonlyMap<string, EventTimes>>(new Map());\n const [removedIds, setRemovedIds] = useState<ReadonlySet<string>>(new Set());\n const [answers, setAnswers] = useState<ReadonlyMap<string, EventResponseV2>>(new Map());\n const [writes] = useState(() => new SerialWrites());\n // Event ids whose shown time or answer the service has confirmed: `settle` drops them.\n const confirmedRef = useRef({ times: new Set<string>(), answers: new Set<string>() });\n const contextRef = useRef(context);\n useEffect(() => {\n contextRef.current = context;\n });\n\n const setOverride = useCallback((id: string, times: EventTimes | null) => {\n setOverrides((current) => {\n const next = new Map(current);\n if (times) next.set(id, times);\n else next.delete(id);\n return next;\n });\n }, []);\n\n const setRemoved = useCallback((id: string, removed: boolean) => {\n setRemovedIds((current) => {\n const next = new Set(current);\n if (removed) next.add(id);\n else next.delete(id);\n return next;\n });\n }, []);\n\n const setAnswer = useCallback((id: string, answer: EventResponseV2 | null) => {\n setAnswers((current) => {\n const next = new Map(current);\n if (answer) next.set(id, answer);\n else next.delete(id);\n return next;\n });\n }, []);\n\n const updateTimes = useCallback(\n async (id: string, times: EventTimes) => {\n await client.mutate<\n CalendarV2UpdateEventTimesMutation,\n CalendarV2UpdateEventTimesMutationVariables\n >({\n mutation: CalendarV2UpdateEventTimesDocument,\n variables: {\n id,\n input: { startTime: times.start.toISOString(), endTime: times.end.toISOString() },\n },\n });\n },\n [client]\n );\n\n const deleteNow = useCallback(\n async (id: string, holdSeconds: number, scope?: UpdateScope) => {\n await client.mutate<CalendarV2DeleteEventMutation, CalendarV2DeleteEventMutationVariables>({\n mutation: CalendarV2DeleteEventDocument,\n variables: { id, holdSeconds, scope: scope ?? null },\n });\n },\n [client]\n );\n\n const failed = useCallback(\n (title: string, error: unknown) => {\n const { tr } = contextRef.current;\n const code = graphQLErrorCode(error);\n const description =\n code === 'FORBIDDEN' || code === 'UNAUTHORIZED'\n ? tr('calendar.v2.actionForbidden', 'You don’t have permission to change this event.')\n : code === 'NOT_FOUND'\n ? tr('calendar.v2.actionGone', 'It may have been deleted or moved by someone else.')\n : tr('calendar.v2.actionRetry', 'Nothing was changed. Try again in a moment.');\n notify({ title, description, tone: 'error' });\n },\n [notify]\n );\n\n const changeTimes = useCallback<EventActions['changeTimes']>(\n async (event, next, kind) => {\n const ctx = contextRef.current;\n const before: EventTimes = { start: event.start, end: event.end };\n const key = `times:${event.id}`;\n const ticket = writes.claim(key);\n const confirmed = confirmedRef.current.times;\n confirmed.delete(event.id);\n setOverride(event.id, next);\n try {\n await writes.run(key, () => updateTimes(event.id, next));\n } catch (error) {\n // A newer change to this event was asked for since: its outcome is the one to show.\n if (!writes.isNewest(key, ticket)) return;\n setOverride(event.id, null);\n failed(\n kind === 'move'\n ? ctx.tr('calendar.v2.moveFailed', 'Couldn’t move “{{title}}”', { title: event.title })\n : ctx.tr('calendar.v2.resizeFailed', 'Couldn’t change “{{title}}”', {\n title: event.title,\n }),\n error\n );\n return;\n }\n if (writes.isNewest(key, ticket)) confirmed.add(event.id);\n invalidateCalendarEvents();\n if (!writes.isNewest(key, ticket)) return;\n const minutes = Math.round((next.end.getTime() - next.start.getTime()) / 60_000);\n const title =\n kind === 'move'\n ? ctx.tr('calendar.v2.moved', 'Moved “{{title}}” to {{day}}, {{time}}.', {\n title: event.title,\n day: dayWords(next.start, ctx),\n time: formatInstantRange(next.start, next.end, ctx.timeZone, ctx.format),\n })\n : ctx.tr('calendar.v2.resized', '“{{title}}” now ends at {{time}} ({{length}}).', {\n title: event.title,\n time: formatInstantTime(next.end, ctx.timeZone, ctx.format),\n length: formatDuration(minutes, ctx.durationWords),\n });\n notify({\n title,\n tone: 'success',\n undoneTitle: ctx.tr('calendar.v2.movedBack', 'Put back.'),\n undoFailedTitle: ctx.tr('calendar.v2.moveBackFailed', 'Couldn’t put it back.'),\n undo: async () => {\n const undoTicket = writes.claim(key);\n confirmed.delete(event.id);\n setOverride(event.id, before);\n try {\n await writes.run(key, () => updateTimes(event.id, before));\n } catch (error) {\n if (writes.isNewest(key, undoTicket)) setOverride(event.id, null);\n throw error;\n }\n if (writes.isNewest(key, undoTicket)) confirmed.add(event.id);\n invalidateCalendarEvents();\n },\n });\n },\n [failed, notify, setOverride, updateTimes, writes]\n );\n\n const remove = useCallback<EventActions['remove']>(\n async (event) => {\n const ctx = contextRef.current;\n if (event.isRecurring) {\n const sure = await confirm({\n title: ctx.tr('calendar.v2.deleteSeriesTitle', 'Delete every event in “{{title}}”?', {\n title: event.title,\n }),\n description: ctx.tr(\n 'calendar.v2.deleteSeriesBody',\n 'This is a repeating event. Every event in the series is deleted, and its guests are told. This can’t be undone.'\n ),\n tone: 'danger',\n confirmLabel: ctx.tr('calendar.v2.deleteSeries', 'Delete the series'),\n cancelLabel: ctx.tr('calendar.v2.keep', 'Keep it'),\n });\n if (!sure) return;\n setRemoved(event.id, true);\n try {\n await deleteNow(event.id, 0, SCOPE_ALL_EVENTS);\n } catch (error) {\n setRemoved(event.id, false);\n failed(\n ctx.tr('calendar.v2.deleteFailed', 'Couldn’t delete “{{title}}”', {\n title: event.title,\n }),\n error\n );\n return;\n }\n invalidateCalendarEvents();\n notify({\n title: ctx.tr('calendar.v2.deletedSeries', 'Deleted every event in “{{title}}”.', {\n title: event.title,\n }),\n tone: 'success',\n });\n return;\n }\n setRemoved(event.id, true);\n try {\n await deleteNow(event.id, DELETE_HOLD_SECONDS);\n } catch (error) {\n setRemoved(event.id, false);\n failed(\n ctx.tr('calendar.v2.deleteFailed', 'Couldn’t delete “{{title}}”', { title: event.title }),\n error\n );\n return;\n }\n invalidateCalendarEvents();\n const guests = guestsToTell(event, ctx.me);\n notify({\n title: ctx.tr('calendar.v2.deleted', 'Deleted “{{title}}”.', { title: event.title }),\n description:\n guests === 0\n ? undefined\n : guests === 1\n ? ctx.tr(\n 'calendar.v2.deletedTellOne',\n 'Its guest hears it’s cancelled when this closes.'\n )\n : ctx.tr(\n 'calendar.v2.deletedTellMany',\n '{{count}} guests hear it’s cancelled when this closes.',\n { count: guests }\n ),\n tone: 'success',\n duration: DELETE_HOLD_SECONDS * 1000,\n undoneTitle: ctx.tr('calendar.v2.restored', 'Restored. Nobody was told.'),\n undoFailedTitle: ctx.tr('calendar.v2.restoreFailed', 'Too late to undo: it’s deleted.'),\n // Past the window (`UNDO_WINDOW_PASSED`) or already gone (NOT_FOUND), the restore is\n // refused and the toast says it is too late: the event stays deleted.\n undo: async () => {\n await client.mutate<\n CalendarV2RestoreEventMutation,\n CalendarV2RestoreEventMutationVariables\n >({\n mutation: CalendarV2RestoreEventDocument,\n variables: { id: event.id },\n });\n setRemoved(event.id, false);\n invalidateCalendarEvents();\n },\n });\n },\n [client, confirm, deleteNow, failed, notify, setRemoved]\n );\n\n const respond = useCallback<EventActions['respond']>(\n async (event, answer) => {\n const ctx = contextRef.current;\n const before = answers.get(event.id) ?? event.myResponse ?? 'NO_RESPONSE';\n if (before === answer) return;\n const key = `answer:${event.id}`;\n const send = (status: EventResponseV2) =>\n writes.run(key, async () => {\n await client.mutate<\n CalendarV2RespondToEventMutation,\n CalendarV2RespondToEventMutationVariables\n >({\n mutation: CalendarV2RespondToEventDocument,\n variables: { eventId: event.id, status: RSVP_STATUS[status] },\n });\n });\n const ticket = writes.claim(key);\n const confirmed = confirmedRef.current.answers;\n confirmed.delete(event.id);\n setAnswer(event.id, answer);\n try {\n await send(answer);\n } catch (error) {\n // A newer answer was given since: its outcome is the one to show.\n if (!writes.isNewest(key, ticket)) return;\n setAnswer(event.id, null);\n failed(\n ctx.tr('calendar.v2.answerFailed', 'Couldn’t send your answer to “{{title}}”', {\n title: event.title,\n }),\n error\n );\n return;\n }\n if (writes.isNewest(key, ticket)) confirmed.add(event.id);\n invalidateCalendarEvents();\n if (!writes.isNewest(key, ticket)) return;\n const title =\n answer === 'ACCEPTED'\n ? ctx.tr(\n 'calendar.v2.answeredYes',\n 'You’re going to “{{title}}”. The organiser is told.',\n {\n title: event.title,\n }\n )\n : answer === 'TENTATIVE'\n ? ctx.tr('calendar.v2.answeredMaybe', 'You’re a maybe for “{{title}}”.', {\n title: event.title,\n })\n : ctx.tr('calendar.v2.answeredNo', 'You declined “{{title}}”.', { title: event.title });\n notify({\n title,\n description:\n answer === 'DECLINED' && !ctx.showDeclined\n ? ctx.tr(\n 'calendar.v2.declinedHidden',\n 'It’s hidden now. “Show events I declined” is in Calendar settings.'\n )\n : undefined,\n tone: 'success',\n undoneTitle: ctx.tr('calendar.v2.answerUndone', 'Your answer is back as it was.'),\n undo: async () => {\n const undoTicket = writes.claim(key);\n confirmed.delete(event.id);\n setAnswer(event.id, before);\n try {\n await send(before);\n } catch (error) {\n if (writes.isNewest(key, undoTicket)) setAnswer(event.id, null);\n throw error;\n }\n if (writes.isNewest(key, undoTicket)) confirmed.add(event.id);\n invalidateCalendarEvents();\n },\n });\n },\n [answers, client, failed, notify, setAnswer, writes]\n );\n\n const duplicate = useCallback<EventActions['duplicate']>(\n async (event) => {\n const ctx = contextRef.current;\n let copyId: string | null = null;\n try {\n const result = await client.mutate<\n CalendarV2DuplicateEventMutation,\n CalendarV2DuplicateEventMutationVariables\n >({\n mutation: CalendarV2DuplicateEventDocument,\n variables: { eventId: event.id, newStartTime: event.start.toISOString() },\n });\n copyId = result.data?.duplicateEvent.id ?? null;\n } catch (error) {\n failed(\n ctx.tr('calendar.v2.duplicateFailed', 'Couldn’t copy “{{title}}”', {\n title: event.title,\n }),\n error\n );\n return;\n }\n invalidateCalendarEvents();\n notify({\n title: ctx.tr('calendar.v2.duplicated', 'Made a copy of “{{title}}” at the same time.', {\n title: event.title,\n }),\n description: ctx.tr(\n 'calendar.v2.duplicatedHint',\n 'Drag it where you want it, or open it to change it.'\n ),\n tone: 'success',\n undoneTitle: ctx.tr('calendar.v2.copyRemoved', 'The copy is gone.'),\n undo: copyId\n ? async () => {\n if (!copyId) return;\n await deleteNow(copyId, 0);\n invalidateCalendarEvents();\n }\n : undefined,\n });\n },\n [client, deleteNow, failed, notify]\n );\n\n const quickCreate = useCallback<EventActions['quickCreate']>(\n async (input) => {\n const ctx = contextRef.current;\n let createdId: string | null = null;\n try {\n const result = await client.mutate<\n CalendarV2CreateEventMutation,\n CalendarV2CreateEventMutationVariables\n >({\n mutation: CalendarV2CreateEventDocument,\n variables: {\n input: {\n calendarId: input.calendarId,\n title: input.title,\n startTime: input.start.toISOString(),\n endTime: input.end.toISOString(),\n allDay: input.allDay,\n eventType: EVENT_TYPE_MEETING,\n timezone: ctx.timeZone,\n },\n },\n });\n createdId = result.data?.createEvent.id ?? null;\n } catch (error) {\n failed(\n ctx.tr('calendar.v2.createFailed', 'Couldn’t add “{{title}}”', { title: input.title }),\n error\n );\n return false;\n }\n let reminderMissed = false;\n if (createdId && ctx.defaultReminder !== null) {\n try {\n await client.mutate<\n CalendarV2CreateReminderMutation,\n CalendarV2CreateReminderMutationVariables\n >({\n mutation: CalendarV2CreateReminderDocument,\n variables: {\n input: {\n eventId: createdId,\n minutesBefore: ctx.defaultReminder,\n channel: REMINDER_IN_APP,\n },\n },\n });\n } catch {\n reminderMissed = true;\n }\n }\n invalidateCalendarEvents();\n const day = instantToZoned(input.start, ctx.timeZone).date;\n notify({\n title: ctx.tr('calendar.v2.created', 'Added “{{title}}”, {{day}} {{time}}.', {\n title: input.title,\n day: formatDay(day, ctx.format, 'short'),\n time: input.allDay\n ? ctx.tr('calendar.v2.allDayLower', 'all day')\n : formatInstantRange(input.start, input.end, ctx.timeZone, ctx.format),\n }),\n description: reminderMissed\n ? ctx.tr(\n 'calendar.v2.reminderMissed',\n 'Its reminder wasn’t added. Open the event to add one.'\n )\n : undefined,\n tone: reminderMissed ? 'warning' : 'success',\n undoneTitle: ctx.tr('calendar.v2.createUndone', 'Removed.'),\n undo: createdId\n ? async () => {\n if (!createdId) return;\n await deleteNow(createdId, 0);\n invalidateCalendarEvents();\n }\n : undefined,\n });\n return true;\n },\n [client, deleteNow, failed, notify]\n );\n\n const downloadIcs = useCallback<EventActions['downloadIcs']>(\n async (event) => {\n const ctx = contextRef.current;\n try {\n const result = await client.query<\n CalendarV2EventIcsQuery,\n CalendarV2EventIcsQueryVariables\n >({\n query: CalendarV2EventIcsDocument,\n variables: { eventId: event.id },\n fetchPolicy: 'network-only',\n });\n const text = result.data?.exportEventToIcs;\n if (!text || !saveFile(text, icsFileName(event.title))) throw new Error('No file');\n } catch {\n notify({\n title: ctx.tr('calendar.v2.icsFailed', 'Couldn’t download “{{title}}”', {\n title: event.title,\n }),\n description: ctx.tr(\n 'calendar.v2.actionRetry',\n 'Nothing was changed. Try again in a moment.'\n ),\n tone: 'error',\n });\n }\n },\n [client, notify]\n );\n\n const copyText = useCallback<EventActions['copyText']>(\n async (text, done) => {\n const ctx = contextRef.current;\n try {\n await navigator.clipboard.writeText(text);\n notify({ title: done, tone: 'success' });\n } catch {\n notify({\n title: ctx.tr(\n 'calendar.v2.copyFailed',\n 'Couldn’t copy. Select the text and copy it instead.'\n ),\n tone: 'error',\n });\n }\n },\n [notify]\n );\n\n const checkSyncNow = useCallback<EventActions['checkSyncNow']>(\n async (calendar) => {\n const ctx = contextRef.current;\n if (!calendar.sync) return;\n try {\n await client.mutate<CalendarV2TriggerSyncMutation, CalendarV2TriggerSyncMutationVariables>({\n mutation: CalendarV2TriggerSyncDocument,\n variables: { syncId: calendar.sync.id },\n });\n } catch (error) {\n failed(\n ctx.tr('calendar.v2.checkFailed', 'Couldn’t check “{{name}}” now', {\n name: calendar.name,\n }),\n error\n );\n return;\n }\n // Every page of calendars: the checked one may be past the first page.\n ctx.reloadCalendars();\n invalidateCalendarEvents();\n notify({\n title: ctx.tr('calendar.v2.checked', 'Checked “{{name}}” for changes.', {\n name: calendar.name,\n }),\n tone: 'success',\n });\n },\n [client, failed, notify]\n );\n\n const settle = useCallback<EventActions['settle']>((events) => {\n const byId = new Map(events.map((event) => [event.id, event]));\n // Confirmed changes give way to this reload, whatever it holds; the others stay until it\n // shows them.\n const confirmedTimes = new Set(confirmedRef.current.times);\n const confirmedAnswers = new Set(confirmedRef.current.answers);\n confirmedRef.current.times.clear();\n confirmedRef.current.answers.clear();\n setOverrides((current) => {\n if (current.size === 0) return current;\n let changed = false;\n const next = new Map(current);\n for (const [id, times] of current) {\n const loaded = byId.get(id);\n if (\n confirmedTimes.has(id) ||\n (loaded &&\n loaded.start.getTime() === times.start.getTime() &&\n loaded.end.getTime() === times.end.getTime())\n ) {\n next.delete(id);\n changed = true;\n }\n }\n return changed ? next : current;\n });\n setAnswers((current) => {\n if (current.size === 0) return current;\n let changed = false;\n const next = new Map(current);\n for (const [id, answer] of current) {\n if (confirmedAnswers.has(id) || byId.get(id)?.myResponse === answer) {\n next.delete(id);\n changed = true;\n }\n }\n return changed ? next : current;\n });\n }, []);\n\n return useMemo(\n () => ({\n overrides,\n removedIds,\n answers,\n changeTimes,\n remove,\n respond,\n duplicate,\n quickCreate,\n downloadIcs,\n copyText,\n checkSyncNow,\n settle,\n }),\n [\n answers,\n changeTimes,\n checkSyncNow,\n copyText,\n downloadIcs,\n duplicate,\n overrides,\n quickCreate,\n remove,\n removedIds,\n respond,\n settle,\n ]\n );\n}\n\n/** The person's answer to show for an event: one given here wins until the views reload. */\nexport function answerFor(\n event: CalendarEventV2,\n answers: ReadonlyMap<string, EventResponseV2>,\n me: string | null\n): EventResponseV2 | null {\n if (myPart(event, me) === 'organizer') return null;\n return answers.get(event.id) ?? event.myResponse;\n}\n"],"mappings":";;;;;;;;;;;AAyHA,SAASA,GAAa,GAAwB,GAA2B;CACvE,OAAOC,EAAM,OAAO,QAAQ,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CAEL,OAAOgE,SACE;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,IACA;EACE1E;EACA4B;EACAoC;EACAF;EACAF;EACAV;EACAvD;EACA0D;EACAZ;EACA3C;EACA+C;EACAsB;CACF,CACF;AACF;AAGA,SAAgBQ,EACd,GACA,GACA,GACwB;CAExB,OADIC,EAAOxG,GAAOE,CAAE,MAAM,cAAoB,OACvC0B,EAAQ,IAAI5B,EAAM,EAAE,KAAKA,EAAM;AACxC"}
@@ -0,0 +1,17 @@
1
+ import { CalendarEventV2 } from '../types';
2
+ export type PeekEvent = {
3
+ status: 'none';
4
+ } | {
5
+ status: 'loading';
6
+ } | {
7
+ status: 'missing';
8
+ } | {
9
+ status: 'error';
10
+ retry: () => void;
11
+ } | {
12
+ status: 'ready';
13
+ event: CalendarEventV2;
14
+ };
15
+ export declare function useEventForPeek(eventId: string | null, loaded: readonly CalendarEventV2[],
16
+ /** The view's events are still loading: wait for them before reading the event on its own. */
17
+ viewLoading?: boolean): PeekEvent;
@@ -0,0 +1,29 @@
1
+ import { CalendarV2EventDocument as e } from "../../generated/wspace-operations.js";
2
+ import { useCalendar as t } from "../../providers/CalendarProvider.js";
3
+ import { graphQLErrorCode as n } from "./errors.js";
4
+ import { toCalendarEventV2 as r } from "./normalize.js";
5
+ import { useMemo as i } from "react";
6
+ import { useQuery as a } from "@apollo/client/react";
7
+ // src/v2/data/useEventForPeek.ts
8
+ function o(o, s, c = !1) {
9
+ let { currentUser: l } = t(), u = l?.id ?? null, d = i(() => o ? s.find((e) => e.id === o) ?? null : null, [o, s]), { data: f, error: p, loading: m, refetch: h } = a(e, {
10
+ variables: { id: o ?? "" },
11
+ skip: !o || d !== null || c,
12
+ fetchPolicy: "network-only"
13
+ }), g = i(() => f?.event ? r(f.event, u) : null, [f, u]);
14
+ return o ? d ? {
15
+ status: "ready",
16
+ event: d
17
+ } : c ? { status: "loading" } : g ? {
18
+ status: "ready",
19
+ event: g
20
+ } : p ? n(p) === "NOT_FOUND" ? { status: "missing" } : {
21
+ status: "error",
22
+ retry: () => {
23
+ h().catch(() => void 0);
24
+ }
25
+ } : m || !f ? { status: "loading" } : { status: "missing" } : { status: "none" };
26
+ }
27
+ export { o as useEventForPeek };
28
+
29
+ //# sourceMappingURL=useEventForPeek.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEventForPeek.js","names":["useEventForPeek","useCalendar","myUserId","currentUser","inView","useMemo","eventId","loaded","event","useQuery","CalendarV2EventDocument","viewLoading","fetched","data","toCalendarEventV2","error","graphQLErrorCode","loading"],"sources":["../../../src/v2/data/useEventForPeek.ts"],"sourcesContent":["/**\n * The event a peek shows (BOFF-15698 A1): from the view's events when it is among them, else\n * read on its own (a link to an event in another week, or on a hidden calendar) once the view\n * has loaded without it. `missing`: it can't be read (deleted, or on a calendar the person\n * can't see).\n */\nimport { useMemo } from 'react';\nimport { useQuery } from '@apollo/client/react';\nimport {\n CalendarV2EventDocument,\n type CalendarV2EventQuery,\n type CalendarV2EventQueryVariables,\n} from '../../generated/wspace-operations';\nimport { useCalendar } from '../../providers/CalendarProvider';\nimport type { CalendarEventV2 } from '../types';\nimport { graphQLErrorCode } from './errors';\nimport { toCalendarEventV2 } from './normalize';\n\nexport type PeekEvent =\n | { status: 'none' }\n | { status: 'loading' }\n | { status: 'missing' }\n | { status: 'error'; retry: () => void }\n | { status: 'ready'; event: CalendarEventV2 };\n\nexport function useEventForPeek(\n eventId: string | null,\n loaded: readonly CalendarEventV2[],\n /** The view's events are still loading: wait for them before reading the event on its own. */\n viewLoading = false\n): PeekEvent {\n const { currentUser } = useCalendar();\n const myUserId = currentUser?.id ?? null;\n const inView = useMemo(\n () => (eventId ? (loaded.find((event) => event.id === eventId) ?? null) : null),\n [eventId, loaded]\n );\n const { data, error, loading, refetch } = useQuery<\n CalendarV2EventQuery,\n CalendarV2EventQueryVariables\n >(CalendarV2EventDocument, {\n variables: { id: eventId ?? '' },\n skip: !eventId || inView !== null || viewLoading,\n fetchPolicy: 'network-only',\n });\n const fetched = useMemo(\n () => (data?.event ? toCalendarEventV2(data.event, myUserId) : null),\n [data, myUserId]\n );\n if (!eventId) return { status: 'none' };\n if (inView) return { status: 'ready', event: inView };\n if (viewLoading) return { status: 'loading' };\n if (fetched) return { status: 'ready', event: fetched };\n if (error) {\n return graphQLErrorCode(error) === 'NOT_FOUND'\n ? { status: 'missing' }\n : {\n status: 'error',\n retry: () => {\n refetch().catch(() => undefined);\n },\n };\n }\n if (loading || !data) return { status: 'loading' };\n return { status: 'missing' };\n}\n"],"mappings":";;;;;;;AAyBA,SAAgBA,EACd,GACA,GAEA,IAAc,IACH;CACX,IAAM,EAAE,mBAAgBC,EAAY,GAC9BC,IAAWC,GAAa,MAAM,MAC9BC,IAASC,QACNC,IAAWC,EAAO,MAAM,MAAUC,EAAM,OAAOF,CAAO,KAAK,OAAQ,MAC1E,CAACA,GAASC,CAAM,CAClB,GACM,EAAE,SAAM,UAAO,YAAS,eAAYE,EAGxCC,GAAyB;EACzB,WAAW,EAAE,IAAIJ,KAAW,GAAG;EAC/B,MAAM,CAACA,KAAWF,MAAW,QAAQO;EACrC,aAAa;CACf,CAAC,GACKC,IAAUP,QACPQ,GAAM,QAAQC,EAAkBD,EAAK,OAAOX,CAAQ,IAAI,MAC/D,CAACW,GAAMX,CAAQ,CACjB;CAgBA,OAfKI,IACDF,IAAe;EAAE,QAAQ;EAAS,OAAOA;CAAO,IAChDO,IAAoB,EAAE,QAAQ,UAAU,IACxCC,IAAgB;EAAE,QAAQ;EAAS,OAAOA;CAAQ,IAClDG,IACKC,EAAiBD,CAAK,MAAM,cAC/B,EAAE,QAAQ,UAAU,IACpB;EACE,QAAQ;EACR,aAAa;GACX,EAAQ,CAAC,CAAC,YAAY,KAAA,CAAS;EACjC;CACF,IAEFE,KAAW,CAACJ,IAAa,EAAE,QAAQ,UAAU,IAC1C,EAAE,QAAQ,UAAU,IAfN,EAAE,QAAQ,OAAO;AAgBxC"}
@@ -0,0 +1,15 @@
1
+ import { CalendarEventV2 } from '../types';
2
+ export interface EventSearchV2 {
3
+ events: CalendarEventV2[];
4
+ status: 'idle' | 'loading' | 'ready' | 'partial' | 'error';
5
+ failedCalendarIds: string[];
6
+ /** Calendars with more matches than one answer holds. */
7
+ truncatedCalendarIds: string[];
8
+ error: Error | null;
9
+ refetch: () => void;
10
+ }
11
+ /**
12
+ * `text`: the search as sent (`searchText`); '' searches nothing (`idle`). A search with no
13
+ * calendar to look in (every one hidden) is answered at once: `ready`, no matches.
14
+ */
15
+ export declare function useEventSearchV2(calendarIds: readonly string[], text: string): EventSearchV2;
@@ -0,0 +1,80 @@
1
+ import { CalendarV2SearchEventsDocument as e } from "../../generated/wspace-operations.js";
2
+ import { useCalendar as t } from "../../providers/CalendarProvider.js";
3
+ import "../search/searchModel.js";
4
+ import { normalizeCalendarIds as n } from "../state/calendarV2Store.js";
5
+ import { useCalendarEventsRevision as r } from "./invalidation.js";
6
+ import { sortEventsV2 as i, toCalendarEventV2 as a } from "./normalize.js";
7
+ import { useKeyedLoad as o } from "./useKeyedLoad.js";
8
+ import { useApolloClient as s } from "@apollo/client/react";
9
+ // src/v2/data/useEventSearchV2.ts
10
+ var c = "\n";
11
+ function l(l, u) {
12
+ let d = s(), { currentUser: f } = t(), p = f?.id ?? null, m = r(), h = n(l).join(c), g = u === "" || h === "" ? null : [
13
+ h,
14
+ u,
15
+ p ?? ""
16
+ ].join("|"), _ = u !== "" && h === "", v = o(g, async () => {
17
+ let t = h.split(c), n = await Promise.allSettled(t.map((t) => d.query({
18
+ query: e,
19
+ variables: {
20
+ calendarId: t,
21
+ search: u,
22
+ limit: 100
23
+ },
24
+ fetchPolicy: "network-only"
25
+ }))), r = {
26
+ events: [],
27
+ failedCalendarIds: [],
28
+ truncatedCalendarIds: []
29
+ }, o = null;
30
+ if (n.forEach((e, n) => {
31
+ let i = t[n] ?? "", s = e.status === "fulfilled" ? e.value.data?.events : void 0;
32
+ if (!s) r.failedCalendarIds.push(i), o ??= e.status === "rejected" ? e.reason : null;
33
+ else {
34
+ s.hasMore && r.truncatedCalendarIds.push(i);
35
+ for (let e of s.events) {
36
+ let t = a(e, p);
37
+ t && r.events.push(t);
38
+ }
39
+ }
40
+ }), r.failedCalendarIds.length === t.length) throw o instanceof Error ? o : /* @__PURE__ */ Error("The search could not be run");
41
+ return {
42
+ ...r,
43
+ events: i(r.events)
44
+ };
45
+ }, m);
46
+ if (g === null) return {
47
+ events: [],
48
+ status: _ ? "ready" : "idle",
49
+ failedCalendarIds: [],
50
+ truncatedCalendarIds: [],
51
+ error: null,
52
+ refetch: v.reload
53
+ };
54
+ let y = v.dataKey === g ? v.data : void 0;
55
+ return v.error ? {
56
+ events: [],
57
+ status: "error",
58
+ failedCalendarIds: [],
59
+ truncatedCalendarIds: [],
60
+ error: v.error,
61
+ refetch: v.reload
62
+ } : y ? {
63
+ events: y.events,
64
+ status: y.failedCalendarIds.length > 0 ? "partial" : "ready",
65
+ failedCalendarIds: y.failedCalendarIds,
66
+ truncatedCalendarIds: y.truncatedCalendarIds,
67
+ error: null,
68
+ refetch: v.reload
69
+ } : {
70
+ events: [],
71
+ status: "loading",
72
+ failedCalendarIds: [],
73
+ truncatedCalendarIds: [],
74
+ error: null,
75
+ refetch: v.reload
76
+ };
77
+ }
78
+ export { l as useEventSearchV2 };
79
+
80
+ //# sourceMappingURL=useEventSearchV2.js.map