您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

googleCalendar.js 2.1KB

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