Added localstorage data
This commit is contained in:
@@ -3,37 +3,33 @@ import { modalClasses } from 'styles';
|
|||||||
import SmallOutlookCard from './SmallOutlookCard';
|
import SmallOutlookCard from './SmallOutlookCard';
|
||||||
import SmallWeatherCard from './SmallWeatherCard';
|
import SmallWeatherCard from './SmallWeatherCard';
|
||||||
|
|
||||||
import { useCommonHooks, useQueryAPI, useWeatherAPI } from 'hooks';
|
import { useCommonHooks, useWeatherAPI } from 'hooks';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import HourlyCard from './HourlyCard';
|
import HourlyCard from './HourlyCard';
|
||||||
|
|
||||||
export function WeatherModal({
|
export function WeatherModal({
|
||||||
current,
|
current,
|
||||||
outlook,
|
outlook,
|
||||||
points,
|
|
||||||
closeWeatherModal,
|
closeWeatherModal,
|
||||||
weatherModalOpened,
|
weatherModalOpened,
|
||||||
}: any) {
|
}: any) {
|
||||||
const { data: personalData, isFetched: personalIsFetched } = useQueryAPI({
|
const {
|
||||||
endpoint: 'api/personalData',
|
theme,
|
||||||
});
|
isMobile,
|
||||||
|
setProviderLabel,
|
||||||
|
setSearchValue,
|
||||||
|
setProviderURL,
|
||||||
|
currentUser,
|
||||||
|
currentLocation,
|
||||||
|
} = useCommonHooks();
|
||||||
const { data: hourly } = useWeatherAPI({
|
const { data: hourly } = useWeatherAPI({
|
||||||
endpoint: 'hourly',
|
endpoint: 'hourly',
|
||||||
office: points?.properties.gridId,
|
office: currentLocation.office,
|
||||||
x: points?.properties.gridX,
|
x: currentLocation.x,
|
||||||
y: points?.properties.gridY,
|
y: currentLocation.y,
|
||||||
});
|
});
|
||||||
const [personal, setPersonal] = useState<any>([]);
|
|
||||||
const [hourlyForecast, setHourlyForecast] = useState<any>([]);
|
const [hourlyForecast, setHourlyForecast] = useState<any>([]);
|
||||||
const [sunset, setSunset] = useState(100);
|
const [sunset, setSunset] = useState(100);
|
||||||
const { theme, isMobile, setProviderLabel, setSearchValue, setProviderURL } =
|
|
||||||
useCommonHooks();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (personalData && personalIsFetched) {
|
|
||||||
setPersonal(personalData);
|
|
||||||
}
|
|
||||||
}, [personalData, personalIsFetched]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (hourly) {
|
if (hourly) {
|
||||||
@@ -87,7 +83,7 @@ export function WeatherModal({
|
|||||||
Weather Forecast for{' '}
|
Weather Forecast for{' '}
|
||||||
</Text>
|
</Text>
|
||||||
<Text fz={18} fw={600}>
|
<Text fz={18} fw={600}>
|
||||||
{personal?.[0]?.physicalAddress}
|
{currentUser.physicalAddress}
|
||||||
</Text>
|
</Text>
|
||||||
</Group>
|
</Group>
|
||||||
</Modal.Title>
|
</Modal.Title>
|
||||||
|
|||||||
@@ -25,6 +25,24 @@ export function useCommonHooks() {
|
|||||||
const [searchValue, setSearchValue] = useState('');
|
const [searchValue, setSearchValue] = useState('');
|
||||||
const [providerLabel, setProviderLabel] = useState('Google Search');
|
const [providerLabel, setProviderLabel] = useState('Google Search');
|
||||||
const [providerURL, setProviderURL] = useState('https://www.google.com/search?q=');
|
const [providerURL, setProviderURL] = useState('https://www.google.com/search?q=');
|
||||||
|
const [currentUser, setCurrentUser] = useLocalStorage<any>({
|
||||||
|
key: 'user',
|
||||||
|
defaultValue: {
|
||||||
|
firstName: 'First',
|
||||||
|
lastName: 'Last',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const [currentLocation, setCurrentLocation] = useLocalStorage<any>({
|
||||||
|
key: 'location',
|
||||||
|
defaultValue: {
|
||||||
|
office: 'HGX',
|
||||||
|
station: 'KHOU',
|
||||||
|
x: 65,
|
||||||
|
y: 96,
|
||||||
|
lat: 29.750950134386066,
|
||||||
|
lon: -95.36220654860034,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const handleThemeChange = (themes: any, save: any) => {
|
const handleThemeChange = (themes: any, save: any) => {
|
||||||
const enabled = themes
|
const enabled = themes
|
||||||
@@ -59,5 +77,9 @@ export function useCommonHooks() {
|
|||||||
setProviderLabel,
|
setProviderLabel,
|
||||||
providerURL,
|
providerURL,
|
||||||
setProviderURL,
|
setProviderURL,
|
||||||
|
currentUser,
|
||||||
|
setCurrentUser,
|
||||||
|
currentLocation,
|
||||||
|
setCurrentLocation,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,14 @@ export function Homepage() {
|
|||||||
const [displayedGreeting, setDisplayedGreeting] = useState('');
|
const [displayedGreeting, setDisplayedGreeting] = useState('');
|
||||||
const [weatherModalOpened, { open: openWeatherModal, close: closeWeatherModal }] =
|
const [weatherModalOpened, { open: openWeatherModal, close: closeWeatherModal }] =
|
||||||
useDisclosure(false);
|
useDisclosure(false);
|
||||||
const { appFilter, bookmarkFilter, isMobile } = useCommonHooks();
|
const {
|
||||||
|
appFilter,
|
||||||
|
bookmarkFilter,
|
||||||
|
isMobile,
|
||||||
|
setCurrentUser,
|
||||||
|
currentLocation,
|
||||||
|
setCurrentLocation,
|
||||||
|
} = useCommonHooks();
|
||||||
const dateOptions: Intl.DateTimeFormatOptions = !isMobile
|
const dateOptions: Intl.DateTimeFormatOptions = !isMobile
|
||||||
? {
|
? {
|
||||||
weekday: 'long',
|
weekday: 'long',
|
||||||
@@ -36,7 +43,6 @@ export function Homepage() {
|
|||||||
}
|
}
|
||||||
: {};
|
: {};
|
||||||
const date = new Date().toLocaleDateString('en-US', dateOptions);
|
const date = new Date().toLocaleDateString('en-US', dateOptions);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (messageData && isMessagesFetched) {
|
if (messageData && isMessagesFetched) {
|
||||||
setMessages(messageData);
|
setMessages(messageData);
|
||||||
@@ -44,6 +50,7 @@ export function Homepage() {
|
|||||||
}, [messageData, isMessagesFetched]);
|
}, [messageData, isMessagesFetched]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (personal && personalIsFetched) {
|
if (personal && personalIsFetched) {
|
||||||
|
setCurrentUser(personal[0]);
|
||||||
setPersonalData(personal);
|
setPersonalData(personal);
|
||||||
}
|
}
|
||||||
}, [personal, personalIsFetched]);
|
}, [personal, personalIsFetched]);
|
||||||
@@ -71,30 +78,31 @@ export function Homepage() {
|
|||||||
const { data: weatherMetadata } = useOSMAPI({ address: personal?.[0].physicalAddress });
|
const { data: weatherMetadata } = useOSMAPI({ address: personal?.[0].physicalAddress });
|
||||||
const { data: points } = useWeatherAPI({
|
const { data: points } = useWeatherAPI({
|
||||||
endpoint: 'points',
|
endpoint: 'points',
|
||||||
lat: weatherMetadata?.[0].lat || 0,
|
lat: weatherMetadata?.[0].lat || currentLocation.lat,
|
||||||
lon: weatherMetadata?.[0].lon || 0,
|
lon: weatherMetadata?.[0].lon || currentLocation.lon,
|
||||||
});
|
});
|
||||||
const { data: basicWeather } = useWeatherAPI({
|
const { data: basicWeather } = useWeatherAPI({
|
||||||
endpoint: 'baseline',
|
endpoint: 'baseline',
|
||||||
office: points?.properties.gridId,
|
office: points?.properties.gridId || currentLocation.office,
|
||||||
x: points?.properties.gridX,
|
x: points?.properties.gridX || currentLocation.x,
|
||||||
y: points?.properties.gridY,
|
y: points?.properties.gridY || currentLocation.y,
|
||||||
});
|
});
|
||||||
const { data: stations } = useWeatherAPI({
|
const { data: stations } = useWeatherAPI({
|
||||||
endpoint: 'stations',
|
endpoint: 'stations',
|
||||||
office: points?.properties.gridId,
|
office: points?.properties.gridId || currentLocation.office,
|
||||||
x: points?.properties.gridX,
|
x: points?.properties.gridX || currentLocation.x,
|
||||||
y: points?.properties.gridY,
|
y: points?.properties.gridY || currentLocation.y,
|
||||||
});
|
});
|
||||||
const { data: weather } = useWeatherAPI({
|
const { data: weather } = useWeatherAPI({
|
||||||
endpoint: 'current',
|
endpoint: 'current',
|
||||||
station: stations?.features[0].properties.stationIdentifier,
|
station:
|
||||||
|
stations?.features[0].properties.stationIdentifier || currentLocation.station,
|
||||||
});
|
});
|
||||||
const { data: forecast } = useWeatherAPI({
|
const { data: forecast } = useWeatherAPI({
|
||||||
endpoint: 'forecast',
|
endpoint: 'forecast',
|
||||||
office: points?.properties.gridId,
|
office: points?.properties.gridId || currentLocation.office,
|
||||||
x: points?.properties.gridX,
|
x: points?.properties.gridX || currentLocation.x,
|
||||||
y: points?.properties.gridY,
|
y: points?.properties.gridY || currentLocation.y,
|
||||||
});
|
});
|
||||||
const [current, setCurrent] = useState<CurrentWeather>({
|
const [current, setCurrent] = useState<CurrentWeather>({
|
||||||
icon: '',
|
icon: '',
|
||||||
@@ -145,7 +153,6 @@ export function Homepage() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [weather, basicWeather]);
|
}, [weather, basicWeather]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (forecast) {
|
if (forecast) {
|
||||||
setOutlook([
|
setOutlook([
|
||||||
@@ -172,9 +179,16 @@ export function Homepage() {
|
|||||||
windDirection: forecast.properties.periods[1].windDirection,
|
windDirection: forecast.properties.periods[1].windDirection,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
setCurrentLocation({
|
||||||
|
office: points?.properties.gridId,
|
||||||
|
station: stations?.features[0].properties.stationIdentifier,
|
||||||
|
x: points?.properties.gridX,
|
||||||
|
y: points?.properties.gridY,
|
||||||
|
lat: weatherMetadata?.[0].lat,
|
||||||
|
lon: weatherMetadata?.[0].lon,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, [forecast]);
|
}, [forecast]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack gap={0} className={stackClasses.containerStack} justify='center'>
|
<Stack gap={0} className={stackClasses.containerStack} justify='center'>
|
||||||
<Search
|
<Search
|
||||||
@@ -182,7 +196,6 @@ export function Homepage() {
|
|||||||
outlook={outlook}
|
outlook={outlook}
|
||||||
weather={weather}
|
weather={weather}
|
||||||
basicWeather={basicWeather}
|
basicWeather={basicWeather}
|
||||||
points={points}
|
|
||||||
weatherModalOpened={weatherModalOpened}
|
weatherModalOpened={weatherModalOpened}
|
||||||
closeWeatherModal={closeWeatherModal}
|
closeWeatherModal={closeWeatherModal}
|
||||||
openWeatherModal={openWeatherModal}
|
openWeatherModal={openWeatherModal}
|
||||||
@@ -195,7 +208,6 @@ export function Homepage() {
|
|||||||
outlook={outlook}
|
outlook={outlook}
|
||||||
weather={weather}
|
weather={weather}
|
||||||
basicWeather={basicWeather}
|
basicWeather={basicWeather}
|
||||||
points={points}
|
|
||||||
weatherModalOpened={weatherModalOpened}
|
weatherModalOpened={weatherModalOpened}
|
||||||
closeWeatherModal={closeWeatherModal}
|
closeWeatherModal={closeWeatherModal}
|
||||||
openWeatherModal={openWeatherModal}
|
openWeatherModal={openWeatherModal}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Group, Stack, Text } from '@mantine/core';
|
import { Group, Stack, Text } from '@mantine/core';
|
||||||
import { WeatherModal } from 'components';
|
import { WeatherModal } from 'components';
|
||||||
import { useCommonHooks, useQueryAPI } from 'hooks';
|
import { useCommonHooks } from 'hooks';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { textClasses } from 'styles';
|
import { textClasses } from 'styles';
|
||||||
|
|
||||||
@@ -12,17 +12,12 @@ function Header({
|
|||||||
outlook,
|
outlook,
|
||||||
weather,
|
weather,
|
||||||
basicWeather,
|
basicWeather,
|
||||||
points,
|
|
||||||
weatherModalOpened,
|
weatherModalOpened,
|
||||||
closeWeatherModal,
|
closeWeatherModal,
|
||||||
openWeatherModal,
|
openWeatherModal,
|
||||||
}: any) {
|
}: any) {
|
||||||
const { data: personal, isFetched: personalIsFetched } = useQueryAPI({
|
|
||||||
endpoint: 'api/personalData',
|
|
||||||
});
|
|
||||||
const [personalData, setPersonalData] = useState<any>([]);
|
|
||||||
const [time, setTime] = useState(new Date());
|
const [time, setTime] = useState(new Date());
|
||||||
const { isMobile } = useCommonHooks();
|
const { isMobile, currentUser } = useCommonHooks();
|
||||||
|
|
||||||
function fixDigits(k: any) {
|
function fixDigits(k: any) {
|
||||||
if (k < 10) {
|
if (k < 10) {
|
||||||
@@ -38,12 +33,6 @@ function Header({
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (personal && personalIsFetched) {
|
|
||||||
setPersonalData(personal);
|
|
||||||
}
|
|
||||||
}, [personal, personalIsFetched]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (weather !== undefined && basicWeather !== undefined) {
|
if (weather !== undefined && basicWeather !== undefined) {
|
||||||
setCurrent({
|
setCurrent({
|
||||||
@@ -92,10 +81,10 @@ function Header({
|
|||||||
fz={isMobile ? 24 : undefined}
|
fz={isMobile ? 24 : undefined}
|
||||||
>
|
>
|
||||||
{greet
|
{greet
|
||||||
.replace('$firstName', personalData?.[0]?.firstName)
|
.replace('$firstName', currentUser.firstName)
|
||||||
.replace('$lastName', personalData?.[0]?.lastName)
|
.replace('$lastName', currentUser.lastName)
|
||||||
.replace('$firstName!', personalData?.[0]?.firstName.toUpperCase())
|
.replace('$firstName!', currentUser.firstName.toUpperCase())
|
||||||
.replace('$lastName!', personalData?.[0]?.lastName.toUpperCase())}
|
.replace('$lastName!', currentUser.lastName.toUpperCase())}
|
||||||
</Text>
|
</Text>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack
|
<Stack
|
||||||
@@ -165,7 +154,6 @@ function Header({
|
|||||||
<WeatherModal
|
<WeatherModal
|
||||||
current={current}
|
current={current}
|
||||||
outlook={outlook}
|
outlook={outlook}
|
||||||
points={points}
|
|
||||||
closeWeatherModal={closeWeatherModal}
|
closeWeatherModal={closeWeatherModal}
|
||||||
weatherModalOpened={weatherModalOpened}
|
weatherModalOpened={weatherModalOpened}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import { textInputClasses } from 'styles';
|
|||||||
export default function Search({
|
export default function Search({
|
||||||
current,
|
current,
|
||||||
outlook,
|
outlook,
|
||||||
points,
|
|
||||||
weatherModalOpened,
|
weatherModalOpened,
|
||||||
closeWeatherModal,
|
closeWeatherModal,
|
||||||
openWeatherModal,
|
openWeatherModal,
|
||||||
@@ -132,7 +131,6 @@ export default function Search({
|
|||||||
<WeatherModal
|
<WeatherModal
|
||||||
current={current}
|
current={current}
|
||||||
outlook={outlook}
|
outlook={outlook}
|
||||||
points={points}
|
|
||||||
closeWeatherModal={closeWeatherModal}
|
closeWeatherModal={closeWeatherModal}
|
||||||
weatherModalOpened={weatherModalOpened}
|
weatherModalOpened={weatherModalOpened}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user