Skip to content

Commit

Permalink
climbing: add unfinished point type (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvaclavik authored Feb 12, 2024
1 parent 24c12ea commit 91ffb81
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/components/FeaturePanel/Climbing/Editor/Points/Point.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ const PointElement = styled.circle<{ isHovered: boolean }>`

const usePointColor = (type, isHovered) => {
const config = useConfig();
const invisiblePointsForTypes = ['bolt', 'piton', 'unfinished'];

if (type === 'bolt' || type === 'piton')
if (invisiblePointsForTypes.includes(type))
return { pointColor: 'transparent', pointStroke: 'transparent' };

if (isHovered)
return {
pointColor: config.pathBorderColor,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import { useClimbingContext } from '../../contexts/ClimbingContext';
import { useConfig } from '../../config';
import { PointProps } from './pointTypes';

export const UnfinishedPoint = ({
x,
y,
isPointSelected,
onClick,
pointerEvents,
}: PointProps) => {
const { isEditMode, photoZoom } = useClimbingContext();
const config = useConfig();
const strokeWidth = 1;
const size = 12;
const dx = x - size / 2 - strokeWidth / 2;
const dy = y + size / 2 + strokeWidth / 2;
const foregroundColor = isPointSelected
? config.anchorColorSelected
: config.anchorColor;
const borderColor = isPointSelected
? config.anchorBorderColorSelected
: config.anchorBorderColor;

return (
<g
transform={`translate(${dx} ${dy}) scale(${1 / photoZoom.scale})`}
cursor={!isEditMode && 'help'}
onClick={onClick}
>
<polygon
stroke={borderColor}
fill={foregroundColor}
pointerEvents={pointerEvents}
strokeWidth={strokeWidth}
points={`0,0 ${size},0 ${size / 2},-${size}`}
>
<title>Unfinished point</title>
</polygon>
</g>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ export const RouteFloatingMenu = () => {
>
Piton
</Button>
<Button
onClick={() => {
onPointTypeChange('unfinished');
}}
>
Unfinished
</Button>
<Button
onClick={() => {
onPointTypeChange(null);
Expand Down
11 changes: 11 additions & 0 deletions src/components/FeaturePanel/Climbing/Editor/RouteMarks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Sling } from './Points/Sling';
import { useClimbingContext } from '../contexts/ClimbingContext';
import { Anchor } from './Points/Anchor';
import { ClimbingRoute } from '../types';
import { UnfinishedPoint } from './Points/UnfinishedPoint';

type Props = {
route: ClimbingRoute;
Expand Down Expand Up @@ -55,6 +56,7 @@ export const RouteMarks = ({
const isAnchorVisible = type === 'anchor';
const isSlingVisible = type === 'sling';
const isPitonVisible = type === 'piton';
const isUnfinishedPointVisible = type === 'unfinished';
const position = getPixelPosition({ x, y, units: 'percentage' });
const isActualPointSelected = isSelected && isPointSelected(index);
const pointerEvents = isSelected ? 'auto' : 'none';
Expand Down Expand Up @@ -104,6 +106,15 @@ export const RouteMarks = ({
onClick={handleClick}
/>
)}
{isUnfinishedPointVisible && (
<UnfinishedPoint
x={position.x}
y={position.y}
isPointSelected={isActualPointSelected}
pointerEvents={pointerEvents}
onClick={handleClick}
/>
)}
{isThisRouteEditOrExtendMode && (
<Point
x={position.x}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const boltCodeMap: Record<string, PointType> = {
A: 'anchor',
P: 'piton',
S: 'sling',
U: 'unfinished',
};

const parsePathString = (pathString?: string): PathPoints =>
Expand Down
2 changes: 1 addition & 1 deletion src/components/FeaturePanel/Climbing/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { gradeSystem } from './utils/gradeData';
import { Feature } from '../../../services/types';

export type PointType = 'anchor' | 'bolt' | 'piton' | 'sling';
export type PointType = 'anchor' | 'bolt' | 'piton' | 'sling' | 'unfinished';

export type Position = {
x: number;
Expand Down

0 comments on commit 91ffb81

Please sign in to comment.