Skip to content

Commit

Permalink
Merge pull request #179 from keita-makino/qualtrics-patch
Browse files Browse the repository at this point in the history
3.0.1 1
  • Loading branch information
keita-makino authored Mar 6, 2024
2 parents 3ffd4a3 + caa575d commit 40e41db
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 33 deletions.
6 changes: 3 additions & 3 deletions dist/bundle.js

Large diffs are not rendered by default.

10 changes: 1 addition & 9 deletions src/components/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ export const Container: React.FC<Props> = (props) => {
type: 'MAP_MOVE',
location: props.view.location,
});
update({
type: 'SET_ACCESS_TOKEN',
accessToken: props.accessToken,
});
} else {
geocoderService
.forwardGeocode({
Expand All @@ -54,10 +50,6 @@ export const Container: React.FC<Props> = (props) => {
},
});
}
update({
type: 'SET_ACCESS_TOKEN',
accessToken: props.accessToken,
});
});
}

Expand Down Expand Up @@ -93,7 +85,7 @@ export const Container: React.FC<Props> = (props) => {
return (
<Grid container>
<InputForm />
<Map />
<Map accessToken={props.accessToken} />
<ClearButton />
</Grid>
);
Expand Down
13 changes: 8 additions & 5 deletions src/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@ import mapboxgl from 'mapbox-gl'; // eslint-disable-line import/no-webpack-loade
import styled from '@emotion/styled';
import { useStandbyIndex } from '../uses/useStandbyIndex';

export const Map: React.FC = () => {
type Props = {
accessToken: string;
};

export const Map: React.FC<Props> = (props: Props) => {
const update = useUpdate();
const state = useTrackedState();
const index = useStandbyIndex();

const mapContainer = useRef<any>(null);

useEffect(() => {
if (!mapContainer.current || !state.accessToken) return;
if (!mapContainer.current || !props.accessToken) return;
const newMap = new mapboxgl.Map({
container: mapContainer.current,
style: 'mapbox://styles/mapbox/streets-v12',
center: [state.view.location.lng, state.view.location.lat],
zoom: state.view.zoom,
accessToken: state.accessToken,
accessToken: props.accessToken,
});

newMap.on('click', (event: any) => {
Expand Down Expand Up @@ -58,7 +61,7 @@ export const Map: React.FC = () => {
type: 'INITIALIZE_MAP',
map: newMap,
});
}, [mapContainer, state.accessToken]);
}, [mapContainer, props.accessToken]);

useEffect(() => {
if (state.markers.length === 0 && state.inputs.length > 0 && state.map) {
Expand Down
10 changes: 5 additions & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ import { Container } from './components';
import { Provider } from './store';

const mapRender = (
apiKey: string,
accessToken: string,
target: HTMLElement,
defaultView?: {
location: { lat: number; lng: number };
zoom: number;
}
},
) => {
const container = document.createElement('div');
container.setAttribute('id', `MapContainer${target.id}`);

target.getElementsByClassName('ChoiceStructure')[0].appendChild(container);

const directionContainer = target.querySelectorAll(
'[role*=presentation]'
'[role*=presentation]',
)[0] as HTMLElement;

render(
<Provider>
<Container
accessToken={apiKey}
accessToken={accessToken}
directionContainer={directionContainer}
view={defaultView}
/>
</Provider>,
document.getElementById(`MapContainer${target.id}`)
document.getElementById(`MapContainer${target.id}`),
);
directionContainer.style.display = 'none';
};
Expand Down
6 changes: 0 additions & 6 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { MapiRequest } from '@mapbox/mapbox-sdk/lib/classes/mapi-request';
import { reducer } from './reducer';

export type GlobalState = {
accessToken?: string;
inputs: Input[];
map?: Map;
view: View;
Expand All @@ -18,7 +17,6 @@ export type GlobalState = {
};

const initialState: GlobalState = {
accessToken: undefined,
inputs: [],
map: undefined,
view: {
Expand All @@ -31,10 +29,6 @@ const initialState: GlobalState = {
};

export type Action =
| {
type: 'SET_ACCESS_TOKEN';
accessToken: string;
}
| {
type: 'ADD_INPUTS';
inputs: Input[];
Expand Down
5 changes: 0 additions & 5 deletions src/store/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import { mapClick } from './mapClick';

export const reducer = (state: GlobalState, action: Action): GlobalState => {
switch (action.type) {
case 'SET_ACCESS_TOKEN':
return {
...state,
accessToken: action.accessToken,
};
case 'INITIALIZE_GEOCODER': {
return {
...state,
Expand Down

0 comments on commit 40e41db

Please sign in to comment.