From ccd13a66ea6e60cfc8d1b50c045e3c2e438edae3 Mon Sep 17 00:00:00 2001 From: Ahmad Azizi <91204996+its-aazizi@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:58:58 +0500 Subject: [PATCH 1/4] updated political view config to support new country codes, desctiption to be updated --- extra/translation-script-content/update-en.json | 15 ++++++++++++++- src/atomicui/molecules/MapButtons/MapButtons.tsx | 8 +++----- src/core/constants/appConfig.ts | 6 +++++- src/setupTests.ts | 6 +++++- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/extra/translation-script-content/update-en.json b/extra/translation-script-content/update-en.json index 0967ef42..074dd703 100644 --- a/extra/translation-script-content/update-en.json +++ b/extra/translation-script-content/update-en.json @@ -1 +1,14 @@ -{} +{ + "georgia_political_view_desc": { + "text": "" + }, + "cyprus_political_view_desc": { + "text": "" + }, + "palestine_political_view_desc": { + "text": "" + }, + "greece_political_view_desc": { + "text": "" + } +} diff --git a/src/atomicui/molecules/MapButtons/MapButtons.tsx b/src/atomicui/molecules/MapButtons/MapButtons.tsx index a52694fe..c3d6cf65 100644 --- a/src/atomicui/molecules/MapButtons/MapButtons.tsx +++ b/src/atomicui/molecules/MapButtons/MapButtons.tsx @@ -230,7 +230,7 @@ const MapButtons: FC = ({ ))} - + = ({ ))} - - - - + + diff --git a/src/core/constants/appConfig.ts b/src/core/constants/appConfig.ts index b8481ccd..e1d72eb1 100644 --- a/src/core/constants/appConfig.ts +++ b/src/core/constants/appConfig.ts @@ -134,7 +134,11 @@ const appConfig = { { alpha2: "SY", alpha3: "SYR", desc: "syria_political_view_desc.text" }, { alpha2: "TR", alpha3: "TUR", desc: "turkey_political_view_desc.text" }, { alpha2: "TZ", alpha3: "TZA", desc: "tanzania_political_view_desc.text" }, - { alpha2: "UY", alpha3: "URY", desc: "uruguay_political_view_desc.text" } + { alpha2: "UY", alpha3: "URY", desc: "uruguay_political_view_desc.text" }, + { alpha2: "GE", alpha3: "GEO", desc: "georgia_political_view_desc.text" }, + { alpha2: "CY", alpha3: "CYP", desc: "cyprus_political_view_desc.text" }, + { alpha2: "PS", alpha3: "PSE", desc: "palestine_political_view_desc.text" }, + { alpha2: "GR", alpha3: "GRC", desc: "greece_political_view_desc.text" } ], GEOFENCE_COLLECTION: "location.aws.com.demo.geofences.GeofenceCollection", DEVICE_ID_WEB: "web_browser_device", diff --git a/src/setupTests.ts b/src/setupTests.ts index 917e01fa..8d76de76 100644 --- a/src/setupTests.ts +++ b/src/setupTests.ts @@ -122,7 +122,11 @@ jest.mock("@demo/core/constants/appConfig", () => ({ { alpha2: "SY", alpha3: "SYR", desc: "syria_political_view_desc.text" }, { alpha2: "TR", alpha3: "TUR", desc: "turkey_political_view_desc.text" }, { alpha2: "TZ", alpha3: "TZA", desc: "tanzania_political_view_desc.text" }, - { alpha2: "UY", alpha3: "URY", desc: "uruguay_political_view_desc.text" } + { alpha2: "UY", alpha3: "URY", desc: "uruguay_political_view_desc.text" }, + { alpha2: "GE", alpha3: "GEO", desc: "georgia_political_view_desc.text" }, + { alpha2: "CY", alpha3: "CYP", desc: "cyprus_political_view_desc.text" }, + { alpha2: "PS", alpha3: "PSE", desc: "palestine_political_view_desc.text" }, + { alpha2: "GR", alpha3: "GRC", desc: "greece_political_view_desc.text" } ], GEOFENCE_COLLECTION: "location.aws.com.demo.geofences.GeofenceCollection", DEVICE_ID_WEB: "web_browser_device", From 9665e5c4e414008c3be2f0547489152bd39237ed Mon Sep 17 00:00:00 2001 From: Ahmad Azizi <91204996+its-aazizi@users.noreply.github.com> Date: Fri, 22 Nov 2024 16:51:34 +0500 Subject: [PATCH 2/4] hide political view flags for windows OS, fixed map language issue for Portuguese and Chinese --- .../PoliticalViewDropdown.tsx | 10 +++++---- src/hooks/useMapManager.ts | 2 +- src/utils/getUserAgent.ts | 21 ++++++++++++++----- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/atomicui/atoms/PoliticalViewDropdown/PoliticalViewDropdown.tsx b/src/atomicui/atoms/PoliticalViewDropdown/PoliticalViewDropdown.tsx index a5ed55d1..d8489523 100644 --- a/src/atomicui/atoms/PoliticalViewDropdown/PoliticalViewDropdown.tsx +++ b/src/atomicui/atoms/PoliticalViewDropdown/PoliticalViewDropdown.tsx @@ -4,7 +4,7 @@ import { Flex, Text } from "@aws-amplify/ui-react"; import { IconArrow } from "@demo/assets/svgs"; import { appConfig } from "@demo/core/constants"; import { useMap } from "@demo/hooks"; -import { getFlagEmoji } from "@demo/utils"; +import { getFlagEmoji, isUserDeviceIsWin } from "@demo/utils"; import { useTranslation } from "react-i18next"; import "./styles.scss"; import { Tooltip } from "react-tooltip"; @@ -95,9 +95,11 @@ const PoliticalViewDropdown: FC = ({ {!!alpha2 && !!alpha3 ? ( <> - - {getFlagEmoji(alpha2)} - + {!isUserDeviceIsWin() && ( + + {getFlagEmoji(alpha2)} + + )} {alpha3} diff --git a/src/hooks/useMapManager.ts b/src/hooks/useMapManager.ts index 89a9efc2..54c29335 100644 --- a/src/hooks/useMapManager.ts +++ b/src/hooks/useMapManager.ts @@ -80,7 +80,7 @@ const useMapManager = ({ useEffect(() => { (async () => { - const styleWithLanguage = await getStyleWithPreferredLanguage(mapStyleUrl, language); + const styleWithLanguage = await getStyleWithPreferredLanguage(mapStyleUrl, language.slice(0, 2)); setMapStyleWithLanguageUrl(styleWithLanguage); })(); }, [mapStyleUrl, language]); diff --git a/src/utils/getUserAgent.ts b/src/utils/getUserAgent.ts index d02534c5..650e30d3 100644 --- a/src/utils/getUserAgent.ts +++ b/src/utils/getUserAgent.ts @@ -11,11 +11,22 @@ const iosCheck = /* iPad on iOS 13 detection */ (navigator.userAgent.includes("Mac") && "ontouchend" in document); -function isUserDeviceIsIOS() { +const isUserDeviceIsIOS = () => { return iosCheck && androidCheck === false ? IOS : undefined; -} -function isUserDeviceIsAndroid(): string | undefined { +}; + +const isUserDeviceIsAndroid = () => { return androidCheck && iosCheck === false ? ANDROID : undefined; -} +}; + +const isUserDeviceIsWin = (): boolean => { + const userAgentData = (navigator as Navigator & { userAgentData?: { platform: string } }).userAgentData; + + if (userAgentData) { + return userAgentData.platform.includes("Win"); + } + + return /Windows/.test(navigator.userAgent); +}; -export { isUserDeviceIsIOS, isUserDeviceIsAndroid }; +export { isUserDeviceIsIOS, isUserDeviceIsAndroid, isUserDeviceIsWin }; From 986f97e82308c58a283191ff10cea10b6824b530 Mon Sep 17 00:00:00 2001 From: Ahmad Azizi <91204996+its-aazizi@users.noreply.github.com> Date: Wed, 27 Nov 2024 23:08:01 +0500 Subject: [PATCH 3/4] added isSupportedByPlaces flag to political view --- .../PoliticalViewDropdown.tsx | 6 ++-- src/core/constants/appConfig.ts | 36 +++++++++---------- src/hooks/useMap.ts | 7 +++- src/services/usePlaceService.ts | 15 ++++---- src/setupTests.ts | 36 +++++++++---------- src/stores/useMapStore.ts | 5 +-- 6 files changed, 57 insertions(+), 48 deletions(-) diff --git a/src/atomicui/atoms/PoliticalViewDropdown/PoliticalViewDropdown.tsx b/src/atomicui/atoms/PoliticalViewDropdown/PoliticalViewDropdown.tsx index d8489523..e38d54d2 100644 --- a/src/atomicui/atoms/PoliticalViewDropdown/PoliticalViewDropdown.tsx +++ b/src/atomicui/atoms/PoliticalViewDropdown/PoliticalViewDropdown.tsx @@ -48,7 +48,7 @@ const PoliticalViewDropdown: FC = ({ }, []); const handleClick = useCallback( - (option: { alpha2: string; alpha3: string; desc: string }) => { + (option: { alpha2: string; alpha3: string; desc: string; isSupportedByPlaces: boolean }) => { setMapPoliticalView(option); setOpen(false); }, @@ -83,13 +83,13 @@ const PoliticalViewDropdown: FC = ({ {disabled && } {open && (
    - {MAP_POLITICAL_VIEWS.map(({ alpha2, alpha3, desc }) => { + {MAP_POLITICAL_VIEWS.map(({ alpha2, alpha3, desc, isSupportedByPlaces }) => { return (
  • handleClick({ alpha2, alpha3, desc })} + onClick={() => handleClick({ alpha2, alpha3, desc, isSupportedByPlaces })} > {!!alpha2 && !!alpha3 ? ( diff --git a/src/core/constants/appConfig.ts b/src/core/constants/appConfig.ts index e1d72eb1..d45ddbc4 100644 --- a/src/core/constants/appConfig.ts +++ b/src/core/constants/appConfig.ts @@ -121,24 +121,24 @@ const appConfig = { { id: MapColorSchemeEnum.DARK.toLowerCase(), name: MapColorSchemeEnum.DARK } ], MAP_POLITICAL_VIEWS: [ - { alpha2: "", alpha3: "", desc: "no_political_view.text" }, - { alpha2: "AR", alpha3: "ARG", desc: "argentina_political_view_desc.text" }, - { alpha2: "EG", alpha3: "EGY", desc: "egypt_political_view_desc.text" }, - { alpha2: "IN", alpha3: "IND", desc: "india_political_view_desc.text" }, - { alpha2: "KE", alpha3: "KEN", desc: "kenya_political_view_desc.text" }, - { alpha2: "MA", alpha3: "MAR", desc: "morocco_political_view_desc.text" }, - { alpha2: "RU", alpha3: "RUS", desc: "russia_political_view_desc.text" }, - { alpha2: "SD", alpha3: "SDN", desc: "sudan_political_view_desc.text" }, - { alpha2: "RS", alpha3: "SRB", desc: "serbia_political_view_desc.text" }, - { alpha2: "SR", alpha3: "SUR", desc: "suriname_political_view_desc.text" }, - { alpha2: "SY", alpha3: "SYR", desc: "syria_political_view_desc.text" }, - { alpha2: "TR", alpha3: "TUR", desc: "turkey_political_view_desc.text" }, - { alpha2: "TZ", alpha3: "TZA", desc: "tanzania_political_view_desc.text" }, - { alpha2: "UY", alpha3: "URY", desc: "uruguay_political_view_desc.text" }, - { alpha2: "GE", alpha3: "GEO", desc: "georgia_political_view_desc.text" }, - { alpha2: "CY", alpha3: "CYP", desc: "cyprus_political_view_desc.text" }, - { alpha2: "PS", alpha3: "PSE", desc: "palestine_political_view_desc.text" }, - { alpha2: "GR", alpha3: "GRC", desc: "greece_political_view_desc.text" } + { alpha2: "", alpha3: "", desc: "no_political_view.text", isSupportedByPlaces: false }, + { alpha2: "AR", alpha3: "ARG", desc: "argentina_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "EG", alpha3: "EGY", desc: "egypt_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "IN", alpha3: "IND", desc: "india_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "KE", alpha3: "KEN", desc: "kenya_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "MA", alpha3: "MAR", desc: "morocco_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "RU", alpha3: "RUS", desc: "russia_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "SD", alpha3: "SDN", desc: "sudan_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "RS", alpha3: "SRB", desc: "serbia_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "SR", alpha3: "SUR", desc: "suriname_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "SY", alpha3: "SYR", desc: "syria_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "TR", alpha3: "TUR", desc: "turkey_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "TZ", alpha3: "TZA", desc: "tanzania_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "UY", alpha3: "URY", desc: "uruguay_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "GE", alpha3: "GEO", desc: "georgia_political_view_desc.text", isSupportedByPlaces: false }, + { alpha2: "CY", alpha3: "CYP", desc: "cyprus_political_view_desc.text", isSupportedByPlaces: false }, + { alpha2: "PS", alpha3: "PSE", desc: "palestine_political_view_desc.text", isSupportedByPlaces: false }, + { alpha2: "GR", alpha3: "GRC", desc: "greece_political_view_desc.text", isSupportedByPlaces: false } ], GEOFENCE_COLLECTION: "location.aws.com.demo.geofences.GeofenceCollection", DEVICE_ID_WEB: "web_browser_device", diff --git a/src/hooks/useMap.ts b/src/hooks/useMap.ts index cec96c3a..74ed4776 100644 --- a/src/hooks/useMap.ts +++ b/src/hooks/useMap.ts @@ -49,7 +49,12 @@ const useMap = () => { setMapColorScheme: (mapColorScheme: MapColorSchemeEnum) => { setState({ mapColorScheme }); }, - setMapPoliticalView: (mapPoliticalView: { alpha2: string; alpha3: string; desc: string }) => { + setMapPoliticalView: (mapPoliticalView: { + alpha2: string; + alpha3: string; + desc: string; + isSupportedByPlaces: boolean; + }) => { setState({ mapPoliticalView }); }, setBiasPosition: (biasPosition: number[]) => { diff --git a/src/services/usePlaceService.ts b/src/services/usePlaceService.ts index 70b3bd56..14cb41bf 100644 --- a/src/services/usePlaceService.ts +++ b/src/services/usePlaceService.ts @@ -23,7 +23,10 @@ const { const usePlaceService = () => { const { placesClient } = useClient(); - const { mapPoliticalView, biasPosition: BiasPosition } = useMap(); + const { + mapPoliticalView: { alpha3, isSupportedByPlaces }, + biasPosition: BiasPosition + } = useMap(); const { i18n } = useTranslation(); const Language = i18n.language; @@ -35,7 +38,7 @@ const usePlaceService = () => { BiasPosition, Language, AdditionalFeatures: ["Core"], - PoliticalView: mapPoliticalView.alpha3 || undefined + PoliticalView: isSupportedByPlaces ? alpha3 : undefined }; const command = new SuggestCommand(input); return await placesClient?.send(command); @@ -45,7 +48,7 @@ const usePlaceService = () => { PlaceId, Language, AdditionalFeatures: ["Contact"], - PoliticalView: mapPoliticalView.alpha3 || undefined + PoliticalView: isSupportedByPlaces ? alpha3 : undefined }; const command = new GetPlaceCommand(input); return await placesClient?.send(command); @@ -56,7 +59,7 @@ const usePlaceService = () => { QueryId: isQueryId ? QueryTextOrId : undefined, BiasPosition: isQueryId ? undefined : BiasPosition, Language: isQueryId ? undefined : Language, - PoliticalView: mapPoliticalView.alpha3 || undefined + PoliticalView: isSupportedByPlaces ? alpha3 : undefined }; const command = new SearchTextCommand(input); return await placesClient?.send(command); @@ -65,7 +68,7 @@ const usePlaceService = () => { const input: ReverseGeocodeCommandInput = { QueryPosition, Language, - PoliticalView: mapPoliticalView.alpha3 || undefined + PoliticalView: isSupportedByPlaces ? alpha3 : undefined }; const command = new ReverseGeocodeCommand(input); return await placesClient?.send(command); @@ -93,7 +96,7 @@ const usePlaceService = () => { return responseBody; } }), - [BiasPosition, Language, mapPoliticalView.alpha3, placesClient] + [BiasPosition, Language, alpha3, isSupportedByPlaces, placesClient] ); }; diff --git a/src/setupTests.ts b/src/setupTests.ts index 8d76de76..fdb15872 100644 --- a/src/setupTests.ts +++ b/src/setupTests.ts @@ -109,24 +109,24 @@ jest.mock("@demo/core/constants/appConfig", () => ({ { id: "dark", name: "Dark" } ], MAP_POLITICAL_VIEWS: [ - { alpha2: "", alpha3: "", desc: "no_political_view.text" }, - { alpha2: "AR", alpha3: "ARG", desc: "argentina_political_view_desc.text" }, - { alpha2: "EG", alpha3: "EGY", desc: "egypt_political_view_desc.text" }, - { alpha2: "IN", alpha3: "IND", desc: "india_political_view_desc.text" }, - { alpha2: "KE", alpha3: "KEN", desc: "kenya_political_view_desc.text" }, - { alpha2: "MA", alpha3: "MAR", desc: "morocco_political_view_desc.text" }, - { alpha2: "RU", alpha3: "RUS", desc: "russia_political_view_desc.text" }, - { alpha2: "SD", alpha3: "SDN", desc: "sudan_political_view_desc.text" }, - { alpha2: "RS", alpha3: "SRB", desc: "serbia_political_view_desc.text" }, - { alpha2: "SR", alpha3: "SUR", desc: "suriname_political_view_desc.text" }, - { alpha2: "SY", alpha3: "SYR", desc: "syria_political_view_desc.text" }, - { alpha2: "TR", alpha3: "TUR", desc: "turkey_political_view_desc.text" }, - { alpha2: "TZ", alpha3: "TZA", desc: "tanzania_political_view_desc.text" }, - { alpha2: "UY", alpha3: "URY", desc: "uruguay_political_view_desc.text" }, - { alpha2: "GE", alpha3: "GEO", desc: "georgia_political_view_desc.text" }, - { alpha2: "CY", alpha3: "CYP", desc: "cyprus_political_view_desc.text" }, - { alpha2: "PS", alpha3: "PSE", desc: "palestine_political_view_desc.text" }, - { alpha2: "GR", alpha3: "GRC", desc: "greece_political_view_desc.text" } + { alpha2: "", alpha3: "", desc: "no_political_view.text", isSupportedByPlaces: false }, + { alpha2: "AR", alpha3: "ARG", desc: "argentina_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "EG", alpha3: "EGY", desc: "egypt_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "IN", alpha3: "IND", desc: "india_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "KE", alpha3: "KEN", desc: "kenya_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "MA", alpha3: "MAR", desc: "morocco_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "RU", alpha3: "RUS", desc: "russia_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "SD", alpha3: "SDN", desc: "sudan_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "RS", alpha3: "SRB", desc: "serbia_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "SR", alpha3: "SUR", desc: "suriname_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "SY", alpha3: "SYR", desc: "syria_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "TR", alpha3: "TUR", desc: "turkey_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "TZ", alpha3: "TZA", desc: "tanzania_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "UY", alpha3: "URY", desc: "uruguay_political_view_desc.text", isSupportedByPlaces: true }, + { alpha2: "GE", alpha3: "GEO", desc: "georgia_political_view_desc.text", isSupportedByPlaces: false }, + { alpha2: "CY", alpha3: "CYP", desc: "cyprus_political_view_desc.text", isSupportedByPlaces: false }, + { alpha2: "PS", alpha3: "PSE", desc: "palestine_political_view_desc.text", isSupportedByPlaces: false }, + { alpha2: "GR", alpha3: "GRC", desc: "greece_political_view_desc.text", isSupportedByPlaces: false } ], GEOFENCE_COLLECTION: "location.aws.com.demo.geofences.GeofenceCollection", DEVICE_ID_WEB: "web_browser_device", diff --git a/src/stores/useMapStore.ts b/src/stores/useMapStore.ts index b9020091..942ce0cf 100644 --- a/src/stores/useMapStore.ts +++ b/src/stores/useMapStore.ts @@ -31,7 +31,7 @@ interface MapStoreProps { mapUnit: MapUnitEnum; mapStyle: MapStyleEnum; mapColorScheme: MapColorSchemeEnum; - mapPoliticalView: { alpha2: string; alpha3: string; desc: string }; + mapPoliticalView: { alpha2: string; alpha3: string; desc: string; isSupportedByPlaces: boolean }; biasPosition: number[]; } @@ -47,7 +47,8 @@ const initialState: IStateProps = { mapPoliticalView: { alpha2: "", alpha3: "", - desc: "no_political_view.text" + desc: "no_political_view.text", + isSupportedByPlaces: false }, biasPosition: [US.longitude, US.latitude] }; From 0702675d5d0f65560b10cdaed05ce5d8ea2022ae Mon Sep 17 00:00:00 2001 From: Ahmad Azizi <91204996+its-aazizi@users.noreply.github.com> Date: Thu, 28 Nov 2024 10:54:24 +0500 Subject: [PATCH 4/4] added isSupportedByPlaces flag to political view --- src/atomicui/molecules/MapButtons/MapButtons.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/atomicui/molecules/MapButtons/MapButtons.tsx b/src/atomicui/molecules/MapButtons/MapButtons.tsx index c3d6cf65..ea183c9c 100644 --- a/src/atomicui/molecules/MapButtons/MapButtons.tsx +++ b/src/atomicui/molecules/MapButtons/MapButtons.tsx @@ -154,7 +154,7 @@ const MapButtons: FC = ({ if (mapStyle !== style) { onShowGridLoader(); style === MapStyleEnum.SATELLITE && - setMapPoliticalView({ alpha2: "", alpha3: "", desc: "no_political_view.text" }); + setMapPoliticalView({ alpha2: "", alpha3: "", desc: "no_political_view.text", isSupportedByPlaces: false }); setMapStyle(style); record([ {