Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Climbing mock points #861

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/components/FeaturePanel/Climbing/Editor/MockedPoints.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';
import { useClimbingContext } from '../contexts/ClimbingContext';
import { machine } from 'node:os';
import { PointWithType } from './PointWithType';

const data = [
{
x: 0.1,
y: 0.4,
type: 'piton',
units: 'percentage' as const,
},
{
x: 0.2,
y: 0.5,
type: 'bolt',
units: 'percentage' as const,
},
];

export const MockedPoints = () => {
const { isEditMode, getPixelPosition, mockedPoints, getMachine } =
useClimbingContext();
const machine = getMachine();

console.log('___', mockedPoints);
return (
<>
{mockedPoints.map((point) => {
const position = getPixelPosition({
x: point.x,
y: point.y,
units: 'percentage',
});

return (
<PointWithType
key={`mocked-point-${point.x}-${point.y}`}
isOtherRouteSelected={false}
isRouteSelected={true}
isPointSelected={true}
isWithOffset={isEditMode}
isPulsing={false}
onMarkedPointClick={() => {}}
x={position.x}
y={position.y}
isEditMode={isEditMode}
type={point.type}
onPointClick={() => {
console.log('___!!');
machine.execute('showPointMenu');
}}
pointIndex={0}
/>
);
})}
</>
);
};
121 changes: 0 additions & 121 deletions src/components/FeaturePanel/Climbing/Editor/PointMenu.tsx

This file was deleted.

96 changes: 96 additions & 0 deletions src/components/FeaturePanel/Climbing/Editor/PointWithType.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import React from 'react';
import { PulsedPoint } from './Points/PulsedPoint';
import { Bolt } from './Points/Bolt';
import { Piton } from './Points/Piton';
import { Sling } from './Points/Sling';
import { Anchor } from './Points/Anchor';
import { UnfinishedPoint } from './Points/UnfinishedPoint';
import { Point } from './Points/Point';

export const PointWithType = ({
onPointClick,
type,
x,
y,
isOtherRouteSelected,
isRouteSelected,
isPointSelected,
onMarkedPointClick,
isPulsing,
isEditMode,
isWithOffset,
pointIndex,
routeNumber,
}) => {
const xOffset = isWithOffset ? 15 : 0;

const isBoltVisible = !isOtherRouteSelected && type === 'bolt';
const isAnchorVisible = !isOtherRouteSelected && type === 'anchor';
const isSlingVisible = !isOtherRouteSelected && type === 'sling';
const isPitonVisible = !isOtherRouteSelected && type === 'piton';
const isUnfinishedPointVisible =
!isOtherRouteSelected && type === 'unfinished';

const pointerEvents = isRouteSelected || isEditMode ? 'auto' : 'none';
return (
<React.Fragment>
{isPulsing && <PulsedPoint x={x} y={y} />}

{isBoltVisible && (
<Bolt
x={x + xOffset}
y={y}
isPointSelected={isPointSelected}
pointerEvents={pointerEvents}
onClick={onMarkedPointClick}
/>
)}
{isPitonVisible && (
<Piton
x={x + xOffset}
y={y}
isPointSelected={isPointSelected}
pointerEvents={pointerEvents}
onClick={onMarkedPointClick}
/>
)}
{isSlingVisible && (
<Sling
x={x}
y={y}
isPointSelected={isPointSelected}
pointerEvents={pointerEvents}
onClick={onMarkedPointClick}
/>
)}
{isAnchorVisible && (
<Anchor
x={x + xOffset}
y={y}
isPointSelected={isPointSelected}
pointerEvents={pointerEvents}
onClick={onMarkedPointClick}
/>
)}
{isUnfinishedPointVisible && (
<UnfinishedPoint
x={x + xOffset}
y={y}
isPointSelected={isPointSelected}
pointerEvents={pointerEvents}
onClick={onMarkedPointClick}
/>
)}
<Point
x={x}
y={y}
type={type}
isRouteSelected={isRouteSelected}
isOtherRouteSelected={isOtherRouteSelected}
onPointInSelectedRouteClick={onPointClick}
index={pointIndex}
routeNumber={routeNumber}
/>
</React.Fragment>
);
};
27 changes: 18 additions & 9 deletions src/components/FeaturePanel/Climbing/Editor/Points/Point.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,27 @@ const usePointColor = (type, isHovered) => {
};
};

type PointType = {
x: number;
y: number;
onPointInSelectedRouteClick: (e: any) => void;
type: any;
index: number;
routeNumber?: number;
isRouteSelected: boolean;
isOtherRouteSelected: boolean;
};

export const Point = ({
x,
y,
onPointInSelectedRouteClick,
type,
index,
routeNumber,
}) => {
isRouteSelected,
isOtherRouteSelected,
}: PointType) => {
const [isHovered, setIsHovered] = useState(false);
const {
setPointSelectedIndex,
Expand All @@ -61,17 +74,13 @@ export const Point = ({
photoZoom,
getCurrentPath,
setIsPanningDisabled,
isRouteSelected,
isPointSelected,
isOtherRouteSelected,
isEditMode,
} = useClimbingContext();
const isMobileMode = useMobileMode();
const isSelected = isRouteSelected(routeNumber);
const isOtherSelected = isOtherRouteSelected(routeNumber);
const { pointColor, pointStroke } = usePointColor(type, isHovered);

const isPointOnRouteSelected = isSelected && isPointSelected(index);
const isPointOnRouteSelected = isRouteSelected && isPointSelected(index);

const onPointClick = (e) => {
e.stopPropagation();
Expand All @@ -80,7 +89,7 @@ export const Point = ({
const onPointMouseEnter = () => {
setIsHovered(true);
const isLastPoint = getCurrentPath().length - 1 === index;
if (!isLastPoint) {
if (!isLastPoint && routeNumber) {
setRouteIndexHovered(routeNumber);
}
};
Expand Down Expand Up @@ -130,13 +139,13 @@ export const Point = ({
};
const title = type && <title>{type}</title>;

if (isOtherSelected && isEditMode)
if (isOtherRouteSelected && isEditMode)
return (
<g transform={`translate(${x},${y}) scale(${1 / photoZoom.scale})`}>
<circle cx={0} cy={0} r={2.5 * photoZoom.scale} fill="white" />
</g>
);
if (!isSelected || !isEditMode) return null;
if (!isRouteSelected || !isEditMode) return null;

return (
<g transform={`translate(${x},${y}) scale(${1 / photoZoom.scale})`}>
Expand Down
Loading
Loading