You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

googleCalendar.ts 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { IStore } from '../../app/types';
  2. import {
  3. getCalendarEntries,
  4. loadGoogleAPI,
  5. signIn,
  6. updateCalendarEvent,
  7. updateProfile
  8. } from '../../google-api/actions'; // @ts-ignore
  9. import googleApi from '../../google-api/googleApi.web';
  10. /**
  11. * A stateless collection of action creators that implements the expected
  12. * interface for interacting with the Google API in order to get calendar data.
  13. *
  14. * @type {Object}
  15. */
  16. export const googleCalendarApi = {
  17. /**
  18. * Retrieves the current calendar events.
  19. *
  20. * @param {number} fetchStartDays - The number of days to go back
  21. * when fetching.
  22. * @param {number} fetchEndDays - The number of days to fetch.
  23. * @returns {function(): Promise<CalendarEntries>}
  24. */
  25. getCalendarEntries,
  26. /**
  27. * Returns the email address for the currently logged in user.
  28. *
  29. * @returns {function(Dispatch<any>): Promise<string|never>}
  30. */
  31. getCurrentEmail() {
  32. return updateProfile();
  33. },
  34. /**
  35. * Initializes the google api if needed.
  36. *
  37. * @returns {function(Dispatch<any>, Function): Promise<void>}
  38. */
  39. load() {
  40. return (dispatch: IStore['dispatch']) => dispatch(loadGoogleAPI());
  41. },
  42. /**
  43. * Prompts the participant to sign in to the Google API Client Library.
  44. *
  45. * @returns {function(Dispatch<any>): Promise<string|never>}
  46. */
  47. signIn,
  48. /**
  49. * Returns whether or not the user is currently signed in.
  50. *
  51. * @returns {function(): Promise<boolean>}
  52. */
  53. _isSignedIn() {
  54. return () => googleApi.isSignedIn();
  55. },
  56. /**
  57. * Updates calendar event by generating new invite URL and editing the event
  58. * adding some descriptive text and location.
  59. *
  60. * @param {string} id - The event id.
  61. * @param {string} calendarId - The id of the calendar to use.
  62. * @param {string} location - The location to save to the event.
  63. * @returns {function(Dispatch<any>): Promise<string|never>}
  64. */
  65. updateCalendarEvent
  66. };