Skip to content

Commit

Permalink
Climbing Guide: Update UX (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvaclavik authored Oct 9, 2024
1 parent 766059a commit a8527fe
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 108 deletions.
35 changes: 24 additions & 11 deletions src/components/FeaturePanel/Climbing/ClimbingCragDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
DialogContent,
DialogActions,
Button,
Box,
Stack,
} from '@mui/material';
import { ClimbingView } from './ClimbingView';
Expand All @@ -17,11 +16,18 @@ import { getOsmappLink } from '../../../services/helpers';
import { useFeatureContext } from '../../utils/FeatureContext';
import { useGetHandleSave } from './useGetHandleSave';
import { getWikimediaCommonsPhotoKeys, removeFilePrefix } from './utils/photo';
import { useMobileMode } from '../../helpers';
import { Guide } from './Guide';

const Flex = styled.div`
display: flex;
justify-content: space-between;
width: 100%;
align-items: center;
gap: 16px;
`;
const LeftActions = styled.div`
flex: 1;
`;

export const ClimbingCragDialog = ({
Expand Down Expand Up @@ -108,6 +114,8 @@ export const ClimbingCragDialog = ({
machine.execute('createRoute');
};

const isMobileMode = useMobileMode();

return (
<Dialog fullScreen open onClose={handleClose}>
<ClimbingCragDialogHeader onClose={handleClose} />
Expand All @@ -127,17 +135,22 @@ export const ClimbingCragDialog = ({
{isEditMode && (
<DialogActions>
<Flex>
<div>
{isEditMode && showDebugMenu && (
<Button
onClick={onNewRouteCreate}
color="primary"
startIcon={<AddIcon />}
>
Add new route
</Button>
<LeftActions>
{!isMobileMode && (
<>
{showDebugMenu && (
<Button
onClick={onNewRouteCreate}
color="primary"
startIcon={<AddIcon />}
>
Add new route
</Button>
)}
<Guide />
</>
)}
</div>
</LeftActions>
<div>
<Stack spacing={2} direction="row">
<Button autoFocus onClick={handleCancel}>
Expand Down
16 changes: 0 additions & 16 deletions src/components/FeaturePanel/Climbing/ClimbingCragDialogHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { useFeatureContext } from '../../utils/FeatureContext';
import { getLabel } from '../../../helpers/featureLabel';
import { getOsmappLink } from '../../../services/helpers';
import { UserSettingsDialog } from '../../HomepagePanel/UserSettingsDialog';
import EditIcon from '@mui/icons-material/Edit';

const Title = styled.div`
flex: 1;
Expand Down Expand Up @@ -101,21 +100,6 @@ export const ClimbingCragDialogHeader = ({ onClose }) => {
)}
</Title>

<Box mr={1}>
{!isEditMode && (
<Tooltip title="Edit crag">
<IconButton
color="primary"
edge="end"
onClick={() => {
setIsEditMode(true);
}}
>
<EditIcon fontSize="small" />
</IconButton>
</Tooltip>
)}
</Box>
<Box mr={2}>
<Tooltip title="Show settings">
<IconButton
Expand Down
26 changes: 18 additions & 8 deletions src/components/FeaturePanel/Climbing/ClimbingView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
import { TransformComponent } from 'react-zoom-pan-pinch';
import { useClimbingContext } from './contexts/ClimbingContext';
import { RoutesEditor } from './Editor/RoutesEditor';
import { Guide } from './Guide';
import { ControlPanel } from './Editor/ControlPanel';
import { useFeatureContext } from '../../utils/FeatureContext';
import {
Expand All @@ -32,6 +31,7 @@ import { getOsmappLink } from '../../../services/helpers';
import { useRouter } from 'next/router';
import FormatListNumberedIcon from '@mui/icons-material/FormatListNumbered';
import MapIcon from '@mui/icons-material/Map';
import EditIcon from '@mui/icons-material/Edit';

const FabContainer = styled.div`
position: absolute;
Expand Down Expand Up @@ -208,7 +208,7 @@ export const ClimbingView = ({ photo }: { photo?: string }) => {
routeListTopOffsets,
setRouteSelectedIndex,
routes,
setPhotoPath,
setIsEditMode,
} = useClimbingContext();
const { feature } = useFeatureContext();

Expand Down Expand Up @@ -417,6 +417,21 @@ export const ClimbingView = ({ photo }: { photo?: string }) => {
$imageUrl={backgroundImageUrl}
>
<>
{!isEditMode && (
<FabContainer>
<Tooltip title="Draw routes" enterDelay={1500} arrow>
<Fab
size="small"
color="secondary"
aria-label="add"
onClick={() => setIsEditMode(true)}
>
<EditIcon />
</Fab>
</Tooltip>
</FabContainer>
)}

{(!isResolutionLoaded || isPhotoLoading) && (
<MiniLoadingContainer>
<CircularProgress color="primary" size={14} thickness={6} />
Expand Down Expand Up @@ -446,12 +461,7 @@ export const ClimbingView = ({ photo }: { photo?: string }) => {
</>
</TransformComponent>
</TransformWrapper>
{isEditMode && (
<>
<ControlPanel />
<Guide />
</>
)}
{isEditMode && <ControlPanel />}
</BlurContainer>
</>
</BackgroundContainer>
Expand Down
13 changes: 9 additions & 4 deletions src/components/FeaturePanel/Climbing/Editor/ControlPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import UndoIcon from '@mui/icons-material/Undo';
import React from 'react';
import styled from '@emotion/styled';
import { IconButton } from '@mui/material';
import { IconButton, useTheme } from '@mui/material';
import { useClimbingContext } from '../contexts/ClimbingContext';

const Container = styled.div`
background: ${({ theme }) => theme.palette.background.default};
border-radius: 8px;
position: absolute;
width: 44px;
width: 36px;
top: 5px;
left: 5px;
z-index: 1;
Expand All @@ -23,6 +21,7 @@ export const ControlPanel = () => {
};

const path = getCurrentPath();
const theme = useTheme();

return (
<Container>
Expand All @@ -32,6 +31,12 @@ export const ControlPanel = () => {
edge="end"
onClick={onUndoClick}
title="Undo last segment"
sx={{
backgroundColor: theme.palette.background.default,
'&:hover': {
backgroundColor: theme.palette.background.paper,
},
}}
>
<UndoIcon fontSize="small" />
</IconButton>
Expand Down
125 changes: 70 additions & 55 deletions src/components/FeaturePanel/Climbing/Guide.tsx
Original file line number Diff line number Diff line change
@@ -1,76 +1,91 @@
import React, { useState } from 'react';
import React from 'react';
import styled from '@emotion/styled';

import { Button, Snackbar, Alert } from '@mui/material';
import { t } from '../../../services/intl';
import { Button, Alert } from '@mui/material';
import { useClimbingContext } from './contexts/ClimbingContext';
import { RouteNumber } from './RouteNumber';
import { useFeatureContext } from '../../utils/FeatureContext';
import { isTicked } from '../../../services/ticks';
import { getWikimediaCommonsPhotoPathKeys } from './utils/photo';
import { getShortId } from '../../../services/helpers';
import { RouteNumber } from './RouteNumber';
import { t } from '../../../services/intl';

const DrawRouteButton = styled(Button)`
align-items: baseline;
const InlineBlockContainer = styled.div`
display: inline-block;
`;

export const Guide = () => {
const [isGuideClosed, setIsGuideClosed] = useState(false);
const { routeSelectedIndex, getMachine, getCurrentPath } =
const { routeSelectedIndex, getCurrentPath, getMachine } =
useClimbingContext();
const machine = getMachine();
const path = getCurrentPath();
const { feature } = useFeatureContext();
const machine = getMachine();

const routePhotoPathsCount = getWikimediaCommonsPhotoPathKeys(
feature.memberFeatures[routeSelectedIndex]?.tags ?? {},
).length;

const handleClose = () => {
setIsGuideClosed(true);
};
const onDrawRouteClick = () => {
machine.execute('extendRoute', { routeNumber: routeSelectedIndex });
};
const path = getCurrentPath();
const isInSchema = path.length > 0;
const showDrawButton =
!isInSchema && machine.currentStateName !== 'extendRoute';

const {
feature: { osmMeta },
} = useFeatureContext();
const photoPathsCount = getWikimediaCommonsPhotoPathKeys(feature.tags).length;
const hasTick = isTicked(getShortId(osmMeta));

return (
<Snackbar
open={
(machine.currentStateName === 'extendRoute' && !isGuideClosed) ||
(routeSelectedIndex !== null && !isInSchema)
}
anchorOrigin={{
vertical: showDrawButton ? 'bottom' : 'top',
horizontal: showDrawButton ? 'left' : 'center',
}}
>
{showDrawButton ? (
<DrawRouteButton
variant="contained"
size="small"
onClick={onDrawRouteClick}
>
{t('climbingpanel.draw_route')} &nbsp;
<RouteNumber
hasCircle={photoPathsCount > 0}
hasTick={hasTick}
hasTooltip={false}
>
{routeSelectedIndex + 1}
</RouteNumber>
</DrawRouteButton>
) : (
<Alert onClose={handleClose} severity="info" variant="filled">
{path.length === 0
? t('climbingpanel.create_first_node')
: t('climbingpanel.create_next_node')}
<>
{routeSelectedIndex === null && (
<Alert severity="info">
Select route you want to draw from the list
</Alert>
)}
</Snackbar>

{machine.currentStateName !== 'extendRoute' &&
routeSelectedIndex !== null &&
routePhotoPathsCount > 0 && (
<Alert severity="info">
Route{' '}
<InlineBlockContainer>
<RouteNumber hasCircle={true} hasTick={false} hasTooltip={false}>
{routeSelectedIndex + 1}
</RouteNumber>
</InlineBlockContainer>{' '}
is already drawn, but you can update it. Just drag the points or add
a new one.
</Alert>
)}

{machine.currentStateName === 'extendRoute' && !isInSchema && (
<Alert severity="info">{t('climbingpanel.create_first_node')}</Alert>
)}
{machine.currentStateName === 'extendRoute' && isInSchema && (
<Alert severity="info">{t('climbingpanel.create_next_node')}</Alert>
)}

{machine.currentStateName !== 'extendRoute' &&
!isInSchema &&
routeSelectedIndex !== null &&
routePhotoPathsCount === 0 && (
<Alert
severity="info"
action={
<Button
color="info"
variant="contained"
size="small"
onClick={onDrawRouteClick}
endIcon={
<RouteNumber
hasCircle={true}
hasTick={false}
hasTooltip={false}
>
{routeSelectedIndex + 1}
</RouteNumber>
}
>
{t('climbingpanel.draw_route')}
</Button>
}
>
This route is not drawn yet
</Alert>
)}
</>
);
};
Loading

0 comments on commit a8527fe

Please sign in to comment.