1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-19 19:49:37 +02:00

Added auto-refresh for greeting and date. Fixed multiple React warnings

This commit is contained in:
unknown 2021-06-13 01:06:42 +02:00
parent d257fbf9a3
commit f137498e7e
16 changed files with 121 additions and 59 deletions

View file

@ -62,7 +62,7 @@ docker run -p 5005:5005 -v <host_dir>:/app/data flame
![Homescreen screenshot](./github/_themes.png) ![Homescreen screenshot](./github/_themes.png)
## Usage ## Usage
### Supported links for applications and bookmarks ### Supported URL formats for applications and bookmarks
#### Rules #### Rules
- URL starts with `http://` - URL starts with `http://`
- Format: `http://www.domain.com`, `http://domain.com` - Format: `http://www.domain.com`, `http://domain.com`

View file

@ -5,8 +5,6 @@ import { getConfig, setTheme } from './store/actions';
import { store } from './store/store'; import { store } from './store/store';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import classes from './App.module.css';
import Home from './components/Home/Home'; import Home from './components/Home/Home';
import Apps from './components/Apps/Apps'; import Apps from './components/Apps/Apps';
import Settings from './components/Settings/Settings'; import Settings from './components/Settings/Settings';

View file

@ -13,7 +13,12 @@ const AppCard = (props: ComponentProps): JSX.Element => {
const [displayUrl, redirectUrl] = urlParser(props.app.url); const [displayUrl, redirectUrl] = urlParser(props.app.url);
return ( return (
<a href={redirectUrl} target='_blank' className={classes.AppCard}> <a
href={redirectUrl}
target='_blank'
rel='noreferrer'
className={classes.AppCard}
>
<div className={classes.AppCardIcon}> <div className={classes.AppCardIcon}>
<Icon icon={iconParser(props.app.icon)} /> <Icon icon={iconParser(props.app.icon)} />
</div> </div>

View file

@ -98,7 +98,15 @@ const AppForm = (props: ComponentProps): JSX.Element => {
value={formData.url} value={formData.url}
onChange={(e) => inputChangeHandler(e)} onChange={(e) => inputChangeHandler(e)}
/> />
<span>Only urls without http[s]:// are supported</span> <span>
<a
href='https://github.com/pawelmalak/flame#supported-URL-formats-for-applications-and-bookmarks'
target='_blank'
rel='noreferrer'
>
{' '}Check supported URL formats
</a>
</span>
</InputGroup> </InputGroup>
<InputGroup> <InputGroup>
<label htmlFor='icon'>App Icon</label> <label htmlFor='icon'>App Icon</label>

View file

@ -1,4 +1,4 @@
import { Fragment, useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
// Redux // Redux
@ -30,6 +30,12 @@ interface ComponentProps {
} }
const Apps = (props: ComponentProps): JSX.Element => { const Apps = (props: ComponentProps): JSX.Element => {
const {
getApps,
apps,
loading
} = props;
const [modalIsOpen, setModalIsOpen] = useState(false); const [modalIsOpen, setModalIsOpen] = useState(false);
const [isInEdit, setIsInEdit] = useState(false); const [isInEdit, setIsInEdit] = useState(false);
const [isInUpdate, setIsInUpdate] = useState(false); const [isInUpdate, setIsInUpdate] = useState(false);
@ -44,10 +50,10 @@ const Apps = (props: ComponentProps): JSX.Element => {
}) })
useEffect(() => { useEffect(() => {
if (props.apps.length === 0) { if (apps.length === 0) {
props.getApps(); getApps();
} }
}, [props.getApps]); }, [getApps, apps]);
const toggleModal = (): void => { const toggleModal = (): void => {
setModalIsOpen(!modalIsOpen); setModalIsOpen(!modalIsOpen);
@ -93,10 +99,10 @@ const Apps = (props: ComponentProps): JSX.Element => {
</div> </div>
<div className={classes.Apps}> <div className={classes.Apps}>
{props.loading {loading
? <Spinner /> ? <Spinner />
: (!isInEdit : (!isInEdit
? <AppGrid apps={props.apps} /> ? <AppGrid apps={apps} />
: <AppTable updateAppHandler={toggleUpdate} />) : <AppTable updateAppHandler={toggleUpdate} />)
} }
</div> </div>

View file

@ -14,12 +14,13 @@ const BookmarkCard = (props: ComponentProps): JSX.Element => {
<h3>{props.category.name}</h3> <h3>{props.category.name}</h3>
<div className={classes.Bookmarks}> <div className={classes.Bookmarks}>
{props.category.bookmarks.map((bookmark: Bookmark) => { {props.category.bookmarks.map((bookmark: Bookmark) => {
const [displayUrl, redirectUrl] = urlParser(bookmark.url); const redirectUrl = urlParser(bookmark.url)[1];
return ( return (
<a <a
href={redirectUrl} href={redirectUrl}
target='_blank' target='_blank'
rel='noreferrer'
key={`bookmark-${bookmark.id}`}> key={`bookmark-${bookmark.id}`}>
{bookmark.icon && ( {bookmark.icon && (
<div className={classes.BookmarkIcon}> <div className={classes.BookmarkIcon}>

View file

@ -184,7 +184,15 @@ const BookmarkForm = (props: ComponentProps): JSX.Element => {
value={formData.url} value={formData.url}
onChange={(e) => inputChangeHandler(e)} onChange={(e) => inputChangeHandler(e)}
/> />
<span>Only urls without http[s]:// are supported</span> <span>
<a
href='https://github.com/pawelmalak/flame#supported-URL-formats-for-applications-and-bookmarks'
target='_blank'
rel='noreferrer'
>
{' '}Check supported URL formats
</a>
</span>
</InputGroup> </InputGroup>
<InputGroup> <InputGroup>
<label htmlFor='categoryId'>Bookmark Category</label> <label htmlFor='categoryId'>Bookmark Category</label>

View file

@ -2,7 +2,7 @@ import { Link } from 'react-router-dom';
import classes from './BookmarkGrid.module.css'; import classes from './BookmarkGrid.module.css';
import { Bookmark, Category } from '../../../interfaces'; import { Category } from '../../../interfaces';
import BookmarkCard from '../BookmarkCard/BookmarkCard'; import BookmarkCard from '../BookmarkCard/BookmarkCard';

View file

@ -28,6 +28,12 @@ export enum ContentType {
} }
const Bookmarks = (props: ComponentProps): JSX.Element => { const Bookmarks = (props: ComponentProps): JSX.Element => {
const {
getCategories,
categories,
loading
} = props;
const [modalIsOpen, setModalIsOpen] = useState(false); const [modalIsOpen, setModalIsOpen] = useState(false);
const [formContentType, setFormContentType] = useState(ContentType.category); const [formContentType, setFormContentType] = useState(ContentType.category);
const [isInEdit, setIsInEdit] = useState(false); const [isInEdit, setIsInEdit] = useState(false);
@ -52,10 +58,10 @@ const Bookmarks = (props: ComponentProps): JSX.Element => {
}) })
useEffect(() => { useEffect(() => {
if (props.categories.length === 0) { if (categories.length === 0) {
props.getCategories(); getCategories();
} }
}, [props.getCategories]) }, [getCategories, categories])
const toggleModal = (): void => { const toggleModal = (): void => {
setModalIsOpen(!modalIsOpen); setModalIsOpen(!modalIsOpen);
@ -132,13 +138,13 @@ const Bookmarks = (props: ComponentProps): JSX.Element => {
/> />
</div> </div>
{props.loading {loading
? <Spinner /> ? <Spinner />
: (!isInEdit : (!isInEdit
? <BookmarkGrid categories={props.categories} /> ? <BookmarkGrid categories={categories} />
: <BookmarkTable : <BookmarkTable
contentType={tableContentType} contentType={tableContentType}
categories={props.categories} categories={categories}
updateHandler={goToUpdateMode} updateHandler={goToUpdateMode}
/> />
) )

View file

@ -1,4 +1,4 @@
import { useEffect } from 'react'; import { useState, useEffect } from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
// Redux // Redux
@ -23,6 +23,10 @@ import AppGrid from '../Apps/AppGrid/AppGrid';
import BookmarkGrid from '../Bookmarks/BookmarkGrid/BookmarkGrid'; import BookmarkGrid from '../Bookmarks/BookmarkGrid/BookmarkGrid';
import WeatherWidget from '../Widgets/WeatherWidget/WeatherWidget'; import WeatherWidget from '../Widgets/WeatherWidget/WeatherWidget';
// Functions
import { greeter } from './functions/greeter';
import { dateTime } from './functions/dateTime';
interface ComponentProps { interface ComponentProps {
getApps: Function; getApps: Function;
getCategories: Function; getCategories: Function;
@ -33,68 +37,74 @@ interface ComponentProps {
} }
const Home = (props: ComponentProps): JSX.Element => { const Home = (props: ComponentProps): JSX.Element => {
const {
getApps,
apps,
appsLoading,
getCategories,
categories,
categoriesLoading
} = props;
const [header, setHeader] = useState({
dateTime: dateTime(),
greeting: greeter()
})
// Load applications
useEffect(() => { useEffect(() => {
if (props.apps.length === 0) { if (apps.length === 0) {
props.getApps(); getApps();
} }
}, [props.getApps]); }, [getApps, apps]);
// Load bookmark categories
useEffect(() => { useEffect(() => {
if (props.categories.length === 0) { if (categories.length === 0) {
props.getCategories(); getCategories();
} }
}, [props.getCategories]); }, [getCategories, categories]);
const dateAndTime = (): string => { // Refresh greeter and time
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; useEffect(() => {
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; const interval = setInterval(() => {
setHeader({
dateTime: dateTime(),
greeting: greeter()
})
}, 1000);
const now = new Date(); return () => clearInterval(interval);
}, [])
return `${days[now.getDay()]}, ${now.getDate()} ${months[now.getMonth()]} ${now.getFullYear()}`;
}
const greeter = (): string => {
const now = new Date().getHours();
let msg: string;
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!';
else msg = 'Hello!';
return msg;
}
return ( return (
<Container> <Container>
<header className={classes.Header}> <header className={classes.Header}>
<p>{dateAndTime()}</p> <p>{header.dateTime}</p>
<Link to='/settings' className={classes.SettingsLink}>Go to Settings</Link> <Link to='/settings' className={classes.SettingsLink}>Go to Settings</Link>
<span className={classes.HeaderMain}> <span className={classes.HeaderMain}>
<h1>{greeter()}</h1> <h1>{header.greeting}</h1>
<WeatherWidget /> <WeatherWidget />
</span> </span>
</header> </header>
<SectionHeadline title='Applications' link='/applications' /> <SectionHeadline title='Applications' link='/applications' />
{props.appsLoading {appsLoading
? <Spinner /> ? <Spinner />
: <AppGrid : <AppGrid
apps={props.apps.filter((app: App) => app.isPinned)} apps={apps.filter((app: App) => app.isPinned)}
totalApps={props.apps.length} totalApps={apps.length}
/> />
} }
<div className={classes.HomeSpace}></div> <div className={classes.HomeSpace}></div>
<SectionHeadline title='Bookmarks' link='/bookmarks' /> <SectionHeadline title='Bookmarks' link='/bookmarks' />
{props.categoriesLoading {categoriesLoading
? <Spinner /> ? <Spinner />
: <BookmarkGrid : <BookmarkGrid
categories={props.categories.filter((category: Category) => category.isPinned)} categories={categories.filter((category: Category) => category.isPinned)}
totalCategories={props.categories.length} totalCategories={categories.length}
/> />
} }

View file

@ -0,0 +1,8 @@
export const dateTime = (): string => {
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
const now = new Date();
return `${days[now.getDay()]}, ${now.getDate()} ${months[now.getMonth()]} ${now.getFullYear()}`;
}

View file

@ -0,0 +1,12 @@
export const greeter = (): string => {
const now = new Date().getHours();
let msg: string;
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!';
else msg = 'Hello!';
return msg;
}

View file

@ -1,4 +1,4 @@
import { MouseEvent, useRef, useEffect } from 'react'; import { MouseEvent, useRef } from 'react';
import classes from './Modal.module.css'; import classes from './Modal.module.css';

View file

@ -89,7 +89,7 @@ export interface DeleteAppAction {
export const deleteApp = (id: number) => async (dispatch: Dispatch) => { export const deleteApp = (id: number) => async (dispatch: Dispatch) => {
try { try {
const res = await axios.delete<ApiResponse<{}>>(`/api/apps/${id}`); await axios.delete<ApiResponse<{}>>(`/api/apps/${id}`);
dispatch<CreateNotificationAction>({ dispatch<CreateNotificationAction>({
type: ActionTypes.createNotification, type: ActionTypes.createNotification,

View file

@ -130,7 +130,7 @@ export interface DeleteCategoryAction {
export const deleteCategory = (id: number) => async (dispatch: Dispatch) => { export const deleteCategory = (id: number) => async (dispatch: Dispatch) => {
try { try {
const res = await axios.delete<ApiResponse<{}>>(`/api/categories/${id}`); await axios.delete<ApiResponse<{}>>(`/api/categories/${id}`);
dispatch<CreateNotificationAction>({ dispatch<CreateNotificationAction>({
type: ActionTypes.createNotification, type: ActionTypes.createNotification,
@ -191,7 +191,7 @@ export interface DeleteBookmarkAction {
export const deleteBookmark = (bookmarkId: number, categoryId: number) => async (dispatch: Dispatch) => { export const deleteBookmark = (bookmarkId: number, categoryId: number) => async (dispatch: Dispatch) => {
try { try {
const res = await axios.delete<ApiResponse<{}>>(`/api/bookmarks/${bookmarkId}`); await axios.delete<ApiResponse<{}>>(`/api/bookmarks/${bookmarkId}`);
dispatch<CreateNotificationAction>({ dispatch<CreateNotificationAction>({
type: ActionTypes.createNotification, type: ActionTypes.createNotification,