Skip to content

Commit

Permalink
climbing: Save other tags (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvaclavik authored May 31, 2024
1 parent 514205e commit 364aec6
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 44 deletions.
84 changes: 42 additions & 42 deletions src/components/FeaturePanel/Climbing/RouteList/ExpandedRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,28 @@ export const ExpandedRow = ({
<Flex>
<Left>
<List>
{tempRoute.description && (
<ListItem>
{isReadOnly ? (
<div>
<Label>Description</Label>
<Value>{getText(tempRoute.description)}</Value>
</div>
) : (
<TextField
size="small"
value={tempRoute.description}
onChange={(e) => onTempRouteChange(e, 'description')}
onClick={stopPropagation}
style={{ marginTop: 10 }}
variant="outlined"
label="Description"
fullWidth
multiline
/>
)}
</ListItem>
)}
<ListItem>
{isReadOnly && tempRoute.description && (
<div>
<Label>Description</Label>
<Value>{getText(tempRoute.description)}</Value>
</div>
)}
{isEditMode && (
<TextField
size="small"
value={tempRoute.description}
onChange={(e) => onTempRouteChange(e, 'description')}
onClick={stopPropagation}
style={{ marginTop: 10 }}
variant="outlined"
label="Description"
fullWidth
multiline
/>
)}
</ListItem>

<ListItem>
<RouteInDifferentPhotos
route={tempRoute}
Expand Down Expand Up @@ -150,26 +150,26 @@ export const ExpandedRow = ({
)}
</ListItem>
)}
{tempRoute.author && (
<ListItem>
{isReadOnly ? (
<div>
<Label>Author</Label>
<Value>{getText(tempRoute.author)}</Value>
</div>
) : (
<TextField
size="small"
value={tempRoute.author}
onChange={(e) => onTempRouteChange(e, 'author')}
onClick={stopPropagation}
style={{ marginTop: 10 }}
variant="outlined"
label="Author"
/>
)}
</ListItem>
)}

<ListItem>
{isReadOnly && tempRoute.author && (
<div>
<Label>Author</Label>
<Value>{getText(tempRoute.author)}</Value>
</div>
)}
{isEditMode && (
<TextField
size="small"
value={tempRoute.author}
onChange={(e) => onTempRouteChange(e, 'author')}
onClick={stopPropagation}
style={{ marginTop: 10 }}
variant="outlined"
label="Author"
/>
)}
</ListItem>
<ListItem>
{tempRoute.feature ? (
<Button
Expand Down
31 changes: 29 additions & 2 deletions src/components/FeaturePanel/Climbing/useGetHandleSave.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useClimbingContext } from './contexts/ClimbingContext';
import { Change, editCrag } from '../../../services/osmApiAuth';
import { invertedBoltCodeMap } from './utils/boltCodes';
import { getFeaturePhotoKeys } from './utils/photo';
import { getOsmTagFromGradeSystem } from './utils/routeGrade';

const WIKIMEDIA_COMMONS = 'wikimedia_commons';

Expand Down Expand Up @@ -42,7 +43,30 @@ const getNewPhotoKey = (photoIndex: number, offset: number) => {
}`;
};

const getUpdatedTags = (route: ClimbingRoute) => {
const getUpdatedBasicTags = (route: ClimbingRoute) => {
const checkedTags = ['name', 'description', 'author'];
const updatedTags = {};
checkedTags.forEach((tagToCheck) => {
if (route[tagToCheck] !== route.feature.tags[tagToCheck]) {
updatedTags[tagToCheck] = route[tagToCheck];
}
});

const newGradeSystem = route.difficulty.gradeSystem;
const gradeSystemKey = getOsmTagFromGradeSystem(newGradeSystem);
const featureDifficulty = route.feature.tags[gradeSystemKey];

const isGradeUpdated = route.difficulty.grade !== featureDifficulty;

if (isGradeUpdated) {
updatedTags[gradeSystemKey] = route.difficulty.grade;
// @TODO: delete previous grade? if(!featureDifficulty)
}

return updatedTags;
};

const getUpdatedPhotoTags = (route: ClimbingRoute) => {
const updatedTags = {};
const photoKeys = getFeaturePhotoKeys(route.feature);
const newPhotoIndex = getNewPhotoIndex(photoKeys);
Expand Down Expand Up @@ -74,7 +98,10 @@ const getChanges = (routes: ClimbingRoute[]): Change[] => {

return existingRoutes
.map((route) => {
const updatedTags = getUpdatedTags(route);
const updatedTags = {
...getUpdatedBasicTags(route),
...getUpdatedPhotoTags(route),
};
const isSame = isSameTags(updatedTags, route.feature.tags);
return isSame
? undefined
Expand Down
3 changes: 3 additions & 0 deletions src/components/FeaturePanel/Climbing/utils/routeGrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,6 @@ export const getRouteGrade = (

export const getGradeSystemName = (gradeSystemKey: GradeSystem) =>
gradeSystem.find((item) => item.key === gradeSystemKey)?.name;

export const getOsmTagFromGradeSystem = (gradeSystemKey: GradeSystem) =>
`climbing:grade:${gradeSystemKey}`;

0 comments on commit 364aec6

Please sign in to comment.