Updated names for uniformity
This commit is contained in:
@@ -19,7 +19,7 @@ import Search from './components/Search/Search';
|
||||
import SettingsButton from './components/SettingsButton/SettingsButton';
|
||||
|
||||
export function Homepage() {
|
||||
const { data: personal, isFetched: personalIsFetched } = useQueryAPI({
|
||||
const { data: personalData, isFetched: personalIsFetched } = useQueryAPI({
|
||||
endpoint: 'api/personalData',
|
||||
});
|
||||
const {
|
||||
@@ -27,7 +27,7 @@ export function Homepage() {
|
||||
isFetching: isMessagesFetching,
|
||||
isFetched: isMessagesFetched,
|
||||
} = useQueryAPI({
|
||||
endpoint: 'api/messages',
|
||||
endpoint: 'api/displayedGreeting',
|
||||
});
|
||||
const {
|
||||
appFilter,
|
||||
@@ -37,8 +37,8 @@ export function Homepage() {
|
||||
currentLocation,
|
||||
setCurrentLocation,
|
||||
} = useCommonHooks();
|
||||
const [personalData, setPersonalData] = useState<PersonalData>();
|
||||
const [messages, setMessages] = useState<Message[]>([]);
|
||||
const [personal, setPersonal] = useState<PersonalData>();
|
||||
const [message, setMessage] = useState<Message>();
|
||||
const [displayedGreeting, setDisplayedGreeting] = useState('');
|
||||
const [weatherModalOpened, { open: openWeatherModal, close: closeWeatherModal }] =
|
||||
useDisclosure(false);
|
||||
@@ -53,36 +53,36 @@ export function Homepage() {
|
||||
const date = new Date().toLocaleDateString('en-US', dateOptions);
|
||||
useEffect(() => {
|
||||
if (messageData && isMessagesFetched) {
|
||||
setMessages(messageData);
|
||||
setMessage(messageData[0]);
|
||||
}
|
||||
}, [messageData, isMessagesFetched]);
|
||||
useEffect(() => {
|
||||
if (personal && personalIsFetched) {
|
||||
setCurrentUser(personal[0]);
|
||||
setPersonalData(personal[0]);
|
||||
if (personalData && personalIsFetched) {
|
||||
setCurrentUser(personalData[0]);
|
||||
setPersonal(personalData[0]);
|
||||
}
|
||||
}, [personal, personalIsFetched]);
|
||||
}, [personalData, personalIsFetched]);
|
||||
useEffect(() => {
|
||||
if (messages && personalData) {
|
||||
if (message !== undefined && personal) {
|
||||
setDisplayedGreeting(() => {
|
||||
if (Math.floor(Math.random() * 100) > 10 || messages.length === 0) {
|
||||
if (Math.floor(Math.random() * 100) > 10 || message === undefined) {
|
||||
switch (Math.floor(new Date().getHours() / 6)) {
|
||||
case 0:
|
||||
return `Good night, ${personalData?.firstName}!`;
|
||||
return `Good night, ${personal?.firstName}!`;
|
||||
case 1:
|
||||
return `Good morning, ${personalData?.firstName}!`;
|
||||
return `Good morning, ${personal?.firstName}!`;
|
||||
case 2:
|
||||
return `Good afternoon, ${personalData?.firstName}!`;
|
||||
return `Good afternoon, ${personal?.firstName}!`;
|
||||
case 3:
|
||||
return `Good evening, ${personalData?.firstName}!`;
|
||||
return `Good evening, ${personal?.firstName}!`;
|
||||
}
|
||||
}
|
||||
return messages[Math.floor(Math.random() * messages.length)].message;
|
||||
return message.message;
|
||||
});
|
||||
}
|
||||
}, [messages, personalData, isMessagesFetching]);
|
||||
}, [message, personal, isMessagesFetching]);
|
||||
const { data: weatherMetadata } = useOSMAPI({
|
||||
address: personal?.[0]?.physicalAddress,
|
||||
address: personalData?.[0]?.physicalAddress,
|
||||
});
|
||||
const { data: points } = useWeatherAPI({
|
||||
endpoint: 'points',
|
||||
|
||||
Reference in New Issue
Block a user