Skip to content

Commit

Permalink
Publictransport: Enable member fetching for route masters (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dlurak authored Oct 8, 2024
1 parent 2bc6b98 commit d821f17
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 22 deletions.
50 changes: 34 additions & 16 deletions src/components/FeaturePanel/MemberFeatures/MemberFeatures.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
import React from 'react';
import { Box } from '@mui/material';
import { getOsmappLink, getShortId } from '../../../services/helpers';
import { getOsmappLink } from '../../../services/helpers';
import { useFeatureContext } from '../../utils/FeatureContext';
import { PanelLabel } from '../Climbing/PanelLabel';
import { Item } from './Item';
import { ClimbingItem } from './ClimbingItem';
import styled from '@emotion/styled';
import { GradeSystemSelect } from '../Climbing/GradeSystemSelect';
import { useUserSettingsContext } from '../../utils/UserSettingsContext';
import { RouteDistributionInPanel } from '../Climbing/RouteDistribution';
import { Feature } from '../../../services/types';
import { isRouteMaster } from '../../../utils';
import { t } from '../../../services/intl';

const getHeading = (feature: Feature) => {
if (feature.tags.climbing === 'crag') {
return t('member_features.climbing');
}
if (isRouteMaster(feature)) {
return t('member_features.routes');
}
return t('member_features.subitems');
};

const PanelAddition = () => {
const { feature } = useFeatureContext();
const { userSettings, setUserSetting } = useUserSettingsContext();

if (feature.tags.climbing !== 'crag') {
return null;
}

return (
<GradeSystemSelect
setGradeSystem={(system) => {
setUserSetting('climbing.gradeSystem', system);
}}
selectedGradeSystem={userSettings['climbing.gradeSystem']}
/>
);
};

const Ul = styled.ul`
padding: 0;
Expand All @@ -19,8 +49,6 @@ export const MemberFeatures = () => {
const { feature } = useFeatureContext();
const { memberFeatures, tags } = feature;

const { userSettings, setUserSetting } = useUserSettingsContext();

if (!memberFeatures?.length) {
return null;
}
Expand All @@ -31,21 +59,11 @@ export const MemberFeatures = () => {
}

const isClimbingCrag = tags.climbing === 'crag';
const heading = isClimbingCrag ? 'Climbing routes' : 'Subitems';

return (
<Box mb={1}>
<PanelLabel
addition={
<GradeSystemSelect
setGradeSystem={(system) => {
setUserSetting('climbing.gradeSystem', system);
}}
selectedGradeSystem={userSettings['climbing.gradeSystem']}
/>
}
>
{heading} ({memberFeatures.length})
<PanelLabel addition={<PanelAddition />}>
{getHeading(feature)} ({memberFeatures.length})
</PanelLabel>
<Ul>
{memberFeatures.map((item, index) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ const LineNumberWrapper = styled(Link)<{
`;

type Tags = Record<string, string>;
const formatTooltip = (tags: Tags, routes: { tags: Tags }[]) => {
const formatTags = (tags: Tags) => {
const parts = [tags.from, ...(tags.via ? [tags.via] : []), tags.to];
return parts.flatMap((str) => str.split(';')).join(' - ');
};

const formatTags = (tags: Tags) => {
const parts = [tags.from, ...(tags.via ? [tags.via] : []), tags.to];
return parts.flatMap((str) => str.split(';')).join(' - ');
};

const formatTooltip = (tags: Tags, routes: { tags: Tags }[]) => {
if (tags.from && tags.to) {
return formatTags(tags);
}
Expand Down
4 changes: 4 additions & 0 deletions src/locales/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,8 @@ export default {
'runway.runway': 'Landebahn',
'runway.size': 'Länge (m) - Breite (m)',
'runway.surface': 'Oberfläche',

'member_features.subitems': 'Subelemente',
'member_features.climbing': 'Kletter Strecken',
'member_features.routes': 'Strecken',
};
4 changes: 4 additions & 0 deletions src/locales/vocabulary.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,8 @@ export default {
'climbingareas.title': 'Climbing areas',
'climbingareas.area': 'Area',
'climbingareas.num_of_crags': 'Number of crags',

'member_features.subitems': 'Subitems',
'member_features.climbing': 'Climbing routes',
'member_features.routes': 'Routes',
};
7 changes: 6 additions & 1 deletion src/services/osmApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
isClimbingRelation,
isClimbingRoute,
isPublictransportRoute,
isRouteMaster,
} from '../utils';
import { getOverpassUrl } from './overpassSearch';

Expand Down Expand Up @@ -228,7 +229,11 @@ export const addMembersAndParents = async (
return { ...feature, parentFeatures };
}

if (isClimbingRelation(feature) || isPublictransportRoute(feature)) {
if (
isClimbingRelation(feature) ||
isPublictransportRoute(feature) ||
isRouteMaster(feature)
) {
const [parentFeatures, featureWithMemberFeatures] = await Promise.all([
fetchParentFeatures(feature.osmMeta),
addMemberFeaturesToRelation(feature),
Expand Down
3 changes: 3 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export const isClimbingRelation = (feature: Feature) =>
export const isClimbingRoute = (feature: Feature) =>
['route_bottom', 'route_top', 'route'].includes(feature?.tags.climbing);

export const isRouteMaster = ({ tags, osmMeta }: Feature) =>
tags.type === 'route_master' && osmMeta.type === 'relation';

export const isPublictransportStop = ({ tags }: Feature) =>
Object.keys(tags).includes('public_transport') ||
tags.railway === 'station' ||
Expand Down

0 comments on commit d821f17

Please sign in to comment.