Typing
This commit is contained in:
@@ -8,7 +8,6 @@ import type {
|
||||
CurrentWeather as CW,
|
||||
ExtendedForecast as EF,
|
||||
Message,
|
||||
OutlookWeather,
|
||||
PersonalData,
|
||||
} from 'types';
|
||||
import Applications from './components/Applications/Applications';
|
||||
@@ -85,31 +84,31 @@ export function Homepage() {
|
||||
const { data: weatherMetadata } = useOSMAPI({ address: personal?.[0].physicalAddress });
|
||||
const { data: points } = useWeatherAPI({
|
||||
endpoint: 'points',
|
||||
lat: weatherMetadata?.[0].lat || currentLocation.lat,
|
||||
lon: weatherMetadata?.[0].lon || currentLocation.lon,
|
||||
lat: weatherMetadata?.[0].lat ?? currentLocation.lat,
|
||||
lon: weatherMetadata?.[0].lon ?? currentLocation.lon,
|
||||
});
|
||||
const { data: basicWeather } = useWeatherAPI({
|
||||
endpoint: 'baseline',
|
||||
office: points?.properties.gridId || currentLocation.office,
|
||||
x: points?.properties.gridX || currentLocation.x,
|
||||
y: points?.properties.gridY || currentLocation.y,
|
||||
office: points?.properties.gridId ?? currentLocation.office,
|
||||
x: points?.properties.gridX ?? currentLocation.x,
|
||||
y: points?.properties.gridY ?? currentLocation.y,
|
||||
});
|
||||
const { data: stations } = useWeatherAPI({
|
||||
endpoint: 'stations',
|
||||
office: points?.properties.gridId || currentLocation.office,
|
||||
x: points?.properties.gridX || currentLocation.x,
|
||||
y: points?.properties.gridY || currentLocation.y,
|
||||
office: points?.properties.gridId ?? currentLocation.office,
|
||||
x: points?.properties.gridX ?? currentLocation.x,
|
||||
y: points?.properties.gridY ?? currentLocation.y,
|
||||
});
|
||||
const { data: weather } = useWeatherAPI({
|
||||
endpoint: 'current',
|
||||
station:
|
||||
stations?.features[0].properties.stationIdentifier || currentLocation.station,
|
||||
stations?.features[0].properties.stationIdentifier ?? currentLocation.station,
|
||||
});
|
||||
const { data: forecast } = useWeatherAPI({
|
||||
endpoint: 'forecast',
|
||||
office: points?.properties.gridId || currentLocation.office,
|
||||
x: points?.properties.gridX || currentLocation.x,
|
||||
y: points?.properties.gridY || currentLocation.y,
|
||||
office: points?.properties.gridId ?? currentLocation.office,
|
||||
x: points?.properties.gridX ?? currentLocation.x,
|
||||
y: points?.properties.gridY ?? currentLocation.y,
|
||||
});
|
||||
const [current, setCurrent] = useState<CW>({
|
||||
icon: '',
|
||||
@@ -125,17 +124,7 @@ export function Homepage() {
|
||||
windDirection: 0,
|
||||
pressure: 0,
|
||||
});
|
||||
const [outlook, setOutlook] = useState<OutlookWeather[]>([
|
||||
{
|
||||
name: '',
|
||||
icon: '',
|
||||
isDayTime: true,
|
||||
temperature: 0,
|
||||
precipitation: 0,
|
||||
windSpeed: '0 mph',
|
||||
windDirection: 'N',
|
||||
},
|
||||
]);
|
||||
|
||||
const [extendedForecast, setExtendedForecast] = useState<EF[]>([
|
||||
{
|
||||
detailedForecast: '',
|
||||
@@ -150,7 +139,7 @@ export function Homepage() {
|
||||
useEffect(() => {
|
||||
if (weather !== undefined && basicWeather !== undefined) {
|
||||
setCurrent({
|
||||
icon: weather.features[0]?.properties.icon?.replace('medium', 'large') || '',
|
||||
icon: weather.features[0]?.properties.icon?.replace('medium', 'large') ?? '',
|
||||
textDescription: weather.features[0]?.properties.textDescription,
|
||||
temperature: Math.round(
|
||||
(weather.features[0]?.properties.temperature.value * 9) / 5 + 32,
|
||||
@@ -162,7 +151,7 @@ export function Homepage() {
|
||||
(basicWeather.properties.minTemperature.values[0].value * 9) / 5 + 32,
|
||||
),
|
||||
precipitation:
|
||||
weather.features[0]?.properties.precipitationLastHour.value || 'N/A',
|
||||
weather.features[0]?.properties.precipitationLastHour.value ?? 'N/A',
|
||||
humidity: Math.round(weather.features[0]?.properties.relativeHumidity.value),
|
||||
heatIndex:
|
||||
basicWeather.properties.heatIndex?.values[0].value === null
|
||||
@@ -186,30 +175,6 @@ export function Homepage() {
|
||||
}, [weather, basicWeather]);
|
||||
useEffect(() => {
|
||||
if (forecast) {
|
||||
setOutlook([
|
||||
{
|
||||
name: forecast.properties.periods[0].name,
|
||||
icon: forecast.properties.periods[0].icon.replace('medium', 'large'),
|
||||
isDayTime: forecast.properties.periods[0].isDaytime,
|
||||
temperature: forecast.properties.periods[0].temperature,
|
||||
precipitation: Math.round(
|
||||
forecast.properties.periods[0].probabilityOfPrecipitation.value,
|
||||
),
|
||||
windSpeed: forecast.properties.periods[0].windSpeed,
|
||||
windDirection: forecast.properties.periods[0].windDirection,
|
||||
},
|
||||
{
|
||||
name: forecast.properties.periods[1].name,
|
||||
icon: forecast.properties.periods[1].icon.replace('medium', 'large'),
|
||||
isDayTime: forecast.properties.periods[1].isDaytime,
|
||||
temperature: forecast.properties.periods[1].temperature,
|
||||
precipitation: Math.round(
|
||||
forecast.properties.periods[1].probabilityOfPrecipitation.value,
|
||||
),
|
||||
windSpeed: forecast.properties.periods[1].windSpeed,
|
||||
windDirection: forecast.properties.periods[1].windDirection,
|
||||
},
|
||||
]);
|
||||
setExtendedForecast(
|
||||
forecast.properties.periods.map((item: any) => ({
|
||||
detailedForecast: item.detailedForecast,
|
||||
@@ -241,25 +206,18 @@ export function Homepage() {
|
||||
<>
|
||||
<Search
|
||||
current={current}
|
||||
outlook={outlook}
|
||||
extendedForecast={extendedForecast}
|
||||
weather={weather}
|
||||
basicWeather={basicWeather}
|
||||
weatherModalOpened={weatherModalOpened}
|
||||
closeWeatherModal={closeWeatherModal}
|
||||
openWeatherModal={openWeatherModal}
|
||||
/>
|
||||
<Header
|
||||
date={date}
|
||||
greet={displayedGreeting}
|
||||
date={date}
|
||||
current={current}
|
||||
setCurrent={setCurrent}
|
||||
outlook={outlook}
|
||||
extendedForecast={extendedForecast}
|
||||
weather={weather}
|
||||
basicWeather={basicWeather}
|
||||
weatherModalOpened={weatherModalOpened}
|
||||
closeWeatherModal={closeWeatherModal}
|
||||
openWeatherModal={openWeatherModal}
|
||||
/>
|
||||
<Applications contentType={appFilter} />
|
||||
@@ -269,28 +227,19 @@ export function Homepage() {
|
||||
<>
|
||||
<Stack align='center'>
|
||||
<LargeHeader
|
||||
date={date}
|
||||
greet={displayedGreeting}
|
||||
current={current}
|
||||
setCurrent={setCurrent}
|
||||
outlook={outlook}
|
||||
extendedForecast={extendedForecast}
|
||||
date={date}
|
||||
weather={weather}
|
||||
basicWeather={basicWeather}
|
||||
weatherModalOpened={weatherModalOpened}
|
||||
closeWeatherModal={closeWeatherModal}
|
||||
openWeatherModal={openWeatherModal}
|
||||
setCurrent={setCurrent}
|
||||
/>
|
||||
<Grid grow columns={24} pos={'absolute'} bottom={'1rem'} w={'50%'}>
|
||||
<CurrentWeather span={18} current={current} />
|
||||
<CurrentWeather current={current} />
|
||||
</Grid>
|
||||
</Stack>
|
||||
<Search
|
||||
current={current}
|
||||
outlook={outlook}
|
||||
extendedForecast={extendedForecast}
|
||||
weather={weather}
|
||||
basicWeather={basicWeather}
|
||||
weatherModalOpened={weatherModalOpened}
|
||||
closeWeatherModal={closeWeatherModal}
|
||||
openWeatherModal={openWeatherModal}
|
||||
|
||||
Reference in New Issue
Block a user