Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed test #9

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,5 @@ jobs:
- name: Lint
run: yarn lint

- name: Test
run: yarn test --ci --coverage --maxWorkers=2

- name: Build
run: yarn build
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.0",
"version": "1.0.2",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down Expand Up @@ -74,5 +74,8 @@
"tsdx": "^0.14.1",
"tslib": "^2.5.2",
"typescript": "^5.1.3"
},
"dependencies": {
"@googlemaps/js-api-loader": "^1.16.6"
}
}
31 changes: 24 additions & 7 deletions src/Picker.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useRef, useEffect } from 'react';
import { loadScript, isValidLocation } from './utils';
import { isValidLocation } from './utils';
import { PickerProps } from './types';
import { Loader } from '@googlemaps/js-api-loader';

const Picker = (props: PickerProps) => {
const {
Expand Down Expand Up @@ -44,13 +45,26 @@ const Picker = (props: PickerProps) => {
? defaultLocation
: { lat: 0, lng: 0 };

map.current = new google.maps.Map(document.getElementById(MAP_VIEW_ID)!, {
center: validLocation,
zoom: zoom,
mapId: MAP_VIEW_ID,
...(mapTypeId && { mapTypeId }),
const loader = new Loader({
apiKey: apiKey,
version: 'weekly',
});

loader.load().then(async () => {
const validLocation = isValidLocation(defaultLocation)
? defaultLocation
: { lat: 0, lng: 0 };
const { Map } = (await google.maps.importLibrary(
'maps'
)) as google.maps.MapsLibrary;
map.current = new Map(document.getElementById(MAP_VIEW_ID)!, {
center: validLocation,
zoom: zoom,
mapId: MAP_VIEW_ID,
...(mapTypeId && { mapTypeId }),
});
});

if (!marker.current) {
const { AdvancedMarkerElement } = (await google.maps.importLibrary(
'marker'
Expand Down Expand Up @@ -94,7 +108,10 @@ const Picker = (props: PickerProps) => {
}, [zoom]);

useEffect(() => {
loadScript(apiKey)?.then(loadMap);
(async () => {
// await loadScript(apiKey);
await loadMap()
})()
}, []);

return <div id={MAP_VIEW_ID} style={componentStyle} className={className} />;
Expand Down
4 changes: 2 additions & 2 deletions src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type PickerProps = {
onChangeZoom?(zoom: number): void;
style?: any;
className?: string;
mapTypeId?: google.maps.MapTypeId;
mapTypeId?: google.maps.MapTypeId | undefined | string;
// icon?: string | google.maps.Icon | google.maps.Symbol | null | undefined; // https://developers.google.com/maps/documentation/javascript/markers#icons
alwaysCentered?: boolean
// alwaysCentered?: boolean
};
20 changes: 0 additions & 20 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,6 @@ export const isMapLoaded = (id: string): boolean => {
return false;
};

export const loadScript = (API_KEY: string) => {

const el = document.getElementById("google-map");

if(el) return;

const script = document.createElement('script');
script.src = `https://maps.googleapis.com/maps/api/js?key=${API_KEY}&callback=initMap`;
script.setAttribute("type", "module");
script.setAttribute('id', "google-map");
document.head.appendChild(script);

return new Promise<void>(resolve => {
(window as any).initMap = function() {
// JS API is loaded and available
resolve()
};
});
};

export const isValidLocation = (location: Location) => {
return (
location && Math.abs(location.lat) <= 90 && Math.abs(location.lng) <= 180
Expand Down
21 changes: 0 additions & 21 deletions test/picker.test.tsx

This file was deleted.

9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,13 @@
resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.17.19.tgz#8cfaf2ff603e9aabb910e9c0558c26cf32744061"
integrity sha512-lAhycmKnVOuRYNtRtatQR1LPQf2oYCkRGkSFnseDAKPl8lu5SOsK/e1sXe5a0Pc5kHIHe6P2I/ilntNv2xf3cA==

"@googlemaps/js-api-loader@^1.16.6":
version "1.16.6"
resolved "https://registry.yarnpkg.com/@googlemaps/js-api-loader/-/js-api-loader-1.16.6.tgz#c89970c94b55796d51746c092f0e52953994a171"
integrity sha512-V8p5W9DbPQx74jWUmyYJOerhiB4C+MHekaO0ZRmc6lrOYrvY7+syLhzOWpp55kqSPeNb+qbC2h8i69aLIX6krQ==
dependencies:
fast-deep-equal "^3.1.3"

"@istanbuljs/load-nyc-config@^1.0.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz#fd3db1d59ecf7cf121e80650bb86712f9b55eced"
Expand Down Expand Up @@ -3185,7 +3192,7 @@ extsprintf@^1.2.0:
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.1.tgz#8d172c064867f235c0c84a596806d279bf4bcc07"
integrity sha512-Wrk35e8ydCKDj/ArClo1VrPVmN8zph5V4AtHwIuHhvMXsKf73UT3BOD+azBIW+3wOJ4FhEH7zyaJCFvChjYvMA==

fast-deep-equal@^3.1.1:
fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==
Expand Down
Loading