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

url 파싱의 숫자 변환 추가 #194

Merged
merged 2 commits into from
Dec 15, 2020
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
11 changes: 7 additions & 4 deletions src/hooks/map/useMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import useMarkerFeature, {
getInitialMarkersFromLocalStorage,
} from '../../hooks/map/useMarkerFeature';
import { urlToJson } from '../../utils/urlParsing';
import validateStyle from '../../utils/validateStyle';
import {
WholeStyleActionPayload,
HistoryState,
Expand Down Expand Up @@ -49,10 +50,12 @@ function useMap(): MapHookType {
if (search && pathname === URLPathNameType.show) {
const { filteredStyle, mapCoordinate } = urlToJson();

// 이부분에 문제가 있는 것 같습니다. 없애면 에러 안나고 잘 되는데 있으면 안되요
// if (validateStyle(states.filteredStyle as WholeStyleActionPayload)) {
changeStyle(filteredStyle as WholeStyleActionPayload);
// }
if (validateStyle(filteredStyle as WholeStyleActionPayload)) {
changeStyle(filteredStyle as WholeStyleActionPayload);
} else {
alert('URL에 잘못된 속성이 포함되어 있습니다.');
}

const { zoom, lng, lat } = mapCoordinate as LocationType;
if (zoom && lng && lat) {
map.setCenter({ lng, lat });
Expand Down
16 changes: 13 additions & 3 deletions src/utils/urlParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function jsonToURL({
}: ExportType): string {
const url =
process.env.NODE_ENV === 'development'
? 'http://localhost:3000/show?='
? 'http://localhost:3000/show?'
: process.env.REACT_APP_DEPLOY_URL;
const styleQueryString = isNotEmptyObject(filteredStyle)
? `style=${encodeURIComponent(
Expand All @@ -88,6 +88,12 @@ export function jsonToURL({
return url + locationQueryString + styleQueryString + markerQueryString;
}

function stringToNumber(style: string): number | string {
const result = Number(style);
if (Number.isNaN(result)) return style;
return result;
}

function urlToJsonGetStyleJson(styleParams: string): URLJsonFeatureType {
if (!styleParams) return {};

Expand Down Expand Up @@ -130,14 +136,18 @@ function urlToJsonGetStyleJson(styleParams: string): URLJsonFeatureType {
element
] as URLJsonSubFeatureType)[
value as StyleKeyType
] as URLJsonStyleType) = values[index + 1] as URLJsonStyleType;
] as URLJsonStyleType) = stringToNumber(
values[index + 1]
) as URLJsonStyleType;
return;
}
((((state[feature] as URLJsonSubFeatureType)[subFeature][
element
] as URLJsonSubFeatureType)[subElement] as URLJsonStyleType)[
value as StyleKeyType
] as URLJsonStyleType) = values[index + 1] as URLJsonStyleType;
] as URLJsonStyleType) = stringToNumber(
values[index + 1]
) as URLJsonStyleType;
}
});
return state as URLJsonFeatureType;
Expand Down