Skip to content

Commit

Permalink
climbing: Hovered lines on top (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvaclavik authored Mar 25, 2024
1 parent d951538 commit c5b2144
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 20 deletions.
31 changes: 18 additions & 13 deletions src/components/FeaturePanel/Climbing/Editor/PathWithBorder.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable react/jsx-props-no-spreading */
import React from 'react';
import styled from 'styled-components';
import { useTheme } from '@material-ui/core';
import { useConfig } from '../config';
import { useClimbingContext } from '../contexts/ClimbingContext';
import { getDifficultyColor } from '../utils/routeGrade';
Expand All @@ -22,9 +23,7 @@ export const PathWithBorder = ({
const config = useConfig();
const { isDifficultyHeatmapEnabled, gradeTable, routeIndexHovered } =
useClimbingContext();
const borderColor = isDifficultyHeatmapEnabled
? config.pathStrokeColor
: config.pathBorderColor;

const strokeColor = isDifficultyHeatmapEnabled
? getDifficultyColor(gradeTable, route.difficulty)
: config.pathStrokeColor;
Expand All @@ -33,26 +32,21 @@ export const PathWithBorder = ({
if (isSelected) {
return config.pathStrokeColorSelected;
}
if (routeIndexHovered === routeNumber) {
return config.pathStrokeColorSelected;
}

return strokeColor;
};
const getBorderColor = () => {
if (isSelected) {
return config.pathBorderColorSelected;
}

return borderColor;
};
const theme = useTheme();
const contrastColor = theme.palette.getContrastText(
isSelected ? config.pathStrokeColorSelected : strokeColor,
);

return (
<>
<RouteBorder
d={d}
strokeWidth={config.pathBorderWidth}
stroke={getBorderColor()}
stroke={contrastColor}
strokeLinecap="round"
strokeLinejoin="round"
fill="none"
Expand All @@ -71,6 +65,17 @@ export const PathWithBorder = ({
// pointerEvents={arePointerEventsDisabled ? 'none' : 'all'}
{...props}
/>
{routeIndexHovered === routeNumber && (
<RouteLine
d={d}
strokeWidth={config.pathStrokeWidth}
stroke={`${config.pathStrokeColorSelected}80`}
strokeLinecap="round"
strokeLinejoin="round"
fill="none"
{...props}
/>
)}
</>
);
};
2 changes: 1 addition & 1 deletion src/components/FeaturePanel/Climbing/Editor/RoutePath.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const RoutePath = ({ route, routeNumber }) => {
return (
<InteractiveArea
stroke="transparent"
strokeWidth={20}
strokeWidth={15}
x1={position1.x}
y1={position1.y}
x2={position2.x}
Expand Down
15 changes: 14 additions & 1 deletion src/components/FeaturePanel/Climbing/Editor/RoutesLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const RoutesLayer = ({
routeSelectedIndex,
getMachine,
isRouteSelected,
isRouteHovered,
getPixelPosition,
editorPosition,
scrollOffset,
Expand Down Expand Up @@ -100,6 +101,7 @@ export const RoutesLayer = ({
const sortedRoutes = routes.reduce<{
selected: Array<RouteRenders>;
rest: Array<RouteRenders>;
hovered: Array<RouteRenders>;
}>(
(acc, route, index) => {
const RenderRoute = () => (
Expand All @@ -126,6 +128,15 @@ export const RoutesLayer = ({
],
};
}
if (isRouteHovered(index)) {
return {
...acc,
hovered: [
...acc.hovered,
{ route: <RenderRoute />, marks: <RenderRouteMarks /> },
],
};
}
return {
...acc,
rest: [
Expand All @@ -134,7 +145,7 @@ export const RoutesLayer = ({
],
};
},
{ selected: [], rest: [] },
{ selected: [], rest: [], hovered: [] },
);

const lastPointOfSelectedRoute =
Expand Down Expand Up @@ -174,6 +185,8 @@ export const RoutesLayer = ({
{sortedRoutes.rest.map((item) => item.marks)}
{sortedRoutes.selected.map((item) => item.route)}
{sortedRoutes.selected.map((item) => item.marks)}
{sortedRoutes.hovered.map((item) => item.route)}
{sortedRoutes.hovered.map((item) => item.marks)}
</Svg>

{routeFloatingMenuPosition && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type ClimbingContextType = {
imageContainerSize: ImageSize;
isPointMoving: boolean;
isRouteSelected: (routeNumber: number) => boolean;
isRouteHovered: (routeNumber: number) => boolean;
isPointSelected: (pointNumber: number) => boolean;
getPhotoInfoForRoute: (routeNumber: number) => PhotoInfo;
pointSelectedIndex: number;
Expand Down Expand Up @@ -273,6 +274,7 @@ export const ClimbingContextProvider = ({ children, feature }: Props) => {
});

const isRouteSelected = (index: number) => routeSelectedIndex === index;
const isRouteHovered = (index: number) => routeIndexHovered === index;
const isPointSelected = (index: number) => pointSelectedIndex === index;
const getPhotoInfoForRoute = (index: number): PhotoInfo => {
const checkedPaths = routes[index]?.paths;
Expand Down Expand Up @@ -348,6 +350,7 @@ export const ClimbingContextProvider = ({ children, feature }: Props) => {
isPointClicked,
isPointMoving,
isRouteSelected,
isRouteHovered,
isPointSelected,
getPhotoInfoForRoute,
pointSelectedIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ export const useScrollShadow = (deps = []) => {
}, deps);

useEffect(() => {
window.addEventListener('resize', () => setShadows());
window.addEventListener('orientationchange', () => setShadows());
const handleShadows = () => setShadows();
window.addEventListener('resize', handleShadows);
window.addEventListener('orientationchange', handleShadows);

return () => {
window.removeEventListener('resize', () => setShadows());
window.removeEventListener('orientationchange', () => setShadows());
window.removeEventListener('resize', handleShadows);
window.removeEventListener('orientationchange', handleShadows);
};
}, []);

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const darkTheme = createMuiTheme({
active: '#2fbc81ff',
inactive: '#0a0a0aff',
border: '#ffffffff',
selected: '#fff',
selected: '#ffffff',
},
} as unknown,
});
Expand Down

0 comments on commit c5b2144

Please sign in to comment.