Clean up and typing

This commit is contained in:
Sean Edmunds
2025-03-27 16:22:34 -05:00
parent b46d89721e
commit 67293b20ca
47 changed files with 450 additions and 540 deletions

View File

@@ -4,8 +4,13 @@ import CurrentWeather from 'components/WeatherModal/CurrentWeather';
import { useCommonHooks, useOSMAPI, useQueryAPI, useWeatherAPI } from 'hooks';
import { useEffect, useState } from 'react';
import { stackClasses } from 'styles';
import type { CurrentWeather as CW, OutlookWeather } from 'types';
import type { ExtendedForecast as EF } from 'types/weather';
import type {
CurrentWeather as CW,
ExtendedForecast as EF,
Message,
OutlookWeather,
PersonalData,
} from 'types';
import Applications from './components/Applications/Applications';
import Bookmarks from './components/Bookmarks/Bookmarks';
import Header from './components/Header/Header';
@@ -24,11 +29,6 @@ export function Homepage() {
} = useQueryAPI({
endpoint: 'api/messages',
});
const [personalData, setPersonalData] = useState<any>(null);
const [messages, setMessages] = useState<any>(null);
const [displayedGreeting, setDisplayedGreeting] = useState('');
const [weatherModalOpened, { open: openWeatherModal, close: closeWeatherModal }] =
useDisclosure(false);
const {
appFilter,
bookmarkFilter,
@@ -37,6 +37,11 @@ export function Homepage() {
currentLocation,
setCurrentLocation,
} = useCommonHooks();
const [personalData, setPersonalData] = useState<PersonalData>();
const [messages, setMessages] = useState<Message[]>([]);
const [displayedGreeting, setDisplayedGreeting] = useState('');
const [weatherModalOpened, { open: openWeatherModal, close: closeWeatherModal }] =
useDisclosure(false);
const dateOptions: Intl.DateTimeFormatOptions = !isMobile
? {
weekday: 'long',
@@ -54,23 +59,22 @@ export function Homepage() {
useEffect(() => {
if (personal && personalIsFetched) {
setCurrentUser(personal[0]);
setPersonalData(personal);
setPersonalData(personal[0]);
}
}, [personal, personalIsFetched]);
useEffect(() => {
if (messages && personalData) {
setDisplayedGreeting(() => {
if (Math.floor(Math.random() * 100) > 10 || messages.length === 0) {
switch (Math.floor(new Date().getHours() / 6)) {
case 0:
return `Good night, ${personalData?.[0]?.firstName}!`;
return `Good night, ${personalData?.firstName}!`;
case 1:
return `Good morning, ${personalData?.[0]?.firstName}!`;
return `Good morning, ${personalData?.firstName}!`;
case 2:
return `Good afternoon, ${personalData?.[0]?.firstName}!`;
return `Good afternoon, ${personalData?.firstName}!`;
case 3:
return `Good evening, ${personalData?.[0]?.firstName}!`;
return `Good evening, ${personalData?.firstName}!`;
}
}
return messages[Math.floor(Math.random() * messages.length)].message;