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 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* @flow */
  2. import {
  3. getCalendarEntries,
  4. googleApi,
  5. loadGoogleAPI,
  6. signIn,
  7. updateProfile
  8. } from '../../google-api';
  9. /**
  10. * A stateless collection of action creators that implements the expected
  11. * interface for interacting with the Google API in order to get calendar data.
  12. *
  13. * @type {Object}
  14. */
  15. export const googleCalendarApi = {
  16. /**
  17. * Retrieves the current calendar events.
  18. *
  19. * @param {number} fetchStartDays - The number of days to go back
  20. * when fetching.
  21. * @param {number} fetchEndDays - The number of days to fetch.
  22. * @returns {function(): Promise<CalendarEntries>}
  23. */
  24. getCalendarEntries,
  25. /**
  26. * Returns the email address for the currently logged in user.
  27. *
  28. * @returns {function(Dispatch<*>): Promise<string|never>}
  29. */
  30. getCurrentEmail() {
  31. return updateProfile();
  32. },
  33. /**
  34. * Initializes the google api if needed.
  35. *
  36. * @returns {function(Dispatch<*>, Function): Promise<void>}
  37. */
  38. load() {
  39. return (dispatch: Dispatch<*>, getState: Function) => {
  40. const { googleApiApplicationClientID }
  41. = getState()['features/base/config'];
  42. return dispatch(loadGoogleAPI(googleApiApplicationClientID));
  43. };
  44. },
  45. /**
  46. * Prompts the participant to sign in to the Google API Client Library.
  47. *
  48. * @returns {function(Dispatch<*>): Promise<string|never>}
  49. */
  50. signIn,
  51. /**
  52. * Returns whether or not the user is currently signed in.
  53. *
  54. * @returns {function(): Promise<boolean>}
  55. */
  56. _isSignedIn() {
  57. return () => googleApi.isSignedIn();
  58. }
  59. };