diff --git a/src/components/FeaturePanel/Climbing/Editor/MockedPoints.tsx b/src/components/FeaturePanel/Climbing/Editor/MockedPoints.tsx new file mode 100644 index 000000000..7915c5775 --- /dev/null +++ b/src/components/FeaturePanel/Climbing/Editor/MockedPoints.tsx @@ -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 ( + {}} + x={position.x} + y={position.y} + isEditMode={isEditMode} + type={point.type} + onPointClick={() => { + console.log('___!!'); + machine.execute('showPointMenu'); + }} + pointIndex={0} + /> + ); + })} + + ); +}; diff --git a/src/components/FeaturePanel/Climbing/Editor/PointMenu.tsx b/src/components/FeaturePanel/Climbing/Editor/PointMenu.tsx deleted file mode 100644 index 207646354..000000000 --- a/src/components/FeaturePanel/Climbing/Editor/PointMenu.tsx +++ /dev/null @@ -1,121 +0,0 @@ -import React from 'react'; - -import RemoveCircleIcon from '@mui/icons-material/RemoveCircle'; -import CloseIcon from '@mui/icons-material/Close'; -import CheckIcon from '@mui/icons-material/Check'; -import DeleteIcon from '@mui/icons-material/Delete'; -import { - Popover, - DialogTitle, - MenuList, - MenuItem, - ListItemIcon, - Typography, - Divider, -} from '@mui/material'; -import { PointType } from '../types'; -import { useClimbingContext } from '../contexts/ClimbingContext'; - -export const PointMenu = ({ anchorEl, setAnchorEl }) => { - const { - pointSelectedIndex, - setPointSelectedIndex, - getMachine, - isPointMoving, - getCurrentPath, - } = useClimbingContext(); - const machine = getMachine(); - const open = Boolean(anchorEl) && !isPointMoving; - const id = open ? 'simple-popper' : undefined; - const selectedPoint = getCurrentPath()[pointSelectedIndex]; - - if (!selectedPoint) return null; - - const onPopoverClose = () => { - setAnchorEl(null); - setPointSelectedIndex(null); - }; - const onDeletePoint = () => { - machine.execute('deletePoint'); - }; - - const onPointTypeChange = (type: PointType) => { - machine.execute('changePointType', { type }); - - onPopoverClose(); - }; - - return ( - { - machine.execute('cancelPointMenu'); - onPopoverClose(); - }} - > - Choose point type - - - onPointTypeChange(null)} - selected={!selectedPoint.type} - > - - Nothing - - onPointTypeChange('bolt')} - selected={selectedPoint.type === 'bolt'} - > - - - - - Bolt / Ring / Hanger - - - onPointTypeChange('anchor')} - selected={selectedPoint.type === 'anchor'} - > - - - - Belay - - - - - - - - Delete point - - - { - onPopoverClose(); - machine.execute('finishRoute'); - }} - > - - - - - Finish editing - - - - - ); -}; diff --git a/src/components/FeaturePanel/Climbing/Editor/PointWithType.tsx b/src/components/FeaturePanel/Climbing/Editor/PointWithType.tsx new file mode 100644 index 000000000..3b558136e --- /dev/null +++ b/src/components/FeaturePanel/Climbing/Editor/PointWithType.tsx @@ -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 ( + + {isPulsing && } + + {isBoltVisible && ( + + )} + {isPitonVisible && ( + + )} + {isSlingVisible && ( + + )} + {isAnchorVisible && ( + + )} + {isUnfinishedPointVisible && ( + + )} + + + ); +}; diff --git a/src/components/FeaturePanel/Climbing/Editor/Points/Point.tsx b/src/components/FeaturePanel/Climbing/Editor/Points/Point.tsx index 9daa38196..268ac11cc 100644 --- a/src/components/FeaturePanel/Climbing/Editor/Points/Point.tsx +++ b/src/components/FeaturePanel/Climbing/Editor/Points/Point.tsx @@ -41,6 +41,17 @@ 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, @@ -48,7 +59,9 @@ export const Point = ({ type, index, routeNumber, -}) => { + isRouteSelected, + isOtherRouteSelected, +}: PointType) => { const [isHovered, setIsHovered] = useState(false); const { setPointSelectedIndex, @@ -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(); @@ -80,7 +89,7 @@ export const Point = ({ const onPointMouseEnter = () => { setIsHovered(true); const isLastPoint = getCurrentPath().length - 1 === index; - if (!isLastPoint) { + if (!isLastPoint && routeNumber) { setRouteIndexHovered(routeNumber); } }; @@ -130,13 +139,13 @@ export const Point = ({ }; const title = type && {type}; - if (isOtherSelected && isEditMode) + if (isOtherRouteSelected && isEditMode) return ( ); - if (!isSelected || !isEditMode) return null; + if (!isRouteSelected || !isEditMode) return null; return ( diff --git a/src/components/FeaturePanel/Climbing/Editor/RouteFloatingMenu.tsx b/src/components/FeaturePanel/Climbing/Editor/RouteFloatingMenu.tsx index f913213d3..cd1f78961 100644 --- a/src/components/FeaturePanel/Climbing/Editor/RouteFloatingMenu.tsx +++ b/src/components/FeaturePanel/Climbing/Editor/RouteFloatingMenu.tsx @@ -42,6 +42,7 @@ export const RouteFloatingMenu = () => { routeSelectedIndex, getCurrentPath, setRouteIndexHovered, + isEditMode, } = useClimbingContext(); const path = getCurrentPath(); const machine = getMachine(); @@ -51,6 +52,8 @@ export const RouteFloatingMenu = () => { routes[routeSelectedIndex] && pointSelectedIndex === getCurrentPath().length - 1) || machine.currentStateName === 'editRoute'; + + const areCragPointsVisible = isEditMode; const isDoneVisible = machine.currentStateName === 'extendRoute'; const isUndoVisible = machine.currentStateName === 'extendRoute' && path.length !== 0; @@ -61,6 +64,15 @@ export const RouteFloatingMenu = () => { const onContinueClimbingRouteClick = useCallback(() => { machine.execute('extendRoute'); }, [machine]); + + const onMockPointsClick = useCallback(() => { + machine.execute('mockPoints'); + }, [machine]); + + const onMockPointsFinish = () => { + machine.execute('editRoute'); + }; + const onDeletePoint = () => { machine.execute('deletePoint'); setIsDeletePointDialogVisible(false); @@ -72,11 +84,16 @@ export const RouteFloatingMenu = () => { const onPointTypeChange = useCallback( (type: PointType) => { - machine.execute('changePointType', { type }); + // @TODO tady upravit aby se tam posílalo routeSelectedIndex=undefined a pointSelectedIndex podle indexu v mockedPoints. Zároveň bude potřeba sem předat informaci který index měním. Možná v climbing contextu? + machine.execute('changePointType', { + type, + routeSelectedIndex, + pointSelectedIndex, + }); setShowRouteMarksMenu(false); }, - [machine], + [machine, routeSelectedIndex, pointSelectedIndex], ); const onMouseEnter = () => { @@ -117,6 +134,9 @@ export const RouteFloatingMenu = () => { if (e.key === 'e') { onContinueClimbingRouteClick(); } + if (e.key === 'm') { + onMockPointsClick(); + } if (isUndoVisible && e.key === 'z' && e.metaKey) { handleUndo(e); } @@ -136,6 +156,7 @@ export const RouteFloatingMenu = () => { isUndoVisible, onContinueClimbingRouteClick, onFinishClimbingRouteClick, + onMockPointsClick, onPointTypeChange, ]); @@ -236,6 +257,14 @@ export const RouteFloatingMenu = () => { Extend )} + {areCragPointsVisible && + (machine.currentStateName === 'mockPoints' ? ( + + ) : ( + + ))} {machine.currentStateName === 'pointMenu' && (