2021-05-13 18:23:12 +02:00
|
|
|
import { useEffect } from 'react';
|
2021-05-08 18:49:08 +02:00
|
|
|
import { Link } from 'react-router-dom';
|
2021-05-23 18:55:27 +02:00
|
|
|
|
|
|
|
// Redux
|
|
|
|
import { connect } from 'react-redux';
|
2021-05-23 18:38:39 +02:00
|
|
|
import { getApps, getCategories } from '../../store/actions';
|
2021-05-13 18:23:12 +02:00
|
|
|
|
2021-05-23 18:55:27 +02:00
|
|
|
// Typescript
|
|
|
|
import { GlobalState } from '../../interfaces/GlobalState';
|
|
|
|
import { App, Category } from '../../interfaces';
|
2021-05-08 18:49:08 +02:00
|
|
|
|
2021-05-23 18:55:27 +02:00
|
|
|
// UI
|
|
|
|
import Icon from '../UI/Icons/Icon/Icon';
|
2021-05-08 18:49:08 +02:00
|
|
|
import { Container } from '../UI/Layout/Layout';
|
2021-05-09 19:02:50 +02:00
|
|
|
import SectionHeadline from '../UI/Headlines/SectionHeadline/SectionHeadline';
|
2021-05-13 18:23:12 +02:00
|
|
|
import Spinner from '../UI/Spinner/Spinner';
|
2021-05-23 18:55:27 +02:00
|
|
|
|
|
|
|
// CSS
|
|
|
|
import classes from './Home.module.css';
|
|
|
|
|
|
|
|
// Components
|
|
|
|
import AppGrid from '../Apps/AppGrid/AppGrid';
|
2021-05-23 18:38:39 +02:00
|
|
|
import BookmarkGrid from '../Bookmarks/BookmarkGrid/BookmarkGrid';
|
2021-05-23 18:55:27 +02:00
|
|
|
import WeatherWidget from '../Widgets/WeatherWidget/WeatherWidget';
|
2021-05-13 18:23:12 +02:00
|
|
|
|
|
|
|
interface ComponentProps {
|
|
|
|
getApps: Function;
|
2021-05-23 18:38:39 +02:00
|
|
|
getCategories: Function;
|
|
|
|
appsLoading: boolean;
|
2021-05-13 18:23:12 +02:00
|
|
|
apps: App[];
|
2021-05-23 18:38:39 +02:00
|
|
|
categoriesLoading: boolean;
|
|
|
|
categories: Category[];
|
2021-05-13 18:23:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const Home = (props: ComponentProps): JSX.Element => {
|
|
|
|
useEffect(() => {
|
2021-05-23 18:38:39 +02:00
|
|
|
if (props.apps.length === 0) {
|
|
|
|
props.getApps();
|
|
|
|
}
|
2021-05-13 18:23:12 +02:00
|
|
|
}, [props.getApps]);
|
2021-05-08 18:49:08 +02:00
|
|
|
|
2021-05-23 18:38:39 +02:00
|
|
|
useEffect(() => {
|
|
|
|
if (props.categories.length === 0) {
|
|
|
|
props.getCategories();
|
|
|
|
}
|
|
|
|
}, [props.getCategories]);
|
|
|
|
|
2021-05-08 18:49:08 +02:00
|
|
|
const dateAndTime = (): string => {
|
|
|
|
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
|
|
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
|
|
|
2021-05-09 19:02:50 +02:00
|
|
|
const now = new Date();
|
2021-05-08 18:49:08 +02:00
|
|
|
|
2021-06-08 12:51:50 +02:00
|
|
|
return `${days[now.getDay()]}, ${now.getDate()} ${months[now.getMonth()]} ${now.getFullYear()}`;
|
2021-05-09 19:02:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const greeter = (): string => {
|
|
|
|
const now = new Date().getHours();
|
|
|
|
let msg: string;
|
2021-05-08 18:49:08 +02:00
|
|
|
|
2021-05-15 18:05:53 +02:00
|
|
|
if (now >= 18) msg = 'Good evening!';
|
|
|
|
else if (now >= 12) msg = 'Good afternoon!';
|
|
|
|
else if (now >= 6) msg = 'Good morning!';
|
|
|
|
else if (now >= 0) msg = 'Good night!';
|
2021-05-13 18:23:12 +02:00
|
|
|
else msg = 'Hello!';
|
2021-05-09 19:02:50 +02:00
|
|
|
|
|
|
|
return msg;
|
2021-05-08 18:49:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container>
|
2021-05-09 19:02:50 +02:00
|
|
|
<header className={classes.Header}>
|
|
|
|
<p>{dateAndTime()}</p>
|
2021-05-23 18:55:27 +02:00
|
|
|
<Link to='/settings' className={classes.SettingsLink}>Go to Settings</Link>
|
2021-05-14 18:51:56 +02:00
|
|
|
<span className={classes.HeaderMain}>
|
|
|
|
<h1>{greeter()}</h1>
|
2021-05-19 18:26:57 +02:00
|
|
|
<WeatherWidget />
|
2021-05-14 18:51:56 +02:00
|
|
|
</span>
|
2021-05-09 19:02:50 +02:00
|
|
|
</header>
|
2021-05-19 18:26:57 +02:00
|
|
|
|
|
|
|
<SectionHeadline title='Applications' link='/applications' />
|
2021-05-23 18:38:39 +02:00
|
|
|
{props.appsLoading
|
2021-05-13 18:23:12 +02:00
|
|
|
? <Spinner />
|
|
|
|
: <AppGrid apps={props.apps.filter((app: App) => app.isPinned)} />
|
|
|
|
}
|
2021-05-09 19:02:50 +02:00
|
|
|
|
2021-06-08 12:51:50 +02:00
|
|
|
<div className={classes.HomeSpace}></div>
|
|
|
|
|
2021-05-13 18:23:12 +02:00
|
|
|
<SectionHeadline title='Bookmarks' link='/bookmarks' />
|
2021-05-23 18:38:39 +02:00
|
|
|
{props.categoriesLoading
|
|
|
|
? <Spinner />
|
|
|
|
: <BookmarkGrid categories={props.categories.filter((category: Category) => category.isPinned)} />
|
|
|
|
}
|
2021-05-09 19:02:50 +02:00
|
|
|
|
2021-05-08 18:49:08 +02:00
|
|
|
<Link to='/settings' className={classes.SettingsButton}>
|
2021-05-23 18:38:39 +02:00
|
|
|
<Icon icon='mdiCog' color='var(--color-background)' />
|
2021-05-08 18:49:08 +02:00
|
|
|
</Link>
|
|
|
|
</Container>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-05-13 18:23:12 +02:00
|
|
|
const mapStateToProps = (state: GlobalState) => {
|
|
|
|
return {
|
2021-05-23 18:38:39 +02:00
|
|
|
appsLoading: state.app.loading,
|
|
|
|
apps: state.app.apps,
|
|
|
|
categoriesLoading: state.bookmark.loading,
|
|
|
|
categories: state.bookmark.categories
|
2021-05-13 18:23:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-23 18:38:39 +02:00
|
|
|
export default connect(mapStateToProps, { getApps, getCategories })(Home);
|