-
-
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
7 changed files
with
238 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import styled from '@emotion/styled'; | ||
import { icon, Sign } from './routing/instructions'; | ||
import { RoutingResult } from './routing/types'; | ||
import { useUserSettingsContext } from '../utils/UserSettingsContext'; | ||
import { toHumanDistance } from './helpers'; | ||
import { Stack, Typography } from '@mui/material'; | ||
|
||
type Instruction = RoutingResult['instructions'][number]; | ||
|
||
const Distance = ({ distance }: { distance: number }) => { | ||
const { userSettings } = useUserSettingsContext(); | ||
const { isImperial } = userSettings; | ||
|
||
return <>{toHumanDistance(isImperial, distance)}</>; | ||
}; | ||
|
||
const Icon = ({ sign }: { sign: Sign }) => { | ||
const Component = icon(sign); | ||
return <Component fontSize="large" />; | ||
}; | ||
|
||
const StyledListItem = styled.li` | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.25rem; | ||
`; | ||
|
||
const Instruction = ({ instruction }: { instruction: Instruction }) => ( | ||
<StyledListItem> | ||
<Stack direction="row" alignItems="center"> | ||
<Icon sign={instruction.sign} /> | ||
{instruction.street_name || instruction.text} | ||
</Stack> | ||
{instruction.distance > 0 && ( | ||
<Stack direction="row" alignItems="center" spacing={0.5}> | ||
<Typography | ||
noWrap | ||
color="textSecondary" | ||
variant="body1" | ||
style={{ overflow: 'visible' }} | ||
> | ||
<Distance distance={instruction.distance} /> | ||
</Typography> | ||
<hr style={{ width: '100%' }} /> | ||
</Stack> | ||
)} | ||
</StyledListItem> | ||
); | ||
|
||
const StyledList = styled.ul` | ||
list-style: none; | ||
padding: 0; | ||
max-height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.25rem; | ||
`; | ||
|
||
type Props = { | ||
instructions: Instruction[]; | ||
}; | ||
|
||
export const Instructions = ({ instructions }: Props) => ( | ||
<StyledList> | ||
{instructions.map((instruction) => ( | ||
<Instruction key={instruction.text} instruction={instruction} /> | ||
))} | ||
</StyledList> | ||
); |
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { | ||
ArrowUpward, | ||
FmdGood, | ||
RampLeft, | ||
RampRight, | ||
RoundaboutLeft, | ||
SportsScore, | ||
TurnLeft, | ||
TurnRight, | ||
TurnSharpRight, | ||
TurnSlightLeft, | ||
TurnSlightRight, | ||
UTurnLeft, | ||
UTurnRight, | ||
} from '@mui/icons-material'; | ||
import QuestionMark from '@mui/icons-material/QuestionMark'; | ||
import TurnSharpLeft from '@mui/icons-material/TurnSharpLeft'; | ||
|
||
const GRAPH_HOPPER_INSTRUCTION_CODES = { | ||
[-3]: 'sharp left', | ||
[-2]: 'left', | ||
[-1]: 'slight left', | ||
0: 'straight', | ||
1: 'slight right', | ||
2: 'right', | ||
3: 'sharp right', | ||
4: 'finish reached', | ||
5: 'via reached', | ||
6: 'roundabout', | ||
[-7]: 'keep left', | ||
7: 'keep right', | ||
[-98]: 'unknown direction u-turn', | ||
[-8]: 'left u-turn', | ||
8: 'right u-turn', | ||
}; | ||
|
||
export type Sign = keyof typeof GRAPH_HOPPER_INSTRUCTION_CODES; | ||
|
||
export const icon = (sign: Sign) => { | ||
switch (sign) { | ||
case -3: | ||
return TurnSharpLeft; | ||
case -2: | ||
return TurnLeft; | ||
case -1: | ||
return TurnSlightLeft; | ||
case 0: | ||
return ArrowUpward; | ||
case 1: | ||
return TurnSlightRight; | ||
case 2: | ||
return TurnRight; | ||
case 3: | ||
return TurnSharpRight; | ||
case 4: | ||
return SportsScore; | ||
case 5: | ||
return FmdGood; | ||
case 6: | ||
return RoundaboutLeft; | ||
case -7: | ||
return RampLeft; | ||
case 7: | ||
return RampRight; | ||
case -98: | ||
case -8: | ||
return UTurnLeft; | ||
case 8: | ||
return UTurnRight; | ||
default: | ||
return QuestionMark; | ||
} | ||
}; |
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