From d821f17c9ce2c152f2cad0b505bb44b37250f3ce Mon Sep 17 00:00:00 2001 From: Dlurak <84224239+Dlurak@users.noreply.github.com> Date: Tue, 8 Oct 2024 14:04:54 +0200 Subject: [PATCH] Publictransport: Enable member fetching for route masters (#647) --- .../MemberFeatures/MemberFeatures.tsx | 50 +++++++++++++------ .../PublicTransport/routes/LineNumber.tsx | 11 ++-- src/locales/de.js | 4 ++ src/locales/vocabulary.js | 4 ++ src/services/osmApi.ts | 7 ++- src/utils.ts | 3 ++ 6 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/components/FeaturePanel/MemberFeatures/MemberFeatures.tsx b/src/components/FeaturePanel/MemberFeatures/MemberFeatures.tsx index 25ee7b5ba..3eb37e18b 100644 --- a/src/components/FeaturePanel/MemberFeatures/MemberFeatures.tsx +++ b/src/components/FeaturePanel/MemberFeatures/MemberFeatures.tsx @@ -1,6 +1,6 @@ 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'; @@ -8,7 +8,37 @@ 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 ( + { + setUserSetting('climbing.gradeSystem', system); + }} + selectedGradeSystem={userSettings['climbing.gradeSystem']} + /> + ); +}; const Ul = styled.ul` padding: 0; @@ -19,8 +49,6 @@ export const MemberFeatures = () => { const { feature } = useFeatureContext(); const { memberFeatures, tags } = feature; - const { userSettings, setUserSetting } = useUserSettingsContext(); - if (!memberFeatures?.length) { return null; } @@ -31,21 +59,11 @@ export const MemberFeatures = () => { } const isClimbingCrag = tags.climbing === 'crag'; - const heading = isClimbingCrag ? 'Climbing routes' : 'Subitems'; return ( - { - setUserSetting('climbing.gradeSystem', system); - }} - selectedGradeSystem={userSettings['climbing.gradeSystem']} - /> - } - > - {heading} ({memberFeatures.length}) + }> + {getHeading(feature)} ({memberFeatures.length})
    {memberFeatures.map((item, index) => diff --git a/src/components/FeaturePanel/PublicTransport/routes/LineNumber.tsx b/src/components/FeaturePanel/PublicTransport/routes/LineNumber.tsx index f686eb9e0..6148a172c 100644 --- a/src/components/FeaturePanel/PublicTransport/routes/LineNumber.tsx +++ b/src/components/FeaturePanel/PublicTransport/routes/LineNumber.tsx @@ -25,12 +25,13 @@ const LineNumberWrapper = styled(Link)<{ `; type Tags = Record; -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); } diff --git a/src/locales/de.js b/src/locales/de.js index 9313c123b..e0bb3ba1c 100644 --- a/src/locales/de.js +++ b/src/locales/de.js @@ -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', }; diff --git a/src/locales/vocabulary.js b/src/locales/vocabulary.js index 92a497020..10b19d0c8 100644 --- a/src/locales/vocabulary.js +++ b/src/locales/vocabulary.js @@ -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', }; diff --git a/src/services/osmApi.ts b/src/services/osmApi.ts index 435243665..77ac1fa9b 100644 --- a/src/services/osmApi.ts +++ b/src/services/osmApi.ts @@ -15,6 +15,7 @@ import { isClimbingRelation, isClimbingRoute, isPublictransportRoute, + isRouteMaster, } from '../utils'; import { getOverpassUrl } from './overpassSearch'; @@ -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), diff --git a/src/utils.ts b/src/utils.ts index 85611919b..6fad6c6be 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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' ||