-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
151 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')} | ||
<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> | ||
)} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.