Skip to content

Commit

Permalink
fix: events and types
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoehnelt committed Sep 3, 2024
1 parent e532706 commit 0a59532
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ Note: The Google Picker API does not support file organization, moving, or copyi

### Methods

| Method | Type |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `addEventListener` | `(type: "cancel" \| "picked", listener: (ev: CustomEvent<ResponseObject>): void, options?: boolean \| AddEventListenerOptions \| undefined) => void` |
| `removeEventListener` | `(type: "cancel" \| "picked", listener: (ev: CustomEvent<ResponseObject>): void, options?: boolean \| EventListenerOptions \| undefined) => void` |
| Method | Type |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `addEventListener` | `(type: "cancel" \| "picked" \| "loaded", listener: (ev: DrivePickerEvent): void, options?: boolean \| AddEventListenerOptions \| undefined) => void` |
| `removeEventListener` | `(type: "cancel" \| "picked" \| "loaded", listener: (ev: DrivePickerEvent): void, options?: boolean \| EventListenerOptions \| undefined) => void` |

### Events

Expand Down
16 changes: 12 additions & 4 deletions src/drive-picker/drive-picker-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,19 @@ export interface DrivePickerElementProps {
width?: number;
}

export type DrivePickerEvent = CustomEvent<google.picker.ResponseObject>;

// TODO fix typings for Action to include "loaded"

export interface DrivePickerElementEventListeners {
addEventListener(
type: "cancel" | "picked",
listener: (ev: CustomEvent<google.picker.ResponseObject>) => void,
type: "cancel" | "picked" | "loaded",
listener: (ev: DrivePickerEvent) => void,
options?: boolean | AddEventListenerOptions,
): void;
removeEventListener(
type: "cancel" | "picked",
listener: (ev: CustomEvent<google.picker.ResponseObject>) => void,
type: "cancel" | "picked" | "loaded",
listener: (ev: DrivePickerEvent) => void,
options?: boolean | EventListenerOptions,
): void;
}
Expand Down Expand Up @@ -275,6 +279,10 @@ export class DrivePickerElement

private callbackToDispatchEvent(data: google.picker.ResponseObject) {
this.visible = Boolean(this.picker?.isVisible());
// TODO file bug for this
if (data.action === google.picker.Action.CANCEL) {
this.visible = false;
}
this.dispatch(data.action, data);
}

Expand Down
1 change: 1 addition & 0 deletions src/drive-picker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

export {
DrivePickerElement,
type DrivePickerEvent,
type DrivePickerElementProps,
} from "./drive-picker-element";

Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function retrieveAccessToken(
}

return new Promise((resolve) => {
const client = google.accounts.oauth2.initTokenClient({
const client = window.google.accounts.oauth2.initTokenClient({
client_id: clientId,
scope,

Expand Down

0 comments on commit 0a59532

Please sign in to comment.