String updates
This commit is contained in:
@@ -1,47 +0,0 @@
|
|||||||
export function date(isMobile: boolean) {
|
|
||||||
const currentDate = new Date();
|
|
||||||
const dateOptions: Intl.DateTimeFormatOptions = !isMobile
|
|
||||||
? {
|
|
||||||
weekday: 'long',
|
|
||||||
year: 'numeric',
|
|
||||||
month: 'long',
|
|
||||||
day: 'numeric',
|
|
||||||
}
|
|
||||||
: {};
|
|
||||||
const date = currentDate.toLocaleDateString('en-US', dateOptions);
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
export function greet(list: any) {
|
|
||||||
const currentTime = new Date();
|
|
||||||
const greet = Math.floor(currentTime.getHours() / 6);
|
|
||||||
const easterEggChance = Math.floor(Math.random() * 100);
|
|
||||||
let timeBased: any = [];
|
|
||||||
let customGreetings: any = [];
|
|
||||||
for (const l of list) {
|
|
||||||
if (l.customGreeting === 0) {
|
|
||||||
timeBased = timeBased.concat(l);
|
|
||||||
} else {
|
|
||||||
customGreetings = customGreetings.concat(l);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (easterEggChance > 10 || customGreetings.length === 0) {
|
|
||||||
return timeBased[greet].message;
|
|
||||||
}
|
|
||||||
return customGreetings[Math.floor(Math.random() * customGreetings.length)].message;
|
|
||||||
}
|
|
||||||
export function validURL(str: any) {
|
|
||||||
const pattern = new RegExp(
|
|
||||||
'^(https?:\\/\\/)?' + // protocol
|
|
||||||
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
|
|
||||||
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
|
|
||||||
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
|
|
||||||
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
|
|
||||||
'(\\#[-a-z\\d_]*)?$',
|
|
||||||
'i',
|
|
||||||
); // fragment locator
|
|
||||||
return !!pattern.test(str);
|
|
||||||
}
|
|
||||||
export function containsProtocol(str: any) {
|
|
||||||
const pattern = /^(https?:\/\/).*/i;
|
|
||||||
return !!pattern.test(str);
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,2 @@
|
|||||||
export { useQueryAPI, useWeatherAPI, useMutationAPI } from './useAPI';
|
export { useQueryAPI, useWeatherAPI, useMutationAPI } from './useAPI';
|
||||||
export { date, greet, validURL, containsProtocol } from './helpers';
|
|
||||||
export { useCommonHooks } from './useCommonHooks';
|
export { useCommonHooks } from './useCommonHooks';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Stack } from '@mantine/core';
|
import { Stack } from '@mantine/core';
|
||||||
import { useDisclosure } from '@mantine/hooks';
|
import { useDisclosure } from '@mantine/hooks';
|
||||||
import { date, greet, useCommonHooks } from 'hooks';
|
import { useCommonHooks } from 'hooks';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { stackClasses } from 'styles';
|
import { stackClasses } from 'styles';
|
||||||
import type { CurrentWeather, OutlookWeather } from 'types';
|
import type { CurrentWeather, OutlookWeather } from 'types';
|
||||||
@@ -21,6 +21,7 @@ export function Homepage() {
|
|||||||
weather,
|
weather,
|
||||||
basicWeather,
|
basicWeather,
|
||||||
forecast,
|
forecast,
|
||||||
|
personal,
|
||||||
} = useCommonHooks();
|
} = useCommonHooks();
|
||||||
const [current, setCurrent] = useState<CurrentWeather>({
|
const [current, setCurrent] = useState<CurrentWeather>({
|
||||||
icon: '',
|
icon: '',
|
||||||
@@ -47,9 +48,33 @@ export function Homepage() {
|
|||||||
const [weatherModalOpened, { open: openWeatherModal, close: closeWeatherModal }] =
|
const [weatherModalOpened, { open: openWeatherModal, close: closeWeatherModal }] =
|
||||||
useDisclosure(false);
|
useDisclosure(false);
|
||||||
|
|
||||||
|
const dateOptions: Intl.DateTimeFormatOptions = !isMobile
|
||||||
|
? {
|
||||||
|
weekday: 'long',
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'long',
|
||||||
|
day: 'numeric',
|
||||||
|
}
|
||||||
|
: {};
|
||||||
|
const date = new Date().toLocaleDateString('en-US', dateOptions);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (messages) {
|
if (messages) {
|
||||||
setDisplayedGreeting(greet(messages));
|
setDisplayedGreeting(() => {
|
||||||
|
if (Math.floor(Math.random() * 100) < 10 || messages.length === 0) {
|
||||||
|
switch (Math.floor(new Date().getHours() / 6)) {
|
||||||
|
case 0:
|
||||||
|
return `Good night, ${personal[0].firstName}!`;
|
||||||
|
case 1:
|
||||||
|
return `Good morning, ${personal[0].firstName}!`;
|
||||||
|
case 2:
|
||||||
|
return `Good afternoon, ${personal[0].firstName}!`;
|
||||||
|
case 3:
|
||||||
|
return `Good evening, ${personal[0].firstName}!`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return messages[Math.floor(Math.random() * messages.length)].message;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, [messages, isMessagesFetching]);
|
}, [messages, isMessagesFetching]);
|
||||||
|
|
||||||
@@ -119,7 +144,7 @@ export function Homepage() {
|
|||||||
openWeatherModal={openWeatherModal}
|
openWeatherModal={openWeatherModal}
|
||||||
/>
|
/>
|
||||||
<Header
|
<Header
|
||||||
date={date(isMobile)}
|
date={date}
|
||||||
greet={displayedGreeting}
|
greet={displayedGreeting}
|
||||||
current={current}
|
current={current}
|
||||||
setCurrent={setCurrent}
|
setCurrent={setCurrent}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ function Header({
|
|||||||
closeWeatherModal,
|
closeWeatherModal,
|
||||||
openWeatherModal,
|
openWeatherModal,
|
||||||
}: any) {
|
}: any) {
|
||||||
const { isMobile, weather, basicWeather } = useCommonHooks();
|
const { isMobile, weather, basicWeather, personal } = useCommonHooks();
|
||||||
const [time, setTime] = useState(new Date());
|
const [time, setTime] = useState(new Date());
|
||||||
function fixDigits(k: any) {
|
function fixDigits(k: any) {
|
||||||
if (k < 10) {
|
if (k < 10) {
|
||||||
@@ -54,7 +54,6 @@ function Header({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [weather, basicWeather]);
|
}, [weather, basicWeather]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
style={{
|
style={{
|
||||||
@@ -77,7 +76,11 @@ function Header({
|
|||||||
classNames={textClasses}
|
classNames={textClasses}
|
||||||
fz={isMobile ? 24 : undefined}
|
fz={isMobile ? 24 : undefined}
|
||||||
>
|
>
|
||||||
{greet}
|
{greet
|
||||||
|
.replace('$firstName', personal?.[0].firstName)
|
||||||
|
.replace('$lastName', personal?.[0].lastName)
|
||||||
|
.replace('$firstName!', personal?.[0].firstName.toUpperCase())
|
||||||
|
.replace('$lastName!', personal?.[0].lastName.toUpperCase())}
|
||||||
</Text>
|
</Text>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack
|
<Stack
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Stack, TextInput } from '@mantine/core';
|
import { Stack, TextInput } from '@mantine/core';
|
||||||
import { useDisclosure } from '@mantine/hooks';
|
import { useDisclosure } from '@mantine/hooks';
|
||||||
import { HelpModal, WeatherModal } from 'components';
|
import { HelpModal, WeatherModal } from 'components';
|
||||||
import { containsProtocol, useCommonHooks, validURL } from 'hooks';
|
import { useCommonHooks } from 'hooks';
|
||||||
import { textInputClasses } from 'styles';
|
import { textInputClasses } from 'styles';
|
||||||
|
|
||||||
export default function Search({
|
export default function Search({
|
||||||
@@ -27,6 +27,15 @@ export default function Search({
|
|||||||
const handleKeyPress = (item: any) => {
|
const handleKeyPress = (item: any) => {
|
||||||
let option = '';
|
let option = '';
|
||||||
let subtext = '';
|
let subtext = '';
|
||||||
|
const urlPattern = new RegExp(
|
||||||
|
'^(https?:\\/\\/)?' + // protocol
|
||||||
|
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
|
||||||
|
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
|
||||||
|
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
|
||||||
|
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
|
||||||
|
'(\\#[-a-z\\d_]*)?$',
|
||||||
|
'i',
|
||||||
|
); // fragment locator
|
||||||
if (item.target.value.startsWith('/')) {
|
if (item.target.value.startsWith('/')) {
|
||||||
option =
|
option =
|
||||||
item.target.value.substr(1, item.target.value.indexOf(' ') - 1) ||
|
item.target.value.substr(1, item.target.value.indexOf(' ') - 1) ||
|
||||||
@@ -46,8 +55,9 @@ export default function Search({
|
|||||||
open(`${providerURL}${subtext}`, '_self');
|
open(`${providerURL}${subtext}`, '_self');
|
||||||
} else if (providerLabel === 'Show weather') {
|
} else if (providerLabel === 'Show weather') {
|
||||||
openWeatherModal();
|
openWeatherModal();
|
||||||
} else if (validURL(item.target.value)) {
|
} else if (urlPattern.test(item.target.value)) {
|
||||||
if (containsProtocol(item.target.value)) window.location = item.target.value;
|
if (/^(https?:\/\/).*/i.test(item.target.value))
|
||||||
|
window.location = item.target.value;
|
||||||
else open(`https://${item.target.value}`, '_self');
|
else open(`https://${item.target.value}`, '_self');
|
||||||
} else {
|
} else {
|
||||||
open(`${providerURL}${subtext}`, '_self');
|
open(`${providerURL}${subtext}`, '_self');
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ function SettingsButton() {
|
|||||||
<Button
|
<Button
|
||||||
classNames={buttonClasses}
|
classNames={buttonClasses}
|
||||||
className={buttonClasses.wakeButton}
|
className={buttonClasses.wakeButton}
|
||||||
disabled={!wolClients?.length}
|
disabled={!wolClients?.length || selectedClient === null}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleWakeRequest();
|
handleWakeRequest();
|
||||||
notify('Wake command sent');
|
notify('Wake command sent');
|
||||||
|
|||||||
Reference in New Issue
Block a user