Skip to content

Commit

Permalink
Fix API key not passing through bug
Browse files Browse the repository at this point in the history
  • Loading branch information
theLAZYmd authored and theLAZYmd committed Apr 11, 2021
1 parent a3d0762 commit 214937f
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 18 deletions.
3 changes: 3 additions & 0 deletions build/hooks/useEvents.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AxiosError } from 'axios';
import { CalendarEvent } from '../Event';
interface EventHookProps {
calendars: {
Expand All @@ -10,6 +11,8 @@ interface EventHookProps {
events?: {
[timestamp: number]: CalendarEvent[];
};
APIkey?: string;
onError?: (e: AxiosError) => void;
}
export default function useEvents(props: EventHookProps): {
colors: {
Expand Down
2 changes: 2 additions & 0 deletions build/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CalendarSettings } from './interfaces';
import { CalendarFrameProps } from './Frame';
import { CalendarEvent } from './Event';
import { AxiosError } from 'axios';
export * from './interfaces';
export * from './Event';
export * from './Key';
Expand All @@ -26,6 +27,7 @@ export interface CalendarProps {
finish?: Date;
title?: string;
timeZone?: string;
onError?: (e: AxiosError) => void;
classNames?: {
[key: string]: string;
};
Expand Down
20 changes: 14 additions & 6 deletions build/index.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/index.es.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions lib/hooks/useEvents.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AxiosError } from 'axios';
import { CalendarEvent } from '../Event';
interface EventHookProps {
calendars: {
Expand All @@ -10,6 +11,8 @@ interface EventHookProps {
events?: {
[timestamp: number]: CalendarEvent[];
};
APIkey?: string;
onError?: (e: AxiosError) => void;
}
export default function useEvents(props: EventHookProps): {
colors: {
Expand Down
2 changes: 2 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CalendarSettings } from './interfaces';
import { CalendarFrameProps } from './Frame';
import { CalendarEvent } from './Event';
import { AxiosError } from 'axios';
export * from './interfaces';
export * from './Event';
export * from './Key';
Expand All @@ -26,6 +27,7 @@ export interface CalendarProps {
finish?: Date;
title?: string;
timeZone?: string;
onError?: (e: AxiosError) => void;
classNames?: {
[key: string]: string;
};
Expand Down
20 changes: 14 additions & 6 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reactjs-google-calendar",
"version": "2.1.2",
"version": "2.1.3",
"description": "A functional calendar renderer for events from a google calendar",
"main": "./lib/index.js",
"module": "build/index.es.js",
Expand Down
9 changes: 7 additions & 2 deletions src/hooks/useEvents.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios, { AxiosResponse } from 'axios';
import axios, { AxiosError, AxiosResponse } from 'axios';
import { CalendarSettingsContext } from '../contexts';
import { CalendarEvent } from '../Event';
import { useCallback, useContext, useEffect, useState } from 'react';
Expand All @@ -16,6 +16,8 @@ interface EventHookProps {
events?: {
[timestamp: number]: CalendarEvent[]
}
APIkey?: string
onError?: (e: AxiosError) => void
}

export default function useEvents(props: EventHookProps) {
Expand All @@ -40,8 +42,11 @@ export default function useEvents(props: EventHookProps) {
sanitizeHtml: true,
timeMin: new Date(props.start).toISOString(), //'2019-10-27T00:00:00Z',
timeMax: new Date(props.finish || Date.now()).toISOString(), //'2019-12-01T00:00:00Z',
key: settings.APIkey
key: props.APIkey
}
}).catch((e) => {
if (props.onError) props.onError(e);
else throw e;
}) as AxiosResponse<GoogleCalendar>;
let { data } = res;
let calendarName = data.summary;
Expand Down
6 changes: 5 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useEffect } from 'react';
import { getEventDate, updateHash } from './utils';
import { CalendarEvent } from './Event';
import { useMemo } from 'react';
import { AxiosError } from 'axios';

export * from './interfaces';
export * from './Event';
Expand All @@ -32,6 +33,7 @@ export interface CalendarProps {
finish?: Date
title?: string
timeZone?: string
onError?: (e: AxiosError) => void

classNames?: {[key: string]: string}
noUpdateHash?: boolean
Expand Down Expand Up @@ -77,7 +79,9 @@ export default function Calendar(props: CalendarProps &
start: props.start,
finish: props.finish,
timeZone: props.timeZone,
events: props.events
events: props.events,
APIkey: props.settings?.APIkey,
onError: props.onError
});

return (
Expand Down

0 comments on commit 214937f

Please sign in to comment.