@burdenoff/microfe-calendar 2026.1124.2 → 2026.1124.4

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 (130) hide show
  1. package/dist/generated/wspace-operations.d.ts +811 -69
  2. package/dist/generated/wspace-operations.js +173 -19
  3. package/dist/generated/wspace-operations.js.map +1 -1
  4. package/dist/generated/wspace-types.d.ts +405 -6
  5. package/dist/pages/ResourcesPage.js.map +1 -1
  6. package/dist/translations/en.d.ts +250 -1
  7. package/dist/v2/CalendarPageV2.js +45 -41
  8. package/dist/v2/CalendarPageV2.js.map +1 -1
  9. package/dist/v2/CalendarRoutesV2.js +64 -64
  10. package/dist/v2/CalendarRoutesV2.js.map +1 -1
  11. package/dist/v2/data/enums.d.ts +1 -0
  12. package/dist/v2/data/enums.js +6 -2
  13. package/dist/v2/data/enums.js.map +1 -1
  14. package/dist/v2/data/errors.d.ts +5 -0
  15. package/dist/v2/data/errors.js +6 -2
  16. package/dist/v2/data/errors.js.map +1 -1
  17. package/dist/v2/data/normalize.d.ts +31 -3
  18. package/dist/v2/data/normalize.js +57 -13
  19. package/dist/v2/data/normalize.js.map +1 -1
  20. package/dist/v2/data/seriesDateLookup.d.ts +9 -0
  21. package/dist/v2/data/seriesDateLookup.js +12 -0
  22. package/dist/v2/data/seriesDateLookup.js.map +1 -0
  23. package/dist/v2/data/useEventActions.d.ts +9 -3
  24. package/dist/v2/data/useEventActions.js +239 -186
  25. package/dist/v2/data/useEventActions.js.map +1 -1
  26. package/dist/v2/data/useEventForPeek.js +63 -21
  27. package/dist/v2/data/useEventForPeek.js.map +1 -1
  28. package/dist/v2/data/useEventsInRangeV2.d.ts +40 -2
  29. package/dist/v2/data/useEventsInRangeV2.js +76 -47
  30. package/dist/v2/data/useEventsInRangeV2.js.map +1 -1
  31. package/dist/v2/day/DayPanel.js +1 -1
  32. package/dist/v2/day/DayPanel.js.map +1 -1
  33. package/dist/v2/dialogs/CalendarDialogsV2.js +12 -9
  34. package/dist/v2/dialogs/CalendarDialogsV2.js.map +1 -1
  35. package/dist/v2/event/CustomRepeat.d.ts +5 -0
  36. package/dist/v2/event/CustomRepeat.js +246 -0
  37. package/dist/v2/event/CustomRepeat.js.map +1 -0
  38. package/dist/v2/event/EventDetailsTab.d.ts +6 -0
  39. package/dist/v2/event/EventDetailsTab.js +291 -0
  40. package/dist/v2/event/EventDetailsTab.js.map +1 -0
  41. package/dist/v2/event/EventDialog.d.ts +35 -0
  42. package/dist/v2/event/EventDialog.js +388 -0
  43. package/dist/v2/event/EventDialog.js.map +1 -0
  44. package/dist/v2/event/EventDialogs.d.ts +3 -0
  45. package/dist/v2/event/EventDialogs.js +118 -0
  46. package/dist/v2/event/EventDialogs.js.map +1 -0
  47. package/dist/v2/event/EventMoreTab.d.ts +4 -0
  48. package/dist/v2/event/EventMoreTab.js +215 -0
  49. package/dist/v2/event/EventMoreTab.js.map +1 -0
  50. package/dist/v2/event/EventPeopleTab.d.ts +8 -0
  51. package/dist/v2/event/EventPeopleTab.js +422 -0
  52. package/dist/v2/event/EventPeopleTab.js.map +1 -0
  53. package/dist/v2/event/EventPlaceTab.d.ts +6 -0
  54. package/dist/v2/event/EventPlaceTab.js +264 -0
  55. package/dist/v2/event/EventPlaceTab.js.map +1 -0
  56. package/dist/v2/event/FindTimeDialog.d.ts +26 -0
  57. package/dist/v2/event/FindTimeDialog.js +667 -0
  58. package/dist/v2/event/FindTimeDialog.js.map +1 -0
  59. package/dist/v2/event/RepeatField.d.ts +5 -0
  60. package/dist/v2/event/RepeatField.js +91 -0
  61. package/dist/v2/event/RepeatField.js.map +1 -0
  62. package/dist/v2/event/dialogLogic.d.ts +97 -0
  63. package/dist/v2/event/dialogLogic.js +120 -0
  64. package/dist/v2/event/dialogLogic.js.map +1 -0
  65. package/dist/v2/event/dialogModel.d.ts +51 -0
  66. package/dist/v2/event/dialogModel.js +13 -0
  67. package/dist/v2/event/dialogModel.js.map +1 -0
  68. package/dist/v2/event/eventForm.d.ts +235 -0
  69. package/dist/v2/event/eventForm.js +450 -0
  70. package/dist/v2/event/eventForm.js.map +1 -0
  71. package/dist/v2/event/findTime.d.ts +120 -0
  72. package/dist/v2/event/findTime.js +149 -0
  73. package/dist/v2/event/findTime.js.map +1 -0
  74. package/dist/v2/event/findTimeSource.d.ts +102 -0
  75. package/dist/v2/event/findTimeSource.js +107 -0
  76. package/dist/v2/event/findTimeSource.js.map +1 -0
  77. package/dist/v2/event/parts.d.ts +46 -0
  78. package/dist/v2/event/parts.js +124 -0
  79. package/dist/v2/event/parts.js.map +1 -0
  80. package/dist/v2/event/place.d.ts +64 -0
  81. package/dist/v2/event/place.js +48 -0
  82. package/dist/v2/event/place.js.map +1 -0
  83. package/dist/v2/event/repeatWords.d.ts +19 -0
  84. package/dist/v2/event/repeatWords.js +130 -0
  85. package/dist/v2/event/repeatWords.js.map +1 -0
  86. package/dist/v2/event/rrule.d.ts +90 -0
  87. package/dist/v2/event/rrule.js +368 -0
  88. package/dist/v2/event/rrule.js.map +1 -0
  89. package/dist/v2/event/savePlan.d.ts +160 -0
  90. package/dist/v2/event/savePlan.js +219 -0
  91. package/dist/v2/event/savePlan.js.map +1 -0
  92. package/dist/v2/event/useEventData.d.ts +96 -0
  93. package/dist/v2/event/useEventData.js +229 -0
  94. package/dist/v2/event/useEventData.js.map +1 -0
  95. package/dist/v2/event/useEventDialogModel.d.ts +50 -0
  96. package/dist/v2/event/useEventDialogModel.js +144 -0
  97. package/dist/v2/event/useEventDialogModel.js.map +1 -0
  98. package/dist/v2/event/useEventSave.d.ts +57 -0
  99. package/dist/v2/event/useEventSave.js +276 -0
  100. package/dist/v2/event/useEventSave.js.map +1 -0
  101. package/dist/v2/events/eventLook.js +16 -16
  102. package/dist/v2/events/eventLook.js.map +1 -1
  103. package/dist/v2/events/eventModel.d.ts +17 -4
  104. package/dist/v2/events/eventModel.js +46 -34
  105. package/dist/v2/events/eventModel.js.map +1 -1
  106. package/dist/v2/events/localChanges.d.ts +4 -1
  107. package/dist/v2/events/localChanges.js +4 -2
  108. package/dist/v2/events/localChanges.js.map +1 -1
  109. package/dist/v2/format.d.ts +2 -0
  110. package/dist/v2/format.js +4 -0
  111. package/dist/v2/format.js.map +1 -1
  112. package/dist/v2/page/CalendarPageContext.d.ts +2 -2
  113. package/dist/v2/page/CalendarPageContext.js.map +1 -1
  114. package/dist/v2/page/useCalendarPageModel.js +141 -139
  115. package/dist/v2/page/useCalendarPageModel.js.map +1 -1
  116. package/dist/v2/page/viewState.d.ts +9 -1
  117. package/dist/v2/page/viewState.js +5 -3
  118. package/dist/v2/page/viewState.js.map +1 -1
  119. package/dist/v2/peek/EventPeek.js.map +1 -1
  120. package/dist/v2/peek/PeekEvent.js +210 -204
  121. package/dist/v2/peek/PeekEvent.js.map +1 -1
  122. package/dist/v2/rail/CalendarRail.js.map +1 -1
  123. package/dist/v2/rail/useMonthEventDates.js +1 -1
  124. package/dist/v2/rail/useMonthEventDates.js.map +1 -1
  125. package/dist/v2/runs/RunPeek.js.map +1 -1
  126. package/dist/v2/states/CalendarStates.d.ts +15 -0
  127. package/dist/v2/states/CalendarStates.js +42 -11
  128. package/dist/v2/states/CalendarStates.js.map +1 -1
  129. package/dist/v2/types.d.ts +32 -2
  130. package/package.json +1 -1
