From 88d5f96968b41229207876bf5d3f5eeac99ccb1a Mon Sep 17 00:00:00 2001 From: Morten Nordseth <43166974+mortennordseth@users.noreply.github.com> Date: Mon, 9 Oct 2023 14:26:44 +0200 Subject: [PATCH] refactor: map header icons and text (#33) * refactor: map header icons and text * fix: tests and imports * refactor: map header importance to 2 * Update src/components/map/map-header.tsx Co-authored-by: Mikael Brevik --------- Co-authored-by: Mikael Brevik --- src/components/map/__tests__/map.test.tsx | 7 +-- src/components/map/map-header.tsx | 58 +++++++++---------- src/components/map/map.module.css | 5 +- .../transport-mode/transport-icon/index.tsx | 4 +- .../departures/nearest-stop-places/index.tsx | 1 - .../departures/stop-place/index.tsx | 1 + 6 files changed, 34 insertions(+), 42 deletions(-) diff --git a/src/components/map/__tests__/map.test.tsx b/src/components/map/__tests__/map.test.tsx index cd5ab542..35fb86f3 100644 --- a/src/components/map/__tests__/map.test.tsx +++ b/src/components/map/__tests__/map.test.tsx @@ -2,14 +2,13 @@ import { cleanup, render } from '@testing-library/react'; import { afterEach, describe, expect, it } from 'vitest'; import { MapHeader } from '@atb/components/map'; import { MapHeaderProps } from '@atb/components/map/map-header'; -import { FeatureCategory } from '@atb/components/venue-icon'; +import { TransportMode } from '@atb/components/transport-mode/types'; const stopPlaceMock: MapHeaderProps = { layer: 'venue', name: 'Trondheim S', id: 'NSR:StopPlace:41742', - street: 'Fosenkaia', - category: [FeatureCategory.ONSTREET_BUS], + transportModes: [TransportMode.BUS], }; const addressMock: MapHeaderProps = { @@ -41,7 +40,7 @@ describe('MapHeader', function () { const output = render( , ); expect(output.getByAltText('Buss')).toBeInTheDocument(); diff --git a/src/components/map/map-header.tsx b/src/components/map/map-header.tsx index 5493ef37..18d5d6e7 100644 --- a/src/components/map/map-header.tsx +++ b/src/components/map/map-header.tsx @@ -2,61 +2,55 @@ import style from './map.module.css'; import { ButtonLink } from '@atb/components/button'; import { ComponentText, useTranslation } from '@atb/translations'; -import VenueIcon, { FeatureCategory } from '@atb/components/venue-icon'; import { and } from '@atb/utils/css'; import { MonoIcon } from '@atb/components/icon'; +import { TransportMode } from '@atb/components/transport-mode/types'; +import { transportModeToTranslatedString } from '@atb/components/transport-mode'; +import { getTransportModeIcon } from '@atb/components/transport-mode/transport-icon'; export type MapHeaderProps = { id: string; name: string; // StopPlace name or address layer: 'address' | 'venue'; - street?: string; - category?: FeatureCategory[]; + transportModes?: TransportMode[]; }; -export function MapHeader({ - id, - name, - layer, - street, - category, -}: MapHeaderProps) { +export function MapHeader({ id, name, layer, transportModes }: MapHeaderProps) { const { t } = useTranslation(); return (
- {layer === 'address' || !category ? ( + {layer === 'address' || !transportModes ? (
) : ( - category.map((type) => ( -
- + transportModes.map((mode) => ( +
+
)) )}
-

- {name} -

-

- {layer === 'venue' - ? t(ComponentText.Map.header.venue(street || '?')) // @TODO: better types - : t(ComponentText.Map.header.address)} -

+ {layer === 'address' && ( +

+ {t(ComponentText.Map.header.address)} +

+ )} +

{name}

diff --git a/src/components/map/map.module.css b/src/components/map/map.module.css index 7435015b..3e7333ab 100644 --- a/src/components/map/map.module.css +++ b/src/components/map/map.module.css @@ -32,16 +32,13 @@ .header__info { display: flex; flex-direction: column; + justify-content: center; } .header__info__secondary { color: var(--text-colors-secondary); } -.flexOrder__2 { - order: 2; -} - .header__buttons { display: flex; gap: var(--spacings-medium); diff --git a/src/components/transport-mode/transport-icon/index.tsx b/src/components/transport-mode/transport-icon/index.tsx index 7abc5356..7adb1018 100644 --- a/src/components/transport-mode/transport-icon/index.tsx +++ b/src/components/transport-mode/transport-icon/index.tsx @@ -99,7 +99,9 @@ function modeToColor( } } -function getTransportModeIcon(mode: TransportModeGroup): MonoIconProps['icon'] { +export function getTransportModeIcon( + mode: TransportModeGroup, +): MonoIconProps['icon'] { switch (mode.mode) { case 'bus': case 'coach': diff --git a/src/page-modules/departures/nearest-stop-places/index.tsx b/src/page-modules/departures/nearest-stop-places/index.tsx index 233cac2c..a632caf2 100644 --- a/src/page-modules/departures/nearest-stop-places/index.tsx +++ b/src/page-modules/departures/nearest-stop-places/index.tsx @@ -30,7 +30,6 @@ export function NearestStopPlaces({ id={activeLocation.id} name={activeLocation.name} layer="address" - street={activeLocation.street} position={[ activeLocation.geometry.coordinates[0], activeLocation.geometry.coordinates[1], diff --git a/src/page-modules/departures/stop-place/index.tsx b/src/page-modules/departures/stop-place/index.tsx index c7c004ea..a95c0d2a 100644 --- a/src/page-modules/departures/stop-place/index.tsx +++ b/src/page-modules/departures/stop-place/index.tsx @@ -36,6 +36,7 @@ export function StopPlace({ departures }: StopPlaceProps) { ]} layer="venue" onSelectStopPlace={(id) => router.push(`/departures/${id}`)} + transportModes={departures.stopPlace.transportMode} />