Skip to content

Commit

Permalink
refactor: refactor transport mode to a module
Browse files Browse the repository at this point in the history
  • Loading branch information
adriansberg committed Nov 13, 2023
1 parent 145ebf9 commit ede4246
Show file tree
Hide file tree
Showing 47 changed files with 416 additions and 268 deletions.
10 changes: 4 additions & 6 deletions src/components/line-chip/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Typo } from '@atb/components/typography';
import style from './line-chip.module.css';
import {
TransportIcon,
useTransportationThemeColor,
} from '@atb/components/transport-mode/transport-icon';
import {
TransportModeType,
TransportSubmodeType,
} from '@atb/components/transport-mode/types';
import { Typo } from '@atb/components/typography';
import style from './line-chip.module.css';
useTransportationThemeColor,
} from '@atb/modules/transport-mode';

export type LineChipProps = {
transportMode: TransportModeType;
Expand Down
9 changes: 5 additions & 4 deletions src/components/map/map-header.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import style from './map.module.css';

import { ButtonLink } from '@atb/components/button';
import { ComponentText, useTranslation } from '@atb/translations';
import { and } from '@atb/utils/css';
import { MonoIcon } from '@atb/components/icon';
import { transportModeToTranslatedString } from '@atb/components/transport-mode';
import { getTransportModeIcon } from '@atb/components/transport-mode/transport-icon';
import { TransportModeType } from '@atb/components/transport-mode/types';
import {
type TransportModeType,
transportModeToTranslatedString,
getTransportModeIcon,
} from '@atb/modules/transport-mode';

export type MapHeaderProps = {
id: string;
Expand Down
3 changes: 3 additions & 0 deletions src/components/search/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default } from './search';
export { default as GeolocationButton } from './geolocation-button';
export { default as SwapButton } from './swap-button';
File renamed without changes.
17 changes: 0 additions & 17 deletions src/components/transport-mode-filter/types.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/components/transport-mode/index.ts

This file was deleted.

29 changes: 0 additions & 29 deletions src/components/transport-mode/types.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/components/transport-mode/utils.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/modules/search-time/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export { default as SearchTimeSelector } from './selector';

export * from './types';

export { parseSearchTimeQuery, searchTimeToQueryString } from './utils';
6 changes: 6 additions & 0 deletions src/modules/search-time/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ export function parseSearchTimeQuery(

return { mode: 'now' };
}

export function searchTimeToQueryString(searchTime: SearchTime) {
return searchTime.mode !== 'now'
? { searchMode: searchTime.mode, searchTime: searchTime.dateTime }
: { searchMode: searchTime.mode };
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { cleanup, render, screen } from '@testing-library/react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import TransportModeFilter from '@atb/components/transport-mode-filter';
import { getInitialTransportModeFilter } from '@atb/components/transport-mode-filter/utils';
import userEvent from '@testing-library/user-event';
import { TransportModeFilterState } from '@atb/components/transport-mode-filter/types';
import TransportModeFilter from '../filter';
import { getInitialTransportModeFilter } from '../utils';
import { TransportModeFilterState } from '../types';

afterEach(() => cleanup());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { getTextForLanguage } from '@atb/translations/utils';
import { useTranslation, ComponentText } from '@atb/translations';
import style from './transport-mode-filter.module.css';
import style from './filter.module.css';
import { MonoIcon } from '@atb/components/icon';
import {
TransportModeFilterOption,
TransportModeFilterState,
} from '@atb/components/transport-mode-filter/types';
import { TransportModeFilterOption, TransportModeFilterState } from './types';
import { Typo } from '@atb/components/typography';
import { getTransportModeIcon } from '@atb/components/transport-mode/transport-icon';
import {
filterOptionsWithTransportModes,
setAllValues,
} from '@atb/components/transport-mode-filter/utils';
import { getTransportModeIcon } from '../icon';
import { filterOptionsWithTransportModes, setAllValues } from './utils';

type TransportModeFilterProps = {
filterState: TransportModeFilterState;
Expand Down
13 changes: 13 additions & 0 deletions src/modules/transport-mode/filter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export { default as TransportModeFilter } from './filter';

export {
type TransportModeFilterOption,
type TransportModeFilterState,
} from './types';

export {
getAllTransportModesFromFilterOptions,
getInitialTransportModeFilter,
parseFilterQuery,
filterToQueryString,
} from './utils';
22 changes: 22 additions & 0 deletions src/modules/transport-mode/filter/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { z } from 'zod';

export const transportModeFilterSchema = z.union([
z.literal('bus'),
z.literal('rail'),
z.literal('expressboat'),
z.literal('ferry'),
z.literal('airportbus'),
z.literal('air'),
z.literal('other'),
]);

export type TransportModeFilterOption = z.infer<
typeof transportModeFilterSchema
>;

export type TransportModeFilterState = Record<
TransportModeFilterOption,
boolean
>;

export { TransportModeFilterOptionType } from '@atb-as/config-specs';
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { uniq } from 'lodash';
import {
TransportModeFilterOption,
transportModeFilterOptions,
TransportModeFilterState,
} from '@atb/components/transport-mode-filter/types';
import {
TransportModeFilterOptionType,
TransportModeType,
} from '@atb-as/config-specs';
import { uniq } from 'lodash';
TransportModeFilterState,
} from './types';
import { TransportModeType } from '../types';

const transportModeFilterOptions: TransportModeFilterOption[] = [
'bus',
'rail',
'expressboat',
'ferry',
'airportbus',
'air',
'other',
];

export function getInitialTransportModeFilter(
initialSelected?: TransportModeFilterOption[] | null,
Expand Down Expand Up @@ -50,8 +57,10 @@ export function parseFilterQuery(
}

export function getAllTransportModesFromFilterOptions(
filterOptions: TransportModeFilterOption[],
filterOptions: TransportModeFilterOption[] | null,
): TransportModeType[] {
if (!filterOptions) return [];

const transportModes: TransportModeType[] = [];

filterOptions.forEach((filterOption) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
.transportIcons {
display: flex;

/* Specialized sizing. */
/* @TODO investigate generic way to handle this */
gap: 0.125rem;
}

.transportIcon,
.transportIconWithLabel {
display: inline-block;

/* Specialized sizing. */
/* @TODO investigate generic way to handle this */
border-radius: var(--border-radius-small);
padding: var(--spacings-xSmall);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useTheme } from '@atb/modules/theme';

import { useTranslation } from '@atb/translations';
import { transportModeToTranslatedString } from '../utils';
import style from './transport-icon.module.css';
import style from './icon.module.css';
import { colorToOverrideMode } from '@atb/utils/color';

export type TransportIconsProps = {
Expand Down
18 changes: 18 additions & 0 deletions src/modules/transport-mode/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export {
type TransportModeType,
type TransportSubmodeType,
type TransportModeGroup,
transportModeSchema,
transportSubmodeSchema,
} from './types';

export {
transportModeToTranslatedString,
severalTransportModesToTranslatedStrings,
isTransportModeType,
isTransportSubmodeType,
filterGraphQlTransportModes,
} from './utils';

export * from './icon';
export * from './filter';
Loading

0 comments on commit ede4246

Please sign in to comment.