npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

google-calendar-react

v1.0.0

Published

Integration of Google Calendar API on your Custom Client side OR React component

Downloads

8

Readme

google-calendar-react

Integration of Google Calendar API on your Custom Client side OR React component

Install

Using NPM

npm install --save google-calendar-react

Using Yarn

yarn add google-calendar-react

Use

import GoogleAPICalendar from 'google-calendar-react';

Typescript Import

import GoogleAPICalendar from 'google-calendar-react/GoogleAPICalendar';

Go to the https://console.developers.google.com/flows/enableapi?apiid=calendar. find your ApiKey and clientId And

Create a file googleApiConfig.json in the root directory with your googleApi clientId and ApiKey.

{
  "clientId": "<YOUR_GOOGLE_CLIENT_ID>",
  "apiKey": "<YOUR_GOOGLE_API_KEY>",
  "scope": "https://www.googleapis.com/auth/calendar", // Pass your Required Read Write Scopes as per needs.
  "discoveryDocs": [
    "https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest"
  ]
}

Setup

handleAuthClick:

    /**
     * Sign in with a Google account.
     */
    public handleAuthClick(): void

handleSignOutClick:

    /**
     * Sign out user google account
     */
    public handleSignoutClick(): void

Example

  import React, {ReactNode, SyntheticEvent} from 'react';
  import GoogleAPICalendar from 'google-calendar-react';

  export default class DoubleButton extends React.Component {
      constructor(props) {
        super(props);
        this.handleItemClick = this.handleItemClick.bind(this);
      }

      public handleItemClick(event: SyntheticEvent<any>, name: string): void {
        if (name === 'sign-in') {
          GoogleAPICalendar.handleAuthClick();
        } else if (name === 'sign-out') {
          GoogleAPICalendar.handleSignoutClick();
        }
      }

      render(): ReactNode {
        return (
              <button
                  onClick={(e) => this.handleItemClick(e, 'sign-in')}
              >
                sign-in
              </button>
              <button
                  onClick={(e) => this.handleItemClick(e, 'sign-out')}
              >
                sign-out
              </button>
          );
      }
  }

setCalendar:

    /**
     * Set the default attribute calendar
     * @param {string} newCalendar ID.
     */
    public setCalendar(newCalendar: string): void

Manage Event

You need to be registered with handleAuthClick.

Create Event:

    /**
    * Create calendar event
    * @param {string} CalendarId for the event by default use 'primary'.
    * @param {object} Event with start and end dateTime
    * @returns {any} Promise on the event.
    */
   public createEvent(event: object, calendarId: string = this.calendar): any {

Create Event From Now:

     /**
     * Create an event from the current time for a certain period.
     * @param {number} Time in minutes for the event
     * @param {string} Summary(Title) of the event
     * @param {string} Description of the event (optional)
     * @param {string} CalendarId by default calendar set by setCalendar.
     * @returns {any} Promise on the event.
     */
    public createEventFromNow({time, summary, description = ''}: any, calendarId: string = this.calendar): any

Example

import GoogleAPICalendar from "google-calendar-react";

const eventFromNow: object = {
  summary: "Poc Dev From Now",
  time: 480
};

GoogleAPICalendar.createEventFromNow(eventFromNow)
  .then((result: object) => {
    console.log(result);
  })
  .catch((error: any) => {
    console.log(error);
  });

List All Upcoming Events:

    /**
     * List all events in the calendar
     * @param {number} maxResults to see
     * @param {string} calendarId to see by default use the calendar attribute
     * @returns {any} Promise with the result.
     */
    public listUpcomingEvents(maxResults: number, calendarId: string = this.calendar): any

Example

import GoogleAPICalendar from "google-calendar-react";

if (GoogleAPICalendar.sign)
  GoogleAPICalendar.listUpcomingEvents(10).then(({ result }: any) => {
    console.log(result.items);
  });

Utils

listenSign:

     /**
     * Execute the callback function when a user is disconnected or connected with the sign status.
     * @param callback
     */
    public listenSign(callback: any): void

onLoad:

    /**
     * Execute the callback function when gapi is loaded (gapi needs to be loaded to use any other methods)
     * @param callback
     */
    public onLoad(callback: any): void

Example

    import React, {ReactNode} from 'react';
    import GoogleAPICalendar from 'google-calendar-react';

    export default class StatusSign extends React.Component<any, any> {
        constructor(props) {
            super(props);
            this.state = {
              sign: GoogleAPICalendar.sign,
            };
            this.signUpdate = this.signUpdate.bind(this);
            GoogleAPICalendar.onLoad(() => {
                GoogleAPICalendar.listenSign(this.signUpdate);
            });
        }

        public signUpdate(sign: boolean): any {
            this.setState({
                sign
            })
        }

        render(): ReactNode {
            return (
                <div>{this.state.sign}</div>
            );
        }
    }