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.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* @flow */
  2. import {
  3. getCalendarEntries,
  4. googleApi,
  5. loadGoogleAPI,
  6. signIn,
  7. updateCalendarEvent,
  8. updateProfile
  9. } from '../../google-api';
  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<*>): Promise<string|never>}
  30. */
  31. getCurrentEmail() {
  32. return updateProfile();
  33. },
  34. /**
  35. * Initializes the google api if needed.
  36. *
  37. * @returns {function(Dispatch<*>, Function): Promise<void>}
  38. */
  39. load() {
  40. return (dispatch: Dispatch<*>, getState: Function) => {
  41. const { googleApiApplicationClientID }
  42. = getState()['features/base/config'];
  43. return dispatch(loadGoogleAPI(googleApiApplicationClientID));
  44. };
  45. },
  46. /**
  47. * Prompts the participant to sign in to the Google API Client Library.
  48. *
  49. * @returns {function(Dispatch<*>): Promise<string|never>}
  50. */
  51. signIn,
  52. /**
  53. * Returns whether or not the user is currently signed in.
  54. *
  55. * @returns {function(): Promise<boolean>}
  56. */
  57. _isSignedIn() {
  58. return () => googleApi.isSignedIn();
  59. },
  60. /**
  61. * Updates calendar event by generating new invite URL and editing the event
  62. * adding some descriptive text and location.
  63. *
  64. * @param {string} id - The event id.
  65. * @param {string} calendarId - The id of the calendar to use.
  66. * @param {string} location - The location to save to the event.
  67. * @returns {function(Dispatch<*>): Promise<string|never>}
  68. */
  69. updateCalendarEvent
  70. };