@@ -1 +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,MAAU,CAACC,EAAM,aAAaA,EAAM,WAAWC,CAAE,CAAC,CAAC;AACjF;AAGA,SAASC,EAAS,GAAe,GAAsC;CACrE,IAAMC,IAAiBC,EAAeC,GAASC,EAAQ,QAAQ,CAAC,CAAC;CACjE,OAAOC,EA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ACF,CACF;AACF;AAGA,SAAgBQ,EACd,GACA,GACA,GACwB;CAExB,OADIC,EAAOxG,GAAOE,CAAE,MAAM,cAAoB,OACvC0B,EAAQ,IAAI5B,EAAM,EAAE,KAAKA,EAAM;AACxC"}
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","removeSeries","seriesId","SCOPE_ALL_EVENTS","removeSeriesDate","variables","instanceDate","CalendarV2CancelOccurrenceDocument","CalendarV2RestoreOccurrenceDocument","remove","isSeriesDate","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","byEventId","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`. One date of\n * a repeating event (A4) is cancelled by its original start (`cancelRecurringInstance`); Undo\n * puts it back (`restoreRecurringInstance`). The whole series takes no hold: it asks first,\n * then deletes every event (`ALL_EVENTS`), with no Undo.\n * - **Answer an invitation**: `respondToEvent`; Undo answers as before. An answer is the\n * event's, so it shows on every date of a series.\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 *\n * Writes name the stored event (`eventId`): a regular date of a series is the series. What shows\n * on the page is kept by occurrence (`id`), except answers, which are the event's.\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 CalendarV2CancelOccurrenceDocument,\n CalendarV2CreateEventDocument,\n CalendarV2CreateReminderDocument,\n CalendarV2DeleteEventDocument,\n CalendarV2DuplicateEventDocument,\n CalendarV2EventIcsDocument,\n CalendarV2RespondToEventDocument,\n CalendarV2RestoreEventDocument,\n CalendarV2RestoreOccurrenceDocument,\n CalendarV2TriggerSyncDocument,\n CalendarV2UpdateEventTimesDocument,\n type CalendarV2CancelOccurrenceMutation,\n type CalendarV2CancelOccurrenceMutationVariables,\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 CalendarV2RestoreOccurrenceMutation,\n type CalendarV2RestoreOccurrenceMutationVariables,\n type CalendarV2TriggerSyncMutation,\n type CalendarV2TriggerSyncMutationVariables,\n type CalendarV2UpdateEventTimesMutation,\n type CalendarV2UpdateEventTimesMutationVariables,\n} from '../../generated/wspace-operations';\nimport { isSeriesDate, 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 occurrence id). */\n overrides: ReadonlyMap<string, EventTimes>;\n /**\n * Deleted here, hidden until the views reload without them: occurrences by id, and whole\n * series by their series id.\n */\n removedIds: ReadonlySet<string>;\n /** Answers given here, shown before the views reload (by the stored event's id). */\n answers: ReadonlyMap<string, EventResponseV2>;\n changeTimes: (event: CalendarEventV2, next: EventTimes, kind: 'move' | 'resize') => Promise<void>;\n /** Deletes this event: one date of a series, or an event that doesn't repeat. */\n remove: (event: CalendarEventV2) => Promise<void>;\n /** Deletes every date of the series the event is a date of, after asking. */\n removeSeries: (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.eventId, 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.eventId, 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 removeSeries = useCallback<EventActions['removeSeries']>(\n async (event) => {\n const ctx = contextRef.current;\n const seriesId = event.seriesId ?? event.eventId;\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(seriesId, true);\n try {\n await deleteNow(seriesId, 0, SCOPE_ALL_EVENTS);\n } catch (error) {\n setRemoved(seriesId, 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 },\n [confirm, deleteNow, failed, notify, setRemoved]\n );\n\n /** One date of a series: cancelled by its original start; Undo puts it back. */\n const removeSeriesDate = useCallback(\n async (event: CalendarEventV2, seriesId: string, instanceDate: Date) => {\n const ctx = contextRef.current;\n const variables = { seriesId, instanceDate: instanceDate.toISOString() };\n setRemoved(event.id, true);\n try {\n await client.mutate<\n CalendarV2CancelOccurrenceMutation,\n CalendarV2CancelOccurrenceMutationVariables\n >({ mutation: CalendarV2CancelOccurrenceDocument, variables });\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 notify({\n title: ctx.tr('calendar.v2.deletedDate', 'Deleted “{{title}}” on {{day}}.', {\n title: event.title,\n day: dayWords(event.start, ctx),\n }),\n description:\n guestsToTell(event, ctx.me) === 0\n ? ctx.tr('calendar.v2.deletedDateRest', 'The series’ other dates stay.')\n : ctx.tr(\n 'calendar.v2.deletedDateGuests',\n 'The series’ other dates stay. Its guests aren’t told about this one.'\n ),\n tone: 'success',\n undoneTitle: ctx.tr('calendar.v2.restoredDate', 'Put back.'),\n undoFailedTitle: ctx.tr('calendar.v2.restoreDateFailed', 'Couldn’t put it back.'),\n undo: async () => {\n await client.mutate<\n CalendarV2RestoreOccurrenceMutation,\n CalendarV2RestoreOccurrenceMutationVariables\n >({ mutation: CalendarV2RestoreOccurrenceDocument, variables });\n setRemoved(event.id, false);\n invalidateCalendarEvents();\n },\n });\n },\n [client, failed, notify, setRemoved]\n );\n\n const remove = useCallback<EventActions['remove']>(\n async (event) => {\n const ctx = contextRef.current;\n if (isSeriesDate(event) && event.seriesId && event.instanceDate) {\n await removeSeriesDate(event, event.seriesId, event.instanceDate);\n return;\n }\n if (event.isRecurring) {\n // A series without a date to name: only the whole series can go.\n await removeSeries(event);\n return;\n }\n setRemoved(event.id, true);\n try {\n await deleteNow(event.eventId, 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.eventId },\n });\n setRemoved(event.id, false);\n invalidateCalendarEvents();\n },\n });\n },\n [client, deleteNow, failed, notify, removeSeries, removeSeriesDate, setRemoved]\n );\n\n const respond = useCallback<EventActions['respond']>(\n async (event, answer) => {\n const ctx = contextRef.current;\n const before = answers.get(event.eventId) ?? event.myResponse ?? 'NO_RESPONSE';\n if (before === answer) return;\n const key = `answer:${event.eventId}`;\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.eventId, status: RSVP_STATUS[status] },\n });\n });\n const ticket = writes.claim(key);\n const confirmed = confirmedRef.current.answers;\n confirmed.delete(event.eventId);\n setAnswer(event.eventId, 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.eventId, 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.eventId);\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.eventId);\n setAnswer(event.eventId, before);\n try {\n await send(before);\n } catch (error) {\n if (writes.isNewest(key, undoTicket)) setAnswer(event.eventId, null);\n throw error;\n }\n if (writes.isNewest(key, undoTicket)) confirmed.add(event.eventId);\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.eventId, 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.eventId },\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 const byEventId = new Map(events.map((event) => [event.eventId, 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) || byEventId.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 removeSeries,\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 removeSeries,\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.eventId) ?? event.myResponse;\n}\n"],"mappings":";;;;;;;;;;;AA2IA,SAASA,EAAa,GAAwB,GAA2B;CACvE,OAAOC,EAAM,OAAO,QAAQ,MAAU,CAACC,EAAM,aAAaA,EAAM,WAAWC,CAAE,CAAC,CAAC;AACjF;AAGA,SAASC,EAAS,GAAe,GAAsC;CACrE,IAAMC,IAAiBC,EAAeC,GAASC,EAAQ,QAAQ,CAAC,CAAC;CAC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;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,IACA;EACEnF;EACA4B;EACA4C;EACAF;EACAF;EACAV;EACA/D;EACAkE;EACAZ;EACAR;EACA3C;EACAuD;EACAsB;CACF,CACF;AACF;AAGA,SAAgBS,EACd,GACA,GACA,GACwB;CAExB,OADIC,EAAOjH,GAAOE,CAAE,MAAM,cAAoB,OACvC0B,EAAQ,IAAI5B,EAAM,OAAO,KAAKA,EAAM;AAC7C"}
@@ -1,29 +1,71 @@
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";
1
+ import { CalendarV2EventDocument as e, CalendarV2EventOccurrencesDocument as t } from "../../generated/wspace-operations.js";
2
+ import { useCalendar as n } from "../../providers/CalendarProvider.js";
3
+ import { graphQLErrorCode as r } from "./errors.js";
4
+ import { parseOccurrenceId as i, toCalendarEventV2 as a, toOccurrenceV2 as o } from "./normalize.js";
5
+ import { seriesDateQuestion as s } from "./seriesDateLookup.js";
6
+ import { useMemo as c } from "react";
7
+ import { useQuery as l } from "@apollo/client/react";
7
8
  // 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,
9
+ function u(e, r, i) {
10
+ let { currentUser: a } = n(), s = a?.id ?? null, { data: u, error: d, loading: f, refetch: p } = l(t, {
11
+ variables: r ?? {
12
+ calendarIds: [],
13
+ startDate: "",
14
+ endDate: ""
15
+ },
16
+ skip: i || r === null,
12
17
  fetchPolicy: "network-only"
13
- }), g = i(() => f?.event ? r(f.event, u) : null, [f, u]);
14
- return o ? d ? {
18
+ });
19
+ return {
20
+ found: c(() => {
21
+ let t = u?.eventsInRangeForCalendars.occurrences.find((t) => t.id === e);
22
+ return t ? o(t, s) : null;
23
+ }, [
24
+ u,
25
+ e,
26
+ s
27
+ ]),
28
+ error: d,
29
+ pending: f || !u,
30
+ refetch: p
31
+ };
32
+ }
33
+ function d(t, r) {
34
+ let { currentUser: o } = n(), d = o?.id ?? null, f = t ? i(t) : null, p = f?.seriesId ?? t, m = l(e, {
35
+ variables: { id: p ?? "" },
36
+ skip: !p || r,
37
+ fetchPolicy: "network-only"
38
+ }), h = c(() => m.data?.event ? a(m.data.event, d) : null, [m.data, d]), g = f ? s(h, f.instanceDate.getTime()) : null, _ = u(t, g, r), v = m.loading || !m.data, y = () => {
39
+ m.refetch().catch(() => void 0), g && _.refetch().catch(() => void 0);
40
+ };
41
+ return f ? {
42
+ event: _.found,
43
+ error: m.error ?? _.error,
44
+ pending: v || g !== null && _.pending,
45
+ retry: y
46
+ } : {
47
+ event: h,
48
+ error: m.error,
49
+ pending: v,
50
+ retry: y
51
+ };
52
+ }
53
+ function f(e, t, n, i) {
54
+ return e ? t ? {
15
55
  status: "ready",
16
- event: d
17
- } : c ? { status: "loading" } : g ? {
56
+ event: t
57
+ } : n ? { status: "loading" } : i.event ? {
18
58
  status: "ready",
19
- event: g
20
- } : p ? n(p) === "NOT_FOUND" ? { status: "missing" } : {
59
+ event: i.event
60
+ } : i.error ? r(i.error) === "NOT_FOUND" ? { status: "missing" } : {
21
61
  status: "error",
22
- retry: () => {
23
- h().catch(() => void 0);
24
- }
25
- } : m || !f ? { status: "loading" } : { status: "missing" } : { status: "none" };
62
+ retry: i.retry
63
+ } : i.pending ? { status: "loading" } : { status: "missing" } : { status: "none" };
64
+ }
65
+ function p(e, t, n = !1) {
66
+ let r = c(() => e ? t.find((t) => t.id === e) ?? null : null, [e, t]);
67
+ return f(e, r, n, d(e, r !== null || n));
26
68
  }
27
- export { o as useEventForPeek };
69
+ export { p as useEventForPeek };
28
70
 
29
71
  //# sourceMappingURL=useEventForPeek.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"useEventForPeek.js","names":["useSeriesDateLookup","useCalendar","myUserId","currentUser","useQuery","CalendarV2EventOccurrencesDocument","question","skip","useMemo","raw","data","occurrence","eventId","toOccurrenceV2","loading","useEventReadAlone","seriesDate","parseOccurrenceId","readId","own","CalendarV2EventDocument","read","toCalendarEventV2","seriesDateQuestion","lookup","ownPending","retry","peekState","inView","viewLoading","graphQLErrorCode","useEventForPeek","loaded","event"],"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 calendar that is hidden) once the\n * view has loaded without it. A date of a series (`<seriesId>@<date>`, A4) is read as its\n * series, then looked up with the views' own range query on the series' calendar, so a date\n * cancelled or moved since the link was made is never shown as if it were still there.\n * `missing`: it can't be read (deleted, gone from its series, or on a calendar the person can't\n * see).\n */\nimport { useMemo } from 'react';\nimport { useQuery } from '@apollo/client/react';\nimport {\n CalendarV2EventDocument,\n CalendarV2EventOccurrencesDocument,\n type CalendarV2EventOccurrencesQuery,\n type CalendarV2EventOccurrencesQueryVariables,\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 { parseOccurrenceId, toCalendarEventV2, toOccurrenceV2 } from './normalize';\nimport { seriesDateQuestion } from './seriesDateLookup';\n\nexport type PeekEvent =\n | { status: 'none' }\n | { status: 'loading' }\n | { status: 'missing' }\n | { status: 'error'; retry: () => void }\n | { status: 'ready'; event: CalendarEventV2 };\n\n/** What reading the event on its own has given so far. */\ninterface ReadAlone {\n /** The event (a series' date at that date), once read and found. */\n event: CalendarEventV2 | null;\n error: unknown;\n /** The reads haven't answered yet. */\n pending: boolean;\n retry: () => void;\n}\n\n/** A series' date, looked up with the range query on its calendar once the series is read. */\nfunction useSeriesDateLookup(\n eventId: string | null,\n question: CalendarV2EventOccurrencesQueryVariables | null,\n skip: boolean\n) {\n const { currentUser } = useCalendar();\n const myUserId = currentUser?.id ?? null;\n const { data, error, loading, refetch } = useQuery<\n CalendarV2EventOccurrencesQuery,\n CalendarV2EventOccurrencesQueryVariables\n >(CalendarV2EventOccurrencesDocument, {\n variables: question ?? { calendarIds: [], startDate: '', endDate: '' },\n skip: skip || question === null,\n fetchPolicy: 'network-only',\n });\n const found = useMemo(() => {\n const raw = data?.eventsInRangeForCalendars.occurrences.find(\n (occurrence) => occurrence.id === eventId\n );\n return raw ? toOccurrenceV2(raw, myUserId) : null;\n }, [data, eventId, myUserId]);\n return { found, error, pending: loading || !data, refetch };\n}\n\n/**\n * Reads an event on its own: by its id, or a series' date by its series and then the range\n * query on the series' calendar. Nothing is asked while `skip`.\n */\nfunction useEventReadAlone(eventId: string | null, skip: boolean): ReadAlone {\n const { currentUser } = useCalendar();\n const myUserId = currentUser?.id ?? null;\n const seriesDate = eventId ? parseOccurrenceId(eventId) : null;\n const readId = seriesDate?.seriesId ?? eventId;\n const own = useQuery<CalendarV2EventQuery, CalendarV2EventQueryVariables>(\n CalendarV2EventDocument,\n { variables: { id: readId ?? '' }, skip: !readId || skip, fetchPolicy: 'network-only' }\n );\n const read = useMemo(\n () => (own.data?.event ? toCalendarEventV2(own.data.event, myUserId) : null),\n [own.data, myUserId]\n );\n const question = seriesDate ? seriesDateQuestion(read, seriesDate.instanceDate.getTime()) : null;\n const lookup = useSeriesDateLookup(eventId, question, skip);\n const ownPending = own.loading || !own.data;\n const retry = () => {\n own.refetch().catch(() => undefined);\n if (question) lookup.refetch().catch(() => undefined);\n };\n if (!seriesDate) return { event: read, error: own.error, pending: ownPending, retry };\n return {\n event: lookup.found,\n error: own.error ?? lookup.error,\n // Waiting for the series, then (when it is one) for its date.\n pending: ownPending || (question !== null && lookup.pending),\n retry,\n };\n}\n\n/** The peek's state from the view's copy and the read on its own. */\nfunction peekState(\n eventId: string | null,\n inView: CalendarEventV2 | null,\n viewLoading: boolean,\n read: ReadAlone\n): PeekEvent {\n if (!eventId) return { status: 'none' };\n if (inView) return { status: 'ready', event: inView };\n if (viewLoading) return { status: 'loading' };\n if (read.event) return { status: 'ready', event: read.event };\n if (read.error) {\n return graphQLErrorCode(read.error) === 'NOT_FOUND'\n ? { status: 'missing' }\n : { status: 'error', retry: read.retry };\n }\n return read.pending ? { status: 'loading' } : { status: 'missing' };\n}\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 inView = useMemo(\n () => (eventId ? (loaded.find((event) => event.id === eventId) ?? null) : null),\n [eventId, loaded]\n );\n const read = useEventReadAlone(eventId, inView !== null || viewLoading);\n return peekState(eventId, inView, viewLoading, read);\n}\n"],"mappings":";;;;;;;;AA2CA,SAASA,EACP,GACA,GACA,GACA;CACA,IAAM,EAAE,mBAAgBC,EAAY,GAC9BC,IAAWC,GAAa,MAAM,MAC9B,EAAE,SAAM,UAAO,YAAS,eAAYC,EAGxCC,GAAoC;EACpC,WAAWC,KAAY;GAAE,aAAa,CAAC;GAAG,WAAW;GAAI,SAAS;EAAG;EACrE,MAAMC,KAAQD,MAAa;EAC3B,aAAa;CACf,CAAC;CAOD,OAAO;EAAE,OANKE,QAAc;GAC1B,IAAMC,IAAMC,GAAM,0BAA0B,YAAY,MACrD,MAAeC,EAAW,OAAOC,CACpC;GACA,OAAOH,IAAMI,EAAeJ,GAAKP,CAAQ,IAAI;EAC/C,GAAG;GAACQ;GAAME;GAASV;EAAQ,CAClB;EAAO;EAAO,SAASY,KAAW,CAACJ;EAAM;CAAQ;AAC5D;AAMA,SAASK,EAAkB,GAAwB,GAA0B;CAC3E,IAAM,EAAE,mBAAgBd,EAAY,GAC9BC,IAAWC,GAAa,MAAM,MAC9Ba,IAAaJ,IAAUK,EAAkBL,CAAO,IAAI,MACpDM,IAASF,GAAY,YAAYJ,GACjCO,IAAMf,EACVgB,GACA;EAAE,WAAW,EAAE,IAAIF,KAAU,GAAG;EAAG,MAAM,CAACA,KAAUX;EAAM,aAAa;CAAe,CACxF,GACMc,IAAOb,QACJW,EAAI,MAAM,QAAQG,EAAkBH,EAAI,KA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encesQuery } from '../../generated/wspace-operations';
1
2
  import { CalendarEventV2 } from '../types';
3
+ /** The most calendars one range question takes (the service refuses more). */
4
+ export declare const RANGE_MAX_CALENDARS = 50;
5
+ /** The longest range one question covers, in days (the service refuses longer). */
6
+ export declare const RANGE_MAX_DAYS = 62;
2
7
  export interface EventsInRangeV2 {
8
+ /** One per occurrence: a repeating event once for each of its dates in the range. */
3
9
  events: CalendarEventV2[];
4
10
  /**
5
11
  * `idle`: skipped. `loading`: this range hasn't answered yet. `ready`. `partial`: some
6
- * calendars failed (`failedCalendarIds`). `error`: every calendar failed (`error`); `events`
7
- * then holds this range's last good answer, if a refresh failed, else nothing.
12
+ * calendars' questions failed (`failedCalendarIds`). `error`: every question failed
13
+ * (`error`); `events` then holds this range's last good answer, if a refresh failed, else
14
+ * nothing.
8
15
  */
9
16
  status: 'idle' | 'loading' | 'ready' | 'partial' | 'error';
10
17
  /** A load is running: the first one for this range, or a refresh. */
11
18
  isFetching: boolean;
19
+ /** Calendars whose question failed: Try again may bring their events. */
12
20
  failedCalendarIds: string[];
21
+ /** Calendars the service won't read for this person: their events aren't shown. */
22
+ unreadableCalendarIds: string[];
23
+ /** Some occurrences may be missing: the service stopped at one of its limits. */
24
+ truncated: boolean;
13
25
  error: Error | null;
14
26
  refetch: () => void;
15
27
  }
28
+ interface LoadedEvents {
29
+ events: CalendarEventV2[];
30
+ failedCalendarIds: string[];
31
+ unreadableCalendarIds: string[];
32
+ truncated: boolean;
33
+ }
34
+ interface RangeQuestion {
35
+ calendarIds: string[];
36
+ startDate: string;
37
+ endDate: string;
38
+ }
39
+ /** `items` in runs of at most `size`. */
40
+ export declare function inBatches<T>(items: readonly T[], size: number): T[][];
41
+ /**
42
+ * The questions that cover `calendarIds` from `fromMs` to `toMs`: batches of at most 50
43
+ * calendars, each over parts of the range of at most 62 days.
44
+ */
45
+ export declare function rangeQuestions(calendarIds: readonly string[], fromMs: number, toMs: number): RangeQuestion[];
46
+ type RangeAnswer = CalendarV2EventOccurrencesQuery['eventsInRangeForCalendars'];
47
+ /**
48
+ * The questions' answers joined: each occurrence once (a part of the range shares the ones that
49
+ * cross into the next), the calendars whose question failed, those the service won't read, and
50
+ * whether any answer was cut off. Throws when every question failed.
51
+ */
52
+ export declare function joinRangeAnswers(questions: readonly RangeQuestion[], settled: readonly PromiseSettledResult<RangeAnswer | null | undefined>[], myUserId: string | null): LoadedEvents;
16
53
  export declare function useEventsInRangeV2(calendarIds: readonly string[], from: Date, to: Date, options?: {
17
54
  skip?: boolean;
18
55
  }): EventsInRangeV2;
56
+ export {};
@@ -1,78 +1,107 @@
1
- import { CalendarV2EventsInRangeDocument as e } from "../../generated/wspace-operations.js";
1
+ import { CalendarV2EventOccurrencesDocument as e } from "../../generated/wspace-operations.js";
2
2
  import { useCalendar as t } from "../../providers/CalendarProvider.js";
3
3
  import { normalizeCalendarIds as n } from "../state/calendarV2Store.js";
4
4
  import { useCalendarEventsRevision as r } from "./invalidation.js";
5
- import { sortEventsV2 as i, toCalendarEventV2 as a } from "./normalize.js";
5
+ import { sortEventsV2 as i, toOccurrenceV2 as a } from "./normalize.js";
6
6
  import { useKeyedLoad as o } from "./useKeyedLoad.js";
7
7
  import { useApolloClient as s } from "@apollo/client/react";
8
- // src/v2/data/useEventsInRangeV2.ts
9
- var c = "\n";
10
- function l(l, u, d, f = {}) {
11
- let p = s(), { currentUser: m } = t(), h = m?.id ?? null, g = r(), _ = n(l).join(c), v = u.getTime(), y = d.getTime(), b = Number.isFinite(v) && Number.isFinite(y) && y > v, x = f.skip || !b ? null : [
8
+ var c = 864e5, l = "\n";
9
+ function u(e, t) {
10
+ let n = [];
11
+ for (let r = 0; r < e.length; r += t) n.push(e.slice(r, r + t));
12
+ return n;
13
+ }
14
+ function d(e, t, n) {
15
+ let r = [];
16
+ for (let e = t; e < n; e += 62 * c) {
17
+ let t = Math.min(n, e + 62 * c);
18
+ r.push({
19
+ startDate: new Date(e).toISOString(),
20
+ endDate: new Date(t).toISOString()
21
+ });
22
+ }
23
+ return u(e, 50).flatMap((e) => r.map((t) => ({
24
+ calendarIds: e,
25
+ ...t
26
+ })));
27
+ }
28
+ function f(e, t, n) {
29
+ let r = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), s = [], c = !1, l = 0, u = null;
30
+ if (t.forEach((t, i) => {
31
+ let d = e[i];
32
+ if (!d) return;
33
+ let f = t.status === "fulfilled" ? t.value : null;
34
+ if (!f) {
35
+ for (let e of d.calendarIds) r.add(e);
36
+ u ??= t.status === "rejected" ? t.reason : null;
37
+ return;
38
+ }
39
+ l += 1, c ||= f.truncated;
40
+ let p = new Set(d.calendarIds);
41
+ for (let e of f.unavailableCalendarIds) p.has(e) && o.add(e);
42
+ for (let e of f.occurrences) {
43
+ let t = a(e, n);
44
+ t && s.push(t);
45
+ }
46
+ }), e.length > 0 && l === 0) throw u instanceof Error ? u : /* @__PURE__ */ Error("The events could not be loaded");
47
+ for (let e of r) o.delete(e);
48
+ return {
49
+ events: i(s),
50
+ failedCalendarIds: [...r],
51
+ unreadableCalendarIds: [...o],
52
+ truncated: c
53
+ };
54
+ }
55
+ function p(i, a, c, u = {}) {
56
+ let p = s(), { currentUser: m } = t(), h = m?.id ?? null, g = r(), _ = n(i).join(l), v = a.getTime(), y = c.getTime(), b = Number.isFinite(v) && Number.isFinite(y) && y > v, x = u.skip || !b ? null : [
12
57
  _,
13
58
  v,
14
59
  y,
15
60
  h ?? ""
16
61
  ].join("|"), S = o(x, async () => {
17
- let t = _ === "" ? [] : _.split(c);
18
- if (t.length === 0) return {
19
- events: [],
20
- failedCalendarIds: []
21
- };
22
- let n = new Date(v).toISOString(), r = new Date(y).toISOString(), o = await Promise.allSettled(t.map((t) => p.query({
62
+ let t = d(_ === "" ? [] : _.split(l), v, y);
63
+ return f(t, await Promise.allSettled(t.map(async (t) => (await p.query({
23
64
  query: e,
24
- variables: {
25
- calendarId: t,
26
- startDate: n,
27
- endDate: r
28
- },
65
+ variables: t,
29
66
  fetchPolicy: "network-only"
30
- }))), s = [], l = [], u = null;
31
- if (o.forEach((e, n) => {
32
- let r = e.status === "fulfilled" ? e.value.data?.eventsInRange : void 0;
33
- if (!r) s.push(t[n] ?? ""), u ??= e.status === "rejected" ? e.reason : null;
34
- else for (let e of r) {
35
- let t = a(e, h);
36
- t && l.push(t);
37
- }
38
- }), s.length === t.length) throw u instanceof Error ? u : /* @__PURE__ */ Error("The events could not be loaded");
39
- return {
40
- events: i(l),
41
- failedCalendarIds: s
42
- };
43
- }, g);
67
+ })).data?.eventsInRangeForCalendars)), h);
68
+ }, g), C = {
69
+ failedCalendarIds: [],
70
+ unreadableCalendarIds: [],
71
+ truncated: !1,
72
+ refetch: S.reload
73
+ };
44
74
  if (x === null) return {
75
+ ...C,
45
76
  events: [],
46
77
  status: "idle",
47
78
  isFetching: !1,
48
- failedCalendarIds: [],
49
- error: null,
50
- refetch: S.reload
79
+ error: null
51
80
  };
52
- let C = S.dataKey === x ? S.data : void 0;
81
+ let w = S.dataKey === x ? S.data : void 0;
53
82
  return S.error ? {
54
- events: C?.events ?? [],
83
+ ...C,
84
+ events: w?.events ?? [],
55
85
  status: "error",
56
86
  isFetching: S.loading,
57
- failedCalendarIds: [],
58
- error: S.error,
59
- refetch: S.reload
60
- } : C ? {
61
- events: C.events,
62
- status: C.failedCalendarIds.length > 0 ? "partial" : "ready",
87
+ error: S.error
88
+ } : w ? {
89
+ events: w.events,
90
+ status: w.failedCalendarIds.length > 0 ? "partial" : "ready",
63
91
  isFetching: S.loading,
64
- failedCalendarIds: C.failedCalendarIds,
92
+ failedCalendarIds: w.failedCalendarIds,
93
+ unreadableCalendarIds: w.unreadableCalendarIds,
94
+ truncated: w.truncated,
65
95
  error: null,
66
96
  refetch: S.reload
67
97
  } : {
98
+ ...C,
68
99
  events: S.data?.events ?? [],
69
100
  status: "loading",
70
101
  isFetching: !0,
71
- failedCalendarIds: [],
72
- error: null,
73
- refetch: S.reload
102
+ error: null
74
103
  };
75
104
  }
76
- export { l as useEventsInRangeV2 };
105
+ export { u as inBatches, f as joinRangeAnswers, d as rangeQuestions, p as useEventsInRangeV2 };
77
106
 
78
107
  //# sourceMappingURL=useEventsInRangeV2.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useEventsInRangeV2.js","names":["ID_SEPARATOR","useEventsInRangeV2","client","useApolloClient","useCalendar","myUserId","currentUser","revision","useCalendarEventsRevision","idsKey","normalizeCalendarIds","calendarIds","fromMs","from","toMs","to","validRange","key","options","load","useKeyedLoad","ids","startDate","endDate","settled","CalendarV2EventsInRangeDocument","failedCalendarIds","events","firstFailure","answer","result","index","raw","event","toCalendarEventV2","sortEventsV2","current"],"sources":["../../../src/v2/data/useEventsInRangeV2.ts"],"sourcesContent":["/**\n * The events of the shown calendars between two instants (BOFF-15698 A0).\n *\n * Until the batch range query exists (B7 `eventsInRangeForCalendars`), it asks today's\n * per-calendar `eventsInRange` once per calendar and keeps the ones that answered\n * (`Promise.allSettled`), as today's `useEvents` does: one calendar that fails doesn't blank\n * the others. When B7 lands, only the loader below changes; the result keeps this shape.\n *\n * - A calendar that failed is named in `failedCalendarIds` (`status: 'partial'`); when every\n * one failed, `status` is `error`. A failed load is never an empty calendar.\n * - While a new range loads, `events` still holds the previous answer (the views place events\n * by day, so the old ones simply fall outside the new days) and `status` is `loading`.\n * - `invalidateCalendarEvents()` (after a write) reloads it, wherever it is mounted.\n * - `eventsInRange` returns a repeating event's first occurrence only (the series isn't\n * expanded); expanding series in the event's zone belongs to the batch query (B7).\n */\nimport { useApolloClient } from '@apollo/client/react';\nimport {\n CalendarV2EventsInRangeDocument,\n type CalendarV2EventsInRangeQuery,\n type CalendarV2EventsInRangeQueryVariables,\n} from '../../generated/wspace-operations';\nimport { useCalendar } from '../../providers/CalendarProvider';\nimport { normalizeCalendarIds } from '../state/calendarV2Store';\nimport type { CalendarEventV2 } from '../types';\nimport { useCalendarEventsRevision } from './invalidation';\nimport { sortEventsV2, toCalendarEventV2 } from './normalize';\nimport { useKeyedLoad } from './useKeyedLoad';\n\nexport interface EventsInRangeV2 {\n events: CalendarEventV2[];\n /**\n * `idle`: skipped. `loading`: this range hasn't answered yet. `ready`. `partial`: some\n * calendars failed (`failedCalendarIds`). `error`: every calendar failed (`error`); `events`\n * then holds this range's last good answer, if a refresh failed, else nothing.\n */\n status: 'idle' | 'loading' | 'ready' | 'partial' | 'error';\n /** A load is running: the first one for this range, or a refresh. */\n isFetching: boolean;\n failedCalendarIds: string[];\n error: Error | null;\n refetch: () => void;\n}\n\ninterface LoadedEvents {\n events: CalendarEventV2[];\n failedCalendarIds: string[];\n}\n\n/** Ids travel in the load key; calendar ids never hold a line break. */\nconst ID_SEPARATOR = '\\n';\n\nexport function useEventsInRangeV2(\n calendarIds: readonly string[],\n from: Date,\n to: Date,\n options: { skip?: boolean } = {}\n): EventsInRangeV2 {\n const client = useApolloClient();\n const { currentUser } = useCalendar();\n const myUserId = currentUser?.id ?? null;\n const revision = useCalendarEventsRevision();\n const idsKey = normalizeCalendarIds(calendarIds).join(ID_SEPARATOR);\n const fromMs = from.getTime();\n const toMs = to.getTime();\n const validRange = Number.isFinite(fromMs) && Number.isFinite(toMs) && toMs > fromMs;\n const key = options.skip || !validRange ? null : [idsKey, fromMs, toMs, myUserId ?? ''].join('|');\n\n const load = useKeyedLoad<LoadedEvents>(\n key,\n async () => {\n const ids = idsKey === '' ? [] : idsKey.split(ID_SEPARATOR);\n if (ids.length === 0) return { events: [], failedCalendarIds: [] };\n const startDate = new Date(fromMs).toISOString();\n const endDate = new Date(toMs).toISOString();\n const settled = await Promise.allSettled(\n ids.map((calendarId) =>\n client.query<CalendarV2EventsInRangeQuery, CalendarV2EventsInRangeQueryVariables>({\n query: CalendarV2EventsInRangeDocument,\n variables: { calendarId, startDate, endDate },\n fetchPolicy: 'network-only',\n })\n )\n );\n const failedCalendarIds: string[] = [];\n const events: CalendarEventV2[] = [];\n let firstFailure: unknown = null;\n settled.forEach((result, index) => {\n const answer = result.status === 'fulfilled' ? result.value.data?.eventsInRange : undefined;\n if (!answer) {\n failedCalendarIds.push(ids[index] ?? '');\n firstFailure ??= result.status === 'rejected' ? result.reason : null;\n return;\n }\n for (const raw of answer) {\n const event = toCalendarEventV2(raw, myUserId);\n if (event) events.push(event);\n }\n });\n if (failedCalendarIds.length === ids.length) {\n throw firstFailure instanceof Error\n ? firstFailure\n : new Error('The events could not be loaded');\n }\n return { events: sortEventsV2(events), failedCalendarIds };\n },\n revision\n );\n\n if (key === null) {\n return {\n events: [],\n status: 'idle',\n isFetching: false,\n failedCalendarIds: [],\n error: null,\n refetch: load.reload,\n };\n }\n const current = load.dataKey === key ? load.data : undefined;\n if (load.error) {\n return {\n events: current?.events ?? [],\n status: 'error',\n isFetching: load.loading,\n failedCalendarIds: [],\n error: load.error,\n refetch: load.reload,\n };\n }\n if (!current) {\n return {\n events: load.data?.events ?? [],\n status: 'loading',\n isFetching: true,\n failedCalendarIds: [],\n error: null,\n refetch: load.reload,\n };\n }\n return {\n events: current.events,\n status: current.failedCalendarIds.length > 0 ? 'partial' : 'ready',\n isFetching: load.loading,\n failedCalendarIds: current.failedCalendarIds,\n error: null,\n refetch: load.reload,\n };\n}\n"],"mappings":";;;;;;;;AAkDA,IAAMA,IAAe;AAErB,SAAgBC,EACd,GACA,GACA,GACA,IAA8B,CAAC,GACd;CACjB,IAAMC,IAASC,EAAgB,GACzB,EAAE,mBAAgBC,EAAY,GAC9BC,IAAWC,GAAa,MAAM,MAC9BC,IAAWC,EAA0B,GACrCC,IAASC,EAAqBC,CAAW,CAAC,CAAC,KAAKX,CAAY,GAC5DY,IAASC,EAAK,QAAQ,GACtBC,IAAOC,EAAG,QAAQ,GAClBC,IAAa,OAAO,SAASJ,CAAM,KAAK,OAAO,SAASE,CAAI,KAAKA,IAAOF,GACxEK,IAAMC,EAAQ,QAAQ,CAACF,IAAa,OAAO;EAACP;EAAQG;EAAQE;EAAMT,KAAY;CAAE,CAAC,CAAC,KAAK,GAAG,GAE1Fc,IAAOC,EACXH,GACA,YAAY;EACV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;EACR,YAAYjB,EAAK;EACjB,mBAAmB,CAAC;EACpB,OAAOA,EAAK;EACZ,SAASA,EAAK;CAChB,IAEGiB,IAUE;EACL,QAAQA,EAAQ;EAChB,QAAQA,EAAQ,kBAAkB,SAAS,IAAI,YAAY;EAC3D,YAAYjB,EAAK;EACjB,mBAAmBiB,EAAQ;EAC3B,OAAO;EACP,SAASjB,EAAK;CAChB,IAhBS;EACL,QAAQA,EAAK,MAAM,UAAU,CAAC;EAC9B,QAAQ;EACR,YAAY;EACZ,mBAAmB,CAAC;EACpB,OAAO;EACP,SAASA,EAAK;CAChB;AAUJ"}
1
+ {"version":3,"file":"useEventsInRangeV2.js","names":["DAY_MS","ID_SEPARATOR","inBatches","batches","index","items","size","rangeQuestions","parts","start","fromMs","toMs","end","calendarIds","batch","part","joinRangeAnswers","failed","unreadable","events","truncated","answered","firstFailure","settled","question","questions","answer","result","id","asked","raw","event","toOccurrenceV2","myUserId","sortEventsV2","useEventsInRangeV2","client","useApolloClient","useCalendar","currentUser","revision","useCalendarEventsRevision","idsKey","normalizeCalendarIds","from","to","validRange","key","options","load","useKeyedLoad","CalendarV2EventOccurrencesDocument","nothing","current"],"sources":["../../../src/v2/data/useEventsInRangeV2.ts"],"sourcesContent":["/**\n * The events of the shown calendars between two instants (BOFF-15698 A0, A4).\n *\n * It asks the service's range query (`eventsInRangeForCalendars`, B7), which expands repeating\n * events in each event's own zone, so a series shows on every one of its dates. One question\n * takes at most 50 calendars and 62 days: more calendars are asked in batches (and a longer\n * range in parts, which the views never need), at once, and the answers joined.\n *\n * - A batch that fails names its calendars in `failedCalendarIds` (`status: 'partial'`): one\n * failing batch doesn't blank the others. When every batch failed, `status` is `error`. A\n * failed load is never an empty calendar.\n * - Calendars the service won't read for this person (not in this workspace, not visible to\n * them, or no right to read their events) are named in `unreadableCalendarIds`: Try again\n * wouldn't change that.\n * - `truncated`: the service stopped at one of its limits (5,000 occurrences an answer, 2,000 a\n * series, its work budget) or couldn't expand a rule, so some dates may be missing.\n * - While a new range loads, `events` still holds the previous answer (the views place events\n * by day, so the old ones simply fall outside the new days) and `status` is `loading`.\n * - `invalidateCalendarEvents()` (after a write) reloads it, wherever it is mounted.\n */\nimport { useApolloClient } from '@apollo/client/react';\nimport {\n CalendarV2EventOccurrencesDocument,\n type CalendarV2EventOccurrencesQuery,\n type CalendarV2EventOccurrencesQueryVariables,\n} from '../../generated/wspace-operations';\nimport { useCalendar } from '../../providers/CalendarProvider';\nimport { normalizeCalendarIds } from '../state/calendarV2Store';\nimport type { CalendarEventV2 } from '../types';\nimport { useCalendarEventsRevision } from './invalidation';\nimport { sortEventsV2, toOccurrenceV2 } from './normalize';\nimport { useKeyedLoad } from './useKeyedLoad';\n\n/** The most calendars one range question takes (the service refuses more). */\nexport const RANGE_MAX_CALENDARS = 50;\n/** The longest range one question covers, in days (the service refuses longer). */\nexport const RANGE_MAX_DAYS = 62;\n\nconst DAY_MS = 86_400_000;\n\nexport interface EventsInRangeV2 {\n /** One per occurrence: a repeating event once for each of its dates in the range. */\n events: CalendarEventV2[];\n /**\n * `idle`: skipped. `loading`: this range hasn't answered yet. `ready`. `partial`: some\n * calendars' questions failed (`failedCalendarIds`). `error`: every question failed\n * (`error`); `events` then holds this range's last good answer, if a refresh failed, else\n * nothing.\n */\n status: 'idle' | 'loading' | 'ready' | 'partial' | 'error';\n /** A load is running: the first one for this range, or a refresh. */\n isFetching: boolean;\n /** Calendars whose question failed: Try again may bring their events. */\n failedCalendarIds: string[];\n /** Calendars the service won't read for this person: their events aren't shown. */\n unreadableCalendarIds: string[];\n /** Some occurrences may be missing: the service stopped at one of its limits. */\n truncated: boolean;\n error: Error | null;\n refetch: () => void;\n}\n\ninterface LoadedEvents {\n events: CalendarEventV2[];\n failedCalendarIds: string[];\n unreadableCalendarIds: string[];\n truncated: boolean;\n}\n\ninterface RangeQuestion {\n calendarIds: string[];\n startDate: string;\n endDate: string;\n}\n\n/** Ids travel in the load key; calendar ids never hold a line break. */\nconst ID_SEPARATOR = '\\n';\n\n/** `items` in runs of at most `size`. */\nexport function inBatches<T>(items: readonly T[], size: number): T[][] {\n const batches: T[][] = [];\n for (let index = 0; index < items.length; index += size) {\n batches.push(items.slice(index, index + size));\n }\n return batches;\n}\n\n/**\n * The questions that cover `calendarIds` from `fromMs` to `toMs`: batches of at most 50\n * calendars, each over parts of the range of at most 62 days.\n */\nexport function rangeQuestions(\n calendarIds: readonly string[],\n fromMs: number,\n toMs: number\n): RangeQuestion[] {\n const parts: { startDate: string; endDate: string }[] = [];\n for (let start = fromMs; start < toMs; start += RANGE_MAX_DAYS * DAY_MS) {\n const end = Math.min(toMs, start + RANGE_MAX_DAYS * DAY_MS);\n parts.push({ startDate: new Date(start).toISOString(), endDate: new Date(end).toISOString() });\n }\n return inBatches(calendarIds, RANGE_MAX_CALENDARS).flatMap((batch) =>\n parts.map((part) => ({ calendarIds: batch, ...part }))\n );\n}\n\ntype RangeAnswer = CalendarV2EventOccurrencesQuery['eventsInRangeForCalendars'];\n\n/**\n * The questions' answers joined: each occurrence once (a part of the range shares the ones that\n * cross into the next), the calendars whose question failed, those the service won't read, and\n * whether any answer was cut off. Throws when every question failed.\n */\nexport function joinRangeAnswers(\n questions: readonly RangeQuestion[],\n settled: readonly PromiseSettledResult<RangeAnswer | null | undefined>[],\n myUserId: string | null\n): LoadedEvents {\n const failed = new Set<string>();\n const unreadable = new Set<string>();\n const events: CalendarEventV2[] = [];\n let truncated = false;\n let answered = 0;\n let firstFailure: unknown = null;\n settled.forEach((result, index) => {\n const question = questions[index];\n if (!question) return;\n const answer = result.status === 'fulfilled' ? result.value : null;\n if (!answer) {\n for (const id of question.calendarIds) failed.add(id);\n firstFailure ??= result.status === 'rejected' ? result.reason : null;\n return;\n }\n answered += 1;\n truncated ||= answer.truncated;\n const asked = new Set(question.calendarIds);\n for (const id of answer.unavailableCalendarIds) if (asked.has(id)) unreadable.add(id);\n for (const raw of answer.occurrences) {\n const event = toOccurrenceV2(raw, myUserId);\n if (event) events.push(event);\n }\n });\n if (questions.length > 0 && answered === 0) {\n throw firstFailure instanceof Error\n ? firstFailure\n : new Error('The events could not be loaded');\n }\n for (const id of failed) unreadable.delete(id);\n return {\n events: sortEventsV2(events),\n failedCalendarIds: [...failed],\n unreadableCalendarIds: [...unreadable],\n truncated,\n };\n}\n\nexport function useEventsInRangeV2(\n calendarIds: readonly string[],\n from: Date,\n to: Date,\n options: { skip?: boolean } = {}\n): EventsInRangeV2 {\n const client = useApolloClient();\n const { currentUser } = useCalendar();\n const myUserId = currentUser?.id ?? null;\n const revision = useCalendarEventsRevision();\n const idsKey = normalizeCalendarIds(calendarIds).join(ID_SEPARATOR);\n const fromMs = from.getTime();\n const toMs = to.getTime();\n const validRange = Number.isFinite(fromMs) && Number.isFinite(toMs) && toMs > fromMs;\n const key = options.skip || !validRange ? null : [idsKey, fromMs, toMs, myUserId ?? ''].join('|');\n\n const load = useKeyedLoad<LoadedEvents>(\n key,\n async () => {\n const ids = idsKey === '' ? [] : idsKey.split(ID_SEPARATOR);\n const questions = rangeQuestions(ids, fromMs, toMs);\n const settled = await Promise.allSettled(\n questions.map(async (variables) => {\n const result = await client.query<\n CalendarV2EventOccurrencesQuery,\n CalendarV2EventOccurrencesQueryVariables\n >({\n query: CalendarV2EventOccurrencesDocument,\n variables,\n fetchPolicy: 'network-only',\n });\n return result.data?.eventsInRangeForCalendars;\n })\n );\n return joinRangeAnswers(questions, settled, myUserId);\n },\n revision\n );\n\n const nothing = {\n failedCalendarIds: [],\n unreadableCalendarIds: [],\n truncated: false,\n refetch: load.reload,\n };\n if (key === null) {\n return { ...nothing, events: [], status: 'idle', isFetching: false, error: null };\n }\n const current = load.dataKey === key ? load.data : undefined;\n if (load.error) {\n return {\n ...nothing,\n events: current?.events ?? [],\n status: 'error',\n isFetching: load.loading,\n error: load.error,\n };\n }\n if (!current) {\n return {\n ...nothing,\n events: load.data?.events ?? [],\n status: 'loading',\n isFetching: true,\n error: null,\n };\n }\n return {\n events: current.events,\n status: current.failedCalendarIds.length > 0 ? 'partial' : 'ready',\n isFetching: load.loading,\n failedCalendarIds: current.failedCalendarIds,\n unreadableCalendarIds: current.unreadableCalendarIds,\n truncated: current.truncated,\n error: null,\n refetch: load.reload,\n };\n}\n"],"mappings":";;;;;;;AAsCA,IAAMA,IAAS,OAsCTC,IAAe;AAGrB,SAAgBC,EAAa,GAAqB,GAAqB;CACrE,IAAMC,IAAiB,CAAC;CACxB,KAAK,IAAIC,IAAQ,GAAGA,IAAQC,EAAM,QAAQ,KAASC,GACjD,EAAQ,KAAKD,EAAM,MAAMD,GAAOA,IAAQE,CAAI,CAAC;CAE/C,OAAOH;AACT;AAMA,SAAgBI,EACd,GACA,GACA,GACiB;CACjB,IAAMC,IAAkD,CAAC;CACzD,KAAK,IAAIC,IAAQC,GAAQD,IAAQE,GAAM,KAAA,KAA0BX,GAAQ;EACvE,IAAMY,IAAM,KAAK,IAAID,GAAMF,IAAA,KAAyBT,CAAM;EAC1D,EAAM,KAAK;GAAE,WAAW,IAAI,KAAKS,CAAK,CAAC,CAAC,YAAY;GAAG,SAAS,IAAI,KAAKG,CAAG,CAAC,CAAC,YAAY;EAAE,CAAC;CAC/F;CACA,OAAOV,EAAUW,GAAA,EAAgC,CAAC,CAAC,SAAS,MAC1DL,EAAM,KAAK,OAAU;EAAE,aAAaM;EAAO,GAAGC;CAAK,EAAE,CACvD;AACF;AASA,SAAgBC,EACd,GACA,GACA,GACc;CACd,IAAMC,oBAAS,IAAI,IAAY,GACzBC,oBAAa,IAAI,IAAY,GAC7BC,IAA4B,CAAC,GAC/BC,IAAY,IACZC,IAAW,GACXC,IAAwB;CAmB5B,IAlBAC,EAAQ,SAAS,GAAQ,MAAU;EACjC,IAAMC,IAAWC,EAAUrB;EAC3B,IAAI,CAACoB,GAAU;EACf,IAAME,IAASC,EAAO,WAAW,cAAcA,EAAO,QAAQ;EAC9D,IAAI,CAACD,GAAQ;GACX,KAAK,IAAME,KAAMJ,EAAS,aAAa,EAAO,IAAII,CAAE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