-
-
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.
Merge remote-tracking branch 'origin/master' into overpass-search
# Conflicts: # src/services/__tests__/osmApi.test.ts
- Loading branch information
Showing
22 changed files
with
595 additions
and
151 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
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
105 changes: 105 additions & 0 deletions
105
src/components/FeaturePanel/renderers/FoodHygieneRatingScheme.tsx
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,105 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { Tooltip, Typography } from '@material-ui/core'; | ||
import RestaurantIcon from '@material-ui/icons/Restaurant'; | ||
import styled from 'styled-components'; | ||
import { getEstablishmentRatingValue } from '../../../services/fhrsApi'; | ||
|
||
const useLoadingState = () => { | ||
const [rating, setRating] = useState<number>(); | ||
const [error, setError] = useState<string>(); | ||
const [loading, setLoading] = useState(true); | ||
|
||
const finishRating = (payload) => { | ||
setLoading(false); | ||
setRating(payload); | ||
}; | ||
|
||
const startRating = () => { | ||
setLoading(true); | ||
setRating(undefined); | ||
setError(undefined); | ||
}; | ||
|
||
const failRating = () => { | ||
setError('Could not load rating'); | ||
setLoading(false); | ||
}; | ||
|
||
return { rating, error, loading, startRating, finishRating, failRating }; | ||
}; | ||
|
||
const Wrapper = styled.div` | ||
display: flex; | ||
gap: 0.5rem; | ||
.MuiRating-root { | ||
margin-top: -2px; | ||
} | ||
`; | ||
|
||
const RatingRound = styled.span` | ||
border-radius: 50%; | ||
background-color: #1a6500; | ||
color: #fff; | ||
padding: 0.25rem 0.5rem; | ||
font-size: 0.75rem; | ||
font-weight: bold; | ||
position: relative; | ||
top: -1px; | ||
`; | ||
|
||
export const FoodHygieneRatingSchemeRenderer = ({ v }) => { | ||
const { rating, error, loading, startRating, finishRating, failRating } = | ||
useLoadingState(); | ||
|
||
useEffect(() => { | ||
const loadData = async () => { | ||
startRating(); | ||
const ratingValue = await getEstablishmentRatingValue(v); | ||
if (Number.isNaN(rating)) { | ||
failRating(); | ||
} | ||
finishRating(ratingValue); | ||
}; | ||
|
||
loadData(); | ||
}, []); | ||
|
||
if (loading) { | ||
return ( | ||
<> | ||
<span className="dotloader" /> | ||
<span className="dotloader" /> | ||
<span className="dotloader" /> | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<RestaurantIcon fontSize="small" /> | ||
<Wrapper> | ||
<Tooltip | ||
arrow | ||
interactive | ||
title="Food Hygiene Rating Scheme (only in UK)" | ||
placement="bottom-end" | ||
> | ||
<a | ||
href={`https://ratings.food.gov.uk/business/${v}`} | ||
className="colorInherit" | ||
> | ||
FHRS{' '} | ||
{Number.isNaN(rating) || error ? ( | ||
<Typography color="textSecondary"> | ||
(Error while fetching rating) | ||
</Typography> | ||
) : ( | ||
<RatingRound>{rating}</RatingRound> | ||
)} | ||
</a> | ||
</Tooltip> | ||
</Wrapper> | ||
</> | ||
); | ||
}; |
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,38 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
import maplibregl from 'maplibre-gl'; | ||
import { useAddMapEvent } from '../../helpers'; | ||
|
||
class OsmappTerrainControl extends maplibregl.TerrainControl { | ||
_toggleTerrain = () => { | ||
if (this._map.getTerrain()) { | ||
this._map.setTerrain(null); | ||
this._map.setMaxPitch(60); | ||
} else { | ||
this._map.setTerrain(this.options); | ||
this._map.setMaxPitch(85); | ||
} | ||
this._updateTerrainIcon(); | ||
}; | ||
} | ||
|
||
const terrainControl = new OsmappTerrainControl({ | ||
source: 'terrain', | ||
exaggeration: 1, | ||
}); | ||
|
||
let added = false; | ||
|
||
export const useToggleTerrainControl = useAddMapEvent((map) => ({ | ||
eventType: 'move', | ||
eventHandler: () => { | ||
if (map.getPitch() > 0) { | ||
if (!added) { | ||
map.addControl(terrainControl); | ||
added = true; | ||
} | ||
} else if (added) { | ||
map.removeControl(terrainControl); | ||
added = false; | ||
} | ||
}, | ||
})); |
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
Oops, something went wrong.