mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-25 22:09:36 +02:00
parent
6f44200a3c
commit
31cf2bc5ad
24 changed files with 1772 additions and 939 deletions
|
@ -1,10 +1,15 @@
|
|||
.AppCard {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.AppCard h3 {
|
||||
color: var(--color-accent);
|
||||
margin-bottom: 10px;
|
||||
font-size: 16px;
|
||||
font-weight: 400;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.AppCardIcon {
|
||||
width: 35px;
|
||||
height: 35px;
|
||||
|
@ -19,7 +24,7 @@
|
|||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
color: var(--color-primary);
|
||||
margin-bottom: -4px;
|
||||
margin-bottom: -10px;
|
||||
}
|
||||
|
||||
.AppCardDetails span {
|
||||
|
@ -29,16 +34,24 @@
|
|||
opacity: 1;
|
||||
}
|
||||
|
||||
@media (min-width: 500px) {
|
||||
.AppCard {
|
||||
padding: 2px;
|
||||
border-radius: 4px;
|
||||
transition: all 0.1s;
|
||||
}
|
||||
.Apps {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 2px;
|
||||
border-radius: 4px;
|
||||
transition: all 0.1s;
|
||||
}
|
||||
|
||||
.AppCard:hover {
|
||||
background-color: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
.Apps a {
|
||||
line-height: 2;
|
||||
transition: all 0.25s;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.Apps a:hover {
|
||||
background-color: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.CustomIcon {
|
||||
|
|
|
@ -1,57 +1,64 @@
|
|||
import classes from './AppCard.module.css';
|
||||
import Icon from '../../UI/Icons/Icon/Icon';
|
||||
import { App, Category } from '../../../interfaces';
|
||||
import { iconParser, urlParser } from '../../../utility';
|
||||
|
||||
import { App } from '../../../interfaces';
|
||||
import { searchConfig } from '../../../utility';
|
||||
import Icon from '../../UI/Icons/Icon/Icon';
|
||||
import classes from './AppCard.module.css';
|
||||
|
||||
interface ComponentProps {
|
||||
app: App;
|
||||
category: Category;
|
||||
apps: App[]
|
||||
pinHandler?: Function;
|
||||
}
|
||||
|
||||
const AppCard = (props: ComponentProps): JSX.Element => {
|
||||
const [displayUrl, redirectUrl] = urlParser(props.app.url);
|
||||
|
||||
let iconEl: JSX.Element;
|
||||
const { icon } = props.app;
|
||||
|
||||
if (/.(jpeg|jpg|png)$/i.test(icon)) {
|
||||
iconEl = (
|
||||
<img
|
||||
src={`/uploads/${icon}`}
|
||||
alt={`${props.app.name} icon`}
|
||||
className={classes.CustomIcon}
|
||||
/>
|
||||
);
|
||||
} else if (/.(svg)$/i.test(icon)) {
|
||||
iconEl = (
|
||||
<div className={classes.CustomIcon}>
|
||||
<svg
|
||||
data-src={`/uploads/${icon}`}
|
||||
fill='var(--color-primary)'
|
||||
className={classes.CustomIcon}
|
||||
></svg>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
iconEl = <Icon icon={iconParser(icon)} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<a
|
||||
href={redirectUrl}
|
||||
target={searchConfig('appsSameTab', false) ? '' : '_blank'}
|
||||
rel='noreferrer'
|
||||
className={classes.AppCard}
|
||||
>
|
||||
<div className={classes.AppCardIcon}>{iconEl}</div>
|
||||
<div className={classes.AppCardDetails}>
|
||||
<h5>{props.app.name}</h5>
|
||||
<span>{displayUrl}</span>
|
||||
<div className={classes.AppCard}>
|
||||
<h3>{props.category.name}</h3>
|
||||
<div className={classes.Apps}>
|
||||
{props.apps.map((app: App) => {
|
||||
const [displayUrl, redirectUrl] = urlParser(app.url);
|
||||
|
||||
let iconEl: JSX.Element;
|
||||
const { icon } = app;
|
||||
|
||||
if (/.(jpeg|jpg|png)$/i.test(icon)) {
|
||||
iconEl = (
|
||||
<img
|
||||
src={`/uploads/${icon}`}
|
||||
alt={`${app.name} icon`}
|
||||
className={classes.CustomIcon}
|
||||
/>
|
||||
);
|
||||
} else if (/.(svg)$/i.test(icon)) {
|
||||
iconEl = (
|
||||
<div className={classes.CustomIcon}>
|
||||
<svg
|
||||
data-src={`/uploads/${icon}`}
|
||||
fill='var(--color-primary)'
|
||||
className={classes.CustomIcon}
|
||||
></svg>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
iconEl = <Icon icon={iconParser(icon)} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<a
|
||||
href={redirectUrl}
|
||||
target='_blank'
|
||||
rel='noreferrer'
|
||||
key={`app-${app.id}`}>
|
||||
<div className={classes.AppCardIcon}>{iconEl}</div>
|
||||
<div className={classes.AppCardDetails}>
|
||||
<h5>{app.name}</h5>
|
||||
<span>{displayUrl}</span>
|
||||
</div>
|
||||
</a>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</a>
|
||||
);
|
||||
};
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default AppCard;
|
||||
|
|
|
@ -1,59 +1,77 @@
|
|||
import { useState, useEffect, ChangeEvent, SyntheticEvent } from 'react';
|
||||
import { ChangeEvent, Dispatch, Fragment, SetStateAction, SyntheticEvent, useEffect, useState } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { addApp, updateApp } from '../../../store/actions';
|
||||
import { App, NewApp } from '../../../interfaces';
|
||||
|
||||
import classes from './AppForm.module.css';
|
||||
|
||||
import ModalForm from '../../UI/Forms/ModalForm/ModalForm';
|
||||
import InputGroup from '../../UI/Forms/InputGroup/InputGroup';
|
||||
import { App, Category, GlobalState, NewApp, NewCategory, NewNotification } from '../../../interfaces';
|
||||
import {
|
||||
addApp,
|
||||
addAppCategory,
|
||||
createNotification,
|
||||
getAppCategories,
|
||||
updateApp,
|
||||
updateAppCategory,
|
||||
} from '../../../store/actions';
|
||||
import Button from '../../UI/Buttons/Button/Button';
|
||||
import InputGroup from '../../UI/Forms/InputGroup/InputGroup';
|
||||
import ModalForm from '../../UI/Forms/ModalForm/ModalForm';
|
||||
import { ContentType } from '../Apps';
|
||||
import classes from './AppForm.module.css';
|
||||
|
||||
interface ComponentProps {
|
||||
modalHandler: () => void;
|
||||
addApp: (formData: NewApp | FormData) => any;
|
||||
updateApp: (id: number, formData: NewApp | FormData) => any;
|
||||
contentType: ContentType;
|
||||
categories: Category[];
|
||||
category?: Category;
|
||||
app?: App;
|
||||
addAppCategory: (formData: NewCategory) => void;
|
||||
addApp: (formData: NewApp | FormData) => void;
|
||||
updateAppCategory: (id: number, formData: NewCategory) => void;
|
||||
updateApp: (id: number, formData: NewApp | FormData, previousCategoryId: number) => void;
|
||||
createNotification: (notification: NewNotification) => void;
|
||||
}
|
||||
|
||||
const AppForm = (props: ComponentProps): JSX.Element => {
|
||||
const [useCustomIcon, toggleUseCustomIcon] = useState<boolean>(false);
|
||||
const [customIcon, setCustomIcon] = useState<File | null>(null);
|
||||
const [formData, setFormData] = useState<NewApp>({
|
||||
const [categoryData, setCategoryData] = useState<NewCategory>({
|
||||
name: '',
|
||||
type: 'apps'
|
||||
})
|
||||
|
||||
const [appData, setAppData] = useState<NewApp>({
|
||||
name: '',
|
||||
url: '',
|
||||
categoryId: -1,
|
||||
icon: '',
|
||||
});
|
||||
|
||||
// Load category data if provided for editing
|
||||
useEffect(() => {
|
||||
if (props.category) {
|
||||
setCategoryData({ name: props.category.name, type: props.category.type });
|
||||
} else {
|
||||
setCategoryData({ name: '', type: "apps" });
|
||||
}
|
||||
}, [props.category]);
|
||||
|
||||
// Load app data if provided for editing
|
||||
useEffect(() => {
|
||||
if (props.app) {
|
||||
setFormData({
|
||||
setAppData({
|
||||
name: props.app.name,
|
||||
url: props.app.url,
|
||||
categoryId: props.app.categoryId,
|
||||
icon: props.app.icon,
|
||||
});
|
||||
} else {
|
||||
setFormData({
|
||||
setAppData({
|
||||
name: '',
|
||||
url: '',
|
||||
categoryId: -1,
|
||||
icon: '',
|
||||
});
|
||||
}
|
||||
}, [props.app]);
|
||||
|
||||
const inputChangeHandler = (e: ChangeEvent<HTMLInputElement>): void => {
|
||||
setFormData({
|
||||
...formData,
|
||||
[e.target.name]: e.target.value,
|
||||
});
|
||||
};
|
||||
|
||||
const fileChangeHandler = (e: ChangeEvent<HTMLInputElement>): void => {
|
||||
if (e.target.files) {
|
||||
setCustomIcon(e.target.files[0]);
|
||||
}
|
||||
};
|
||||
|
||||
const formSubmitHandler = (e: SyntheticEvent<HTMLFormElement>): void => {
|
||||
e.preventDefault();
|
||||
|
||||
|
@ -63,132 +81,241 @@ const AppForm = (props: ComponentProps): JSX.Element => {
|
|||
if (customIcon) {
|
||||
data.append('icon', customIcon);
|
||||
}
|
||||
data.append('name', formData.name);
|
||||
data.append('url', formData.url);
|
||||
data.append('name', appData.name);
|
||||
data.append('url', appData.url);
|
||||
data.append('categoryId', appData.categoryId.toString());
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
if (!props.app) {
|
||||
if (customIcon) {
|
||||
const data = createFormData();
|
||||
props.addApp(data);
|
||||
} else {
|
||||
props.addApp(formData);
|
||||
if (!props.category && !props.app) {
|
||||
// Add new
|
||||
if (props.contentType === ContentType.category) {
|
||||
// Add category
|
||||
props.addAppCategory(categoryData);
|
||||
setCategoryData({ name: '', type: 'apps' });
|
||||
} else if (props.contentType === ContentType.app) {
|
||||
// Add app
|
||||
if (appData.categoryId === -1) {
|
||||
props.createNotification({
|
||||
title: 'Error',
|
||||
message: 'Please select category'
|
||||
})
|
||||
return;
|
||||
}
|
||||
if (customIcon) {
|
||||
const data = createFormData();
|
||||
props.addApp(data);
|
||||
} else {
|
||||
props.addApp(appData);
|
||||
}
|
||||
setAppData({
|
||||
name: '',
|
||||
url: '',
|
||||
categoryId: appData.categoryId,
|
||||
icon: ''
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if (customIcon) {
|
||||
const data = createFormData();
|
||||
props.updateApp(props.app.id, data);
|
||||
} else {
|
||||
props.updateApp(props.app.id, formData);
|
||||
props.modalHandler();
|
||||
// Update
|
||||
if (props.contentType === ContentType.category && props.category) {
|
||||
// Update category
|
||||
props.updateAppCategory(props.category.id, categoryData);
|
||||
setCategoryData({ name: '', type: 'apps' });
|
||||
} else if (props.contentType === ContentType.app && props.app) {
|
||||
// Update app
|
||||
if (customIcon) {
|
||||
const data = createFormData();
|
||||
props.updateApp(props.app.id, data, props.app.categoryId);
|
||||
} else {
|
||||
props.updateApp(props.app.id, appData, props.app.categoryId);
|
||||
props.modalHandler();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setFormData({
|
||||
name: '',
|
||||
url: '',
|
||||
icon: '',
|
||||
});
|
||||
};
|
||||
setAppData({
|
||||
name: '',
|
||||
url: '',
|
||||
categoryId: -1,
|
||||
icon: ''
|
||||
});
|
||||
|
||||
setCustomIcon(null);
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeHandler = (e: ChangeEvent<HTMLInputElement | HTMLSelectElement>, setDataFunction: Dispatch<SetStateAction<any>>, data: any): void => {
|
||||
setDataFunction({
|
||||
...data,
|
||||
[e.target.name]: e.target.value
|
||||
})
|
||||
}
|
||||
|
||||
const fileChangeHandler = (e: ChangeEvent<HTMLInputElement>): void => {
|
||||
if (e.target.files) {
|
||||
setCustomIcon(e.target.files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
let button = <Button>Submit</Button>
|
||||
|
||||
if (!props.category && !props.app) {
|
||||
if (props.contentType === ContentType.category) {
|
||||
button = <Button>Add new category</Button>;
|
||||
} else {
|
||||
button = <Button>Add new app</Button>;
|
||||
}
|
||||
} else if (props.category) {
|
||||
button = <Button>Update category</Button>
|
||||
} else if (props.app) {
|
||||
button = <Button>Update app</Button>
|
||||
}
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
modalHandler={props.modalHandler}
|
||||
formHandler={formSubmitHandler}
|
||||
>
|
||||
<InputGroup>
|
||||
<label htmlFor="name">App Name</label>
|
||||
<input
|
||||
type="text"
|
||||
name="name"
|
||||
id="name"
|
||||
placeholder="Bookstack"
|
||||
required
|
||||
value={formData.name}
|
||||
onChange={(e) => inputChangeHandler(e)}
|
||||
/>
|
||||
</InputGroup>
|
||||
<InputGroup>
|
||||
<label htmlFor="url">App URL</label>
|
||||
<input
|
||||
type="text"
|
||||
name="url"
|
||||
id="url"
|
||||
placeholder="bookstack.example.com"
|
||||
required
|
||||
value={formData.url}
|
||||
onChange={(e) => inputChangeHandler(e)}
|
||||
/>
|
||||
<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>
|
||||
{!useCustomIcon ? (
|
||||
// use mdi icon
|
||||
<InputGroup>
|
||||
<label htmlFor="icon">App Icon</label>
|
||||
<input
|
||||
type="text"
|
||||
name="icon"
|
||||
id="icon"
|
||||
placeholder="book-open-outline"
|
||||
required
|
||||
value={formData.icon}
|
||||
onChange={(e) => inputChangeHandler(e)}
|
||||
/>
|
||||
<span>
|
||||
Use icon name from MDI.
|
||||
<a href="https://materialdesignicons.com/" target="blank">
|
||||
{' '}
|
||||
Click here for reference
|
||||
</a>
|
||||
</span>
|
||||
<span
|
||||
onClick={() => toggleUseCustomIcon(!useCustomIcon)}
|
||||
className={classes.Switch}
|
||||
>
|
||||
Switch to custom icon upload
|
||||
</span>
|
||||
</InputGroup>
|
||||
) : (
|
||||
// upload custom icon
|
||||
<InputGroup>
|
||||
<label htmlFor="icon">App Icon</label>
|
||||
<input
|
||||
type="file"
|
||||
name="icon"
|
||||
id="icon"
|
||||
required
|
||||
onChange={(e) => fileChangeHandler(e)}
|
||||
accept=".jpg,.jpeg,.png,.svg"
|
||||
/>
|
||||
<span
|
||||
onClick={() => {
|
||||
setCustomIcon(null);
|
||||
toggleUseCustomIcon(!useCustomIcon);
|
||||
}}
|
||||
className={classes.Switch}
|
||||
>
|
||||
Switch to MDI
|
||||
</span>
|
||||
</InputGroup>
|
||||
)}
|
||||
{!props.app ? (
|
||||
<Button>Add new application</Button>
|
||||
) : (
|
||||
<Button>Update application</Button>
|
||||
)}
|
||||
{props.contentType === ContentType.category
|
||||
? (
|
||||
<Fragment>
|
||||
<InputGroup>
|
||||
<label htmlFor='categoryName'>Category Name</label>
|
||||
<input
|
||||
type='text'
|
||||
name='name'
|
||||
id='categoryName'
|
||||
placeholder='Social Media'
|
||||
required
|
||||
value={categoryData.name}
|
||||
onChange={(e) => inputChangeHandler(e, setCategoryData, categoryData)}
|
||||
/>
|
||||
</InputGroup>
|
||||
</Fragment>
|
||||
)
|
||||
: (
|
||||
<Fragment>
|
||||
<InputGroup>
|
||||
<label htmlFor='name'>App Name</label>
|
||||
<input
|
||||
type='text'
|
||||
name='name'
|
||||
id='name'
|
||||
placeholder='Bookstack'
|
||||
required
|
||||
value={appData.name}
|
||||
onChange={(e) => inputChangeHandler(e, setAppData, appData)}
|
||||
/>
|
||||
</InputGroup>
|
||||
<InputGroup>
|
||||
<label htmlFor='url'>App URL</label>
|
||||
<input
|
||||
type='text'
|
||||
name='url'
|
||||
id='url'
|
||||
placeholder='bookstack.example.com'
|
||||
required
|
||||
value={appData.url}
|
||||
onChange={(e) => inputChangeHandler(e, setAppData, appData)}
|
||||
/>
|
||||
<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>
|
||||
<label htmlFor='categoryId'>App Category</label>
|
||||
<select
|
||||
name='categoryId'
|
||||
id='categoryId'
|
||||
required
|
||||
onChange={(e) => inputChangeHandler(e, setAppData, appData)}
|
||||
value={appData.categoryId}
|
||||
>
|
||||
<option value={-1}>Select category</option>
|
||||
{props.categories.map((category: Category): JSX.Element => {
|
||||
return (
|
||||
<option
|
||||
key={category.id}
|
||||
value={category.id}
|
||||
>
|
||||
{category.name}
|
||||
</option>
|
||||
)
|
||||
})}
|
||||
</select>
|
||||
</InputGroup>
|
||||
{!useCustomIcon
|
||||
// use mdi icon
|
||||
? (<InputGroup>
|
||||
<label htmlFor='icon'>App Icon</label>
|
||||
<input
|
||||
type='text'
|
||||
name='icon'
|
||||
id='icon'
|
||||
placeholder='book-open-outline'
|
||||
required
|
||||
value={appData.icon}
|
||||
onChange={(e) => inputChangeHandler(e, setAppData, appData)}
|
||||
/>
|
||||
<span>
|
||||
Use icon name from MDI.
|
||||
<a
|
||||
href='https://materialdesignicons.com/'
|
||||
target='blank'>
|
||||
{' '}Click here for reference
|
||||
</a>
|
||||
</span>
|
||||
<span
|
||||
onClick={() => toggleUseCustomIcon(!useCustomIcon)}
|
||||
className={classes.Switch}>
|
||||
Switch to custom icon upload
|
||||
</span>
|
||||
</InputGroup>)
|
||||
// upload custom icon
|
||||
: (<InputGroup>
|
||||
<label htmlFor='icon'>App Icon</label>
|
||||
<input
|
||||
type='file'
|
||||
name='icon'
|
||||
id='icon'
|
||||
required
|
||||
onChange={(e) => fileChangeHandler(e)}
|
||||
accept=".jpg,.jpeg,.png,.svg"
|
||||
/>
|
||||
<span
|
||||
onClick={() => toggleUseCustomIcon(!useCustomIcon)}
|
||||
className={classes.Switch}>
|
||||
Switch to MDI
|
||||
</span>
|
||||
</InputGroup>)
|
||||
}
|
||||
</Fragment>
|
||||
)
|
||||
}
|
||||
{button}
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default connect(null, { addApp, updateApp })(AppForm);
|
||||
const mapStateToProps = (state: GlobalState) => {
|
||||
return {
|
||||
categories: state.app.categories
|
||||
}
|
||||
}
|
||||
|
||||
const dispatchMap = {
|
||||
getAppCategories,
|
||||
addAppCategory,
|
||||
addApp,
|
||||
updateAppCategory,
|
||||
updateApp,
|
||||
createNotification
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, dispatchMap)(AppForm);
|
||||
|
|
|
@ -1,28 +1,29 @@
|
|||
import classes from './AppGrid.module.css';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { App } from '../../../interfaces/App';
|
||||
|
||||
import { App, Category } from '../../../interfaces';
|
||||
import AppCard from '../AppCard/AppCard';
|
||||
import classes from './AppGrid.module.css';
|
||||
|
||||
interface ComponentProps {
|
||||
apps: App[];
|
||||
totalApps?: number;
|
||||
categories: Category[];
|
||||
apps: App[]
|
||||
totalCategories?: number;
|
||||
searching: boolean;
|
||||
}
|
||||
|
||||
const AppGrid = (props: ComponentProps): JSX.Element => {
|
||||
let apps: JSX.Element;
|
||||
|
||||
if (props.apps.length > 0) {
|
||||
if (props.categories.length > 0) {
|
||||
apps = (
|
||||
<div className={classes.AppGrid}>
|
||||
{props.apps.map((app: App): JSX.Element => {
|
||||
return <AppCard key={app.id} app={app} />;
|
||||
{props.categories.map((category: Category): JSX.Element => {
|
||||
return <AppCard key={category.id} category={category} apps={props.apps.filter((app: App) => app.categoryId === category.id)} />
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
if (props.totalApps) {
|
||||
if (props.totalCategories) {
|
||||
if (props.searching) {
|
||||
apps = (
|
||||
<p className={classes.AppsMessage}>
|
||||
|
@ -32,7 +33,7 @@ const AppGrid = (props: ComponentProps): JSX.Element => {
|
|||
} else {
|
||||
apps = (
|
||||
<p className={classes.AppsMessage}>
|
||||
There are no pinned applications. You can pin them from the{' '}
|
||||
There are no pinned application categories. You can pin them from the{' '}
|
||||
<Link to="/applications">/applications</Link> menu
|
||||
</p>
|
||||
);
|
||||
|
@ -40,7 +41,7 @@ const AppGrid = (props: ComponentProps): JSX.Element => {
|
|||
} else {
|
||||
apps = (
|
||||
<p className={classes.AppsMessage}>
|
||||
You don't have any applications. You can add a new one from{' '}
|
||||
You don't have any applications. You can add a new one from the{' '}
|
||||
<Link to="/applications">/applications</Link> menu
|
||||
</p>
|
||||
);
|
||||
|
|
|
@ -1,73 +1,101 @@
|
|||
import { Fragment, KeyboardEvent, useState, useEffect } from 'react';
|
||||
import { DragDropContext, Droppable, Draggable, DropResult } from 'react-beautiful-dnd';
|
||||
import { Fragment, KeyboardEvent, useEffect, useState } from 'react';
|
||||
import { DragDropContext, Draggable, Droppable, DropResult } from 'react-beautiful-dnd';
|
||||
import { connect } from 'react-redux';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
// Redux
|
||||
import { connect } from 'react-redux';
|
||||
import { pinApp, deleteApp, reorderApps, updateConfig, createNotification } from '../../../store/actions';
|
||||
|
||||
// Typescript
|
||||
import { App, GlobalState, NewNotification } from '../../../interfaces';
|
||||
|
||||
// CSS
|
||||
import classes from './AppTable.module.css';
|
||||
|
||||
// UI
|
||||
import { App, Category, NewNotification } from '../../../interfaces';
|
||||
import {
|
||||
createNotification,
|
||||
deleteApp,
|
||||
deleteAppCategory,
|
||||
pinApp,
|
||||
pinAppCategory,
|
||||
reorderAppCategories,
|
||||
reorderApps,
|
||||
updateConfig,
|
||||
} from '../../../store/actions';
|
||||
import { searchConfig } from '../../../utility';
|
||||
import Icon from '../../UI/Icons/Icon/Icon';
|
||||
import Table from '../../UI/Table/Table';
|
||||
|
||||
// Utils
|
||||
import { searchConfig } from '../../../utility';
|
||||
import { ContentType } from '../Apps';
|
||||
import classes from './AppTable.module.css';
|
||||
|
||||
interface ComponentProps {
|
||||
contentType: ContentType;
|
||||
categories: Category[];
|
||||
apps: App[];
|
||||
pinAppCategory: (category: Category) => void;
|
||||
deleteAppCategory: (id: number) => void;
|
||||
reorderAppCategories: (categories: Category[]) => void;
|
||||
updateHandler: (data: Category | App) => void;
|
||||
pinApp: (app: App) => void;
|
||||
deleteApp: (id: number) => void;
|
||||
updateAppHandler: (app: App) => void;
|
||||
reorderApps: (apps: App[]) => void;
|
||||
updateConfig: (formData: any) => void;
|
||||
createNotification: (notification: NewNotification) => void;
|
||||
}
|
||||
|
||||
const AppTable = (props: ComponentProps): JSX.Element => {
|
||||
const [localCategories, setLocalCategories] = useState<Category[]>([]);
|
||||
const [localApps, setLocalApps] = useState<App[]>([]);
|
||||
const [isCustomOrder, setIsCustomOrder] = useState<boolean>(false);
|
||||
|
||||
// Copy categories array
|
||||
useEffect(() => {
|
||||
setLocalCategories([...props.categories]);
|
||||
}, [props.categories]);
|
||||
|
||||
// Copy apps array
|
||||
useEffect(() => {
|
||||
setLocalApps([...props.apps]);
|
||||
}, [props.apps])
|
||||
}, [props.apps]);
|
||||
|
||||
// Check ordering
|
||||
useEffect(() => {
|
||||
const order = searchConfig('useOrdering', '');
|
||||
const order = searchConfig("useOrdering", "");
|
||||
|
||||
if (order === 'orderId') {
|
||||
if (order === "orderId") {
|
||||
setIsCustomOrder(true);
|
||||
}
|
||||
}, [])
|
||||
}, []);
|
||||
|
||||
const deleteCategoryHandler = (category: Category): void => {
|
||||
const proceed = window.confirm(
|
||||
`Are you sure you want to delete ${category.name}? It will delete ALL assigned apps`
|
||||
);
|
||||
|
||||
if (proceed) {
|
||||
props.deleteAppCategory(category.id);
|
||||
}
|
||||
};
|
||||
|
||||
const deleteAppHandler = (app: App): void => {
|
||||
const proceed = window.confirm(`Are you sure you want to delete ${app.name} at ${app.url} ?`);
|
||||
const proceed = window.confirm(
|
||||
`Are you sure you want to delete ${app.name} at ${app.url} ?`
|
||||
);
|
||||
|
||||
if (proceed) {
|
||||
props.deleteApp(app.id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Support keyboard navigation for actions
|
||||
const keyboardActionHandler = (e: KeyboardEvent, app: App, handler: Function) => {
|
||||
if (e.key === 'Enter') {
|
||||
handler(app);
|
||||
const keyboardActionHandler = (
|
||||
e: KeyboardEvent,
|
||||
object: any,
|
||||
handler: Function
|
||||
) => {
|
||||
if (e.key === "Enter") {
|
||||
handler(object);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const dragEndHanlder = (result: DropResult): void => {
|
||||
const dragEndHandler = (result: DropResult): void => {
|
||||
if (!isCustomOrder) {
|
||||
props.createNotification({
|
||||
title: 'Error',
|
||||
message: 'Custom order is disabled'
|
||||
})
|
||||
title: "Error",
|
||||
message: "Custom order is disabled",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -75,106 +103,251 @@ const AppTable = (props: ComponentProps): JSX.Element => {
|
|||
return;
|
||||
}
|
||||
|
||||
const tmpApps = [...localApps];
|
||||
const [movedApp] = tmpApps.splice(result.source.index, 1);
|
||||
tmpApps.splice(result.destination.index, 0, movedApp);
|
||||
if (props.contentType === ContentType.app) {
|
||||
const tmpApps = [...localApps];
|
||||
const [movedApp] = tmpApps.splice(result.source.index, 1);
|
||||
tmpApps.splice(result.destination.index, 0, movedApp);
|
||||
|
||||
setLocalApps(tmpApps);
|
||||
props.reorderApps(tmpApps);
|
||||
}
|
||||
setLocalApps(tmpApps);
|
||||
props.reorderApps(tmpApps);
|
||||
} else if (props.contentType === ContentType.category) {
|
||||
const tmpCategories = [...localCategories];
|
||||
const [movedCategory] = tmpCategories.splice(result.source.index, 1);
|
||||
tmpCategories.splice(result.destination.index, 0, movedCategory);
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<div className={classes.Message}>
|
||||
{isCustomOrder
|
||||
? <p>You can drag and drop single rows to reorder application</p>
|
||||
: <p>Custom order is disabled. You can change it in <Link to='/settings/other'>settings</Link></p>
|
||||
}
|
||||
</div>
|
||||
<DragDropContext onDragEnd={dragEndHanlder}>
|
||||
<Droppable droppableId='apps'>
|
||||
{(provided) => (
|
||||
<Table headers={[
|
||||
'Name',
|
||||
'URL',
|
||||
'Icon',
|
||||
'Actions'
|
||||
]}
|
||||
innerRef={provided.innerRef}>
|
||||
{localApps.map((app: App, index): JSX.Element => {
|
||||
return (
|
||||
<Draggable key={app.id} draggableId={app.id.toString()} index={index}>
|
||||
{(provided, snapshot) => {
|
||||
const style = {
|
||||
border: snapshot.isDragging ? '1px solid var(--color-accent)' : 'none',
|
||||
borderRadius: '4px',
|
||||
...provided.draggableProps.style,
|
||||
};
|
||||
|
||||
return (
|
||||
<tr
|
||||
{...provided.draggableProps}
|
||||
{...provided.dragHandleProps}
|
||||
ref={provided.innerRef}
|
||||
style={style}
|
||||
>
|
||||
<td style={{ width:'200px' }}>{app.name}</td>
|
||||
<td style={{ width:'200px' }}>{app.url}</td>
|
||||
<td style={{ width:'200px' }}>{app.icon}</td>
|
||||
{!snapshot.isDragging && (
|
||||
<td className={classes.TableActions}>
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() => deleteAppHandler(app)}
|
||||
onKeyDown={(e) => keyboardActionHandler(e, app, deleteAppHandler)}
|
||||
tabIndex={0}>
|
||||
<Icon icon='mdiDelete' />
|
||||
</div>
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() => props.updateAppHandler(app)}
|
||||
onKeyDown={(e) => keyboardActionHandler(e, app, props.updateAppHandler)}
|
||||
tabIndex={0}>
|
||||
<Icon icon='mdiPencil' />
|
||||
</div>
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() => props.pinApp(app)}
|
||||
onKeyDown={(e) => keyboardActionHandler(e, app, props.pinApp)}
|
||||
tabIndex={0}>
|
||||
{app.isPinned
|
||||
? <Icon icon='mdiPinOff' color='var(--color-accent)' />
|
||||
: <Icon icon='mdiPin' />
|
||||
}
|
||||
</div>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
)
|
||||
}}
|
||||
</Draggable>
|
||||
)
|
||||
})}
|
||||
</Table>
|
||||
setLocalCategories(tmpCategories);
|
||||
props.reorderAppCategories(tmpCategories);
|
||||
}
|
||||
};
|
||||
|
||||
if (props.contentType === ContentType.category) {
|
||||
return (
|
||||
<Fragment>
|
||||
<div className={classes.Message}>
|
||||
{isCustomOrder ? (
|
||||
<p>You can drag and drop single rows to reorder categories</p>
|
||||
) : (
|
||||
<p>
|
||||
Custom order is disabled. You can change it in{" "}
|
||||
<Link to="/settings/other">settings</Link>
|
||||
</p>
|
||||
)}
|
||||
</Droppable>
|
||||
</DragDropContext>
|
||||
</Fragment>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
<DragDropContext onDragEnd={dragEndHandler}>
|
||||
<Droppable droppableId="categories">
|
||||
{(provided) => (
|
||||
<Table headers={["Name", "Actions"]} innerRef={provided.innerRef}>
|
||||
{localCategories.map(
|
||||
(category: Category, index): JSX.Element => {
|
||||
return (
|
||||
<Draggable
|
||||
key={category.id}
|
||||
draggableId={category.id.toString()}
|
||||
index={index}
|
||||
>
|
||||
{(provided, snapshot) => {
|
||||
const style = {
|
||||
border: snapshot.isDragging
|
||||
? "1px solid var(--color-accent)"
|
||||
: "none",
|
||||
borderRadius: "4px",
|
||||
...provided.draggableProps.style,
|
||||
};
|
||||
|
||||
const mapStateToProps = (state: GlobalState) => {
|
||||
return {
|
||||
apps: state.app.apps
|
||||
return (
|
||||
<tr
|
||||
{...provided.draggableProps}
|
||||
{...provided.dragHandleProps}
|
||||
ref={provided.innerRef}
|
||||
style={style}
|
||||
>
|
||||
<td>{category.name}</td>
|
||||
{!snapshot.isDragging && (
|
||||
<td className={classes.TableActions}>
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() =>
|
||||
deleteCategoryHandler(category)
|
||||
}
|
||||
onKeyDown={(e) =>
|
||||
keyboardActionHandler(
|
||||
e,
|
||||
category,
|
||||
deleteCategoryHandler
|
||||
)
|
||||
}
|
||||
tabIndex={0}
|
||||
>
|
||||
<Icon icon="mdiDelete" />
|
||||
</div>
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() =>
|
||||
props.updateHandler(category)
|
||||
}
|
||||
tabIndex={0}
|
||||
>
|
||||
<Icon icon="mdiPencil" />
|
||||
</div>
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() => props.pinAppCategory(category)}
|
||||
onKeyDown={(e) =>
|
||||
keyboardActionHandler(
|
||||
e,
|
||||
category,
|
||||
props.pinAppCategory
|
||||
)
|
||||
}
|
||||
tabIndex={0}
|
||||
>
|
||||
{category.isPinned ? (
|
||||
<Icon
|
||||
icon="mdiPinOff"
|
||||
color="var(--color-accent)"
|
||||
/>
|
||||
) : (
|
||||
<Icon icon="mdiPin" />
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
);
|
||||
}}
|
||||
</Draggable>
|
||||
);
|
||||
}
|
||||
)}
|
||||
</Table>
|
||||
)}
|
||||
</Droppable>
|
||||
</DragDropContext>
|
||||
</Fragment>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<Fragment>
|
||||
<div className={classes.Message}>
|
||||
{isCustomOrder ? (
|
||||
<p>You can drag and drop single rows to reorder application</p>
|
||||
) : (
|
||||
<p>
|
||||
Custom order is disabled. You can change it in{" "}
|
||||
<Link to="/settings/other">settings</Link>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<DragDropContext onDragEnd={dragEndHandler}>
|
||||
<Droppable droppableId="apps">
|
||||
{(provided) => (
|
||||
<Table
|
||||
headers={["Name", "URL", "Icon", "Category", "Actions"]}
|
||||
innerRef={provided.innerRef}
|
||||
>
|
||||
{localApps.map((app: App, index): JSX.Element => {
|
||||
return (
|
||||
<Draggable
|
||||
key={app.id}
|
||||
draggableId={app.id.toString()}
|
||||
index={index}
|
||||
>
|
||||
{(provided, snapshot) => {
|
||||
const style = {
|
||||
border: snapshot.isDragging
|
||||
? "1px solid var(--color-accent)"
|
||||
: "none",
|
||||
borderRadius: "4px",
|
||||
...provided.draggableProps.style,
|
||||
};
|
||||
|
||||
const category = localCategories.find((category: Category) => category.id === app.categoryId);
|
||||
const categoryName = category?.name;
|
||||
|
||||
return (
|
||||
<tr
|
||||
{...provided.draggableProps}
|
||||
{...provided.dragHandleProps}
|
||||
ref={provided.innerRef}
|
||||
style={style}
|
||||
>
|
||||
<td style={{ width: "200px" }}>{app.name}</td>
|
||||
<td style={{ width: "200px" }}>{app.url}</td>
|
||||
<td style={{ width: "200px" }}>{app.icon}</td>
|
||||
<td style={{ width: "200px" }}>{categoryName}</td>
|
||||
{!snapshot.isDragging && (
|
||||
<td className={classes.TableActions}>
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() => deleteAppHandler(app)}
|
||||
onKeyDown={(e) =>
|
||||
keyboardActionHandler(
|
||||
e,
|
||||
app,
|
||||
deleteAppHandler
|
||||
)
|
||||
}
|
||||
tabIndex={0}
|
||||
>
|
||||
<Icon icon="mdiDelete" />
|
||||
</div>
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() => props.updateHandler(app)}
|
||||
onKeyDown={(e) =>
|
||||
keyboardActionHandler(
|
||||
e,
|
||||
app,
|
||||
props.updateHandler
|
||||
)
|
||||
}
|
||||
tabIndex={0}
|
||||
>
|
||||
<Icon icon="mdiPencil" />
|
||||
</div>
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() => props.pinApp(app)}
|
||||
onKeyDown={(e) =>
|
||||
keyboardActionHandler(e, app, props.pinApp)
|
||||
}
|
||||
tabIndex={0}
|
||||
>
|
||||
{app.isPinned ? (
|
||||
<Icon
|
||||
icon="mdiPinOff"
|
||||
color="var(--color-accent)"
|
||||
/>
|
||||
) : (
|
||||
<Icon icon="mdiPin" />
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
);
|
||||
}}
|
||||
</Draggable>
|
||||
);
|
||||
})}
|
||||
</Table>
|
||||
)}
|
||||
</Droppable>
|
||||
</DragDropContext>
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const actions = {
|
||||
pinAppCategory,
|
||||
deleteAppCategory,
|
||||
reorderAppCategories,
|
||||
pinApp,
|
||||
deleteApp,
|
||||
reorderApps,
|
||||
updateConfig,
|
||||
createNotification
|
||||
}
|
||||
createNotification,
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, actions)(AppTable);
|
||||
export default connect(null, actions)(AppTable);
|
||||
|
|
|
@ -1,45 +1,63 @@
|
|||
import { useEffect, useState } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
// Redux
|
||||
import { connect } from 'react-redux';
|
||||
import { getApps } from '../../store/actions';
|
||||
|
||||
// Typescript
|
||||
import { App, GlobalState } from '../../interfaces';
|
||||
|
||||
// CSS
|
||||
import classes from './Apps.module.css';
|
||||
|
||||
// UI
|
||||
import { Container } from '../UI/Layout/Layout';
|
||||
import Headline from '../UI/Headlines/Headline/Headline';
|
||||
import Spinner from '../UI/Spinner/Spinner';
|
||||
import { App, Category, GlobalState } from '../../interfaces';
|
||||
import { getAppCategories, getApps } from '../../store/actions';
|
||||
import ActionButton from '../UI/Buttons/ActionButton/ActionButton';
|
||||
import Headline from '../UI/Headlines/Headline/Headline';
|
||||
import { Container } from '../UI/Layout/Layout';
|
||||
import Modal from '../UI/Modal/Modal';
|
||||
|
||||
// Subcomponents
|
||||
import AppGrid from './AppGrid/AppGrid';
|
||||
import Spinner from '../UI/Spinner/Spinner';
|
||||
import AppForm from './AppForm/AppForm';
|
||||
import AppGrid from './AppGrid/AppGrid';
|
||||
import classes from './Apps.module.css';
|
||||
import AppTable from './AppTable/AppTable';
|
||||
|
||||
interface ComponentProps {
|
||||
getApps: Function;
|
||||
apps: App[];
|
||||
interface ComponentProps {
|
||||
loading: boolean;
|
||||
categories: Category[];
|
||||
getAppCategories: () => void;
|
||||
apps: App[];
|
||||
getApps: () => void;
|
||||
searching: boolean;
|
||||
}
|
||||
|
||||
export enum ContentType {
|
||||
category,
|
||||
app
|
||||
}
|
||||
|
||||
const Apps = (props: ComponentProps): JSX.Element => {
|
||||
const { getApps, apps, loading, searching = false } = props;
|
||||
const {
|
||||
apps,
|
||||
getApps,
|
||||
getAppCategories,
|
||||
categories,
|
||||
loading,
|
||||
searching = false
|
||||
} = props;
|
||||
|
||||
const [modalIsOpen, setModalIsOpen] = useState(false);
|
||||
const [formContentType, setFormContentType] = useState(ContentType.category);
|
||||
const [isInEdit, setIsInEdit] = useState(false);
|
||||
const [tableContentType, setTableContentType] = useState(ContentType.category);
|
||||
const [isInUpdate, setIsInUpdate] = useState(false);
|
||||
const [categoryInUpdate, setCategoryInUpdate] = useState<Category>({
|
||||
name: "",
|
||||
id: -1,
|
||||
isPinned: false,
|
||||
orderId: 0,
|
||||
type: "apps",
|
||||
bookmarks: [],
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date()
|
||||
})
|
||||
const [appInUpdate, setAppInUpdate] = useState<App>({
|
||||
name: 'string',
|
||||
url: 'string',
|
||||
icon: 'string',
|
||||
name: "string",
|
||||
url: "string",
|
||||
categoryId: -1,
|
||||
icon: "string",
|
||||
isPinned: false,
|
||||
orderId: 0,
|
||||
id: 0,
|
||||
|
@ -53,60 +71,93 @@ const Apps = (props: ComponentProps): JSX.Element => {
|
|||
}
|
||||
}, [getApps]);
|
||||
|
||||
useEffect(() => {
|
||||
if (categories.length === 0) {
|
||||
getAppCategories();
|
||||
}
|
||||
}, [getAppCategories])
|
||||
|
||||
const toggleModal = (): void => {
|
||||
setModalIsOpen(!modalIsOpen);
|
||||
setIsInUpdate(false);
|
||||
};
|
||||
// setIsInUpdate(false);
|
||||
}
|
||||
|
||||
const toggleEdit = (): void => {
|
||||
setIsInEdit(!isInEdit);
|
||||
const addActionHandler = (contentType: ContentType) => {
|
||||
setFormContentType(contentType);
|
||||
setIsInUpdate(false);
|
||||
};
|
||||
toggleModal();
|
||||
}
|
||||
|
||||
const toggleUpdate = (app: App): void => {
|
||||
setAppInUpdate(app);
|
||||
const editActionHandler = (contentType: ContentType) => {
|
||||
// We"re in the edit mode and the same button was clicked - go back to list
|
||||
if (isInEdit && contentType === tableContentType) {
|
||||
setIsInEdit(false);
|
||||
} else {
|
||||
setIsInEdit(true);
|
||||
setTableContentType(contentType);
|
||||
}
|
||||
}
|
||||
|
||||
const instanceOfCategory = (object: any): object is Category => {
|
||||
return "apps" in object;
|
||||
}
|
||||
|
||||
const goToUpdateMode = (data: Category | App): void => {
|
||||
setIsInUpdate(true);
|
||||
setModalIsOpen(true);
|
||||
};
|
||||
if (instanceOfCategory(data)) {
|
||||
setFormContentType(ContentType.category);
|
||||
setCategoryInUpdate(data);
|
||||
} else {
|
||||
setFormContentType(ContentType.app);
|
||||
setAppInUpdate(data);
|
||||
}
|
||||
toggleModal();
|
||||
}
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Modal isOpen={modalIsOpen} setIsOpen={setModalIsOpen}>
|
||||
<Modal isOpen={modalIsOpen} setIsOpen={toggleModal}>
|
||||
{!isInUpdate ? (
|
||||
<AppForm modalHandler={toggleModal} />
|
||||
<AppForm modalHandler={toggleModal} contentType={formContentType} />
|
||||
) : (
|
||||
<AppForm modalHandler={toggleModal} app={appInUpdate} />
|
||||
formContentType === ContentType.category ? (
|
||||
<AppForm modalHandler={toggleModal} contentType={formContentType} category={categoryInUpdate} />
|
||||
) : (
|
||||
<AppForm modalHandler={toggleModal} contentType={formContentType} app={appInUpdate} />
|
||||
)
|
||||
)}
|
||||
</Modal>
|
||||
|
||||
<Headline
|
||||
title="All Applications"
|
||||
subtitle={<Link to="/">Go back</Link>}
|
||||
subtitle={(<Link to="/">Go back</Link>)}
|
||||
/>
|
||||
|
||||
<div className={classes.ActionsContainer}>
|
||||
<ActionButton name="Add" icon="mdiPlusBox" handler={toggleModal} />
|
||||
<ActionButton name="Edit" icon="mdiPencil" handler={toggleEdit} />
|
||||
<ActionButton name="Add Category" icon="mdiPlusBox" handler={() => addActionHandler(ContentType.category)} />
|
||||
<ActionButton name="Add App" icon="mdiPlusBox" handler={() => addActionHandler(ContentType.app)} />
|
||||
<ActionButton name="Edit Categories" icon="mdiPencil" handler={() => editActionHandler(ContentType.category)} />
|
||||
<ActionButton name="Edit Apps" icon="mdiPencil" handler={() => editActionHandler(ContentType.app)} />
|
||||
</div>
|
||||
|
||||
<div className={classes.Apps}>
|
||||
{loading ? (
|
||||
<Spinner />
|
||||
) : !isInEdit ? (
|
||||
<AppGrid apps={apps} searching />
|
||||
) : (
|
||||
<AppTable updateAppHandler={toggleUpdate} />
|
||||
)}
|
||||
</div>
|
||||
{loading ? (
|
||||
<Spinner />
|
||||
) : (!isInEdit ? (
|
||||
<AppGrid categories={categories} apps={apps} searching />
|
||||
) : (
|
||||
<AppTable contentType={tableContentType} categories={categories} apps={apps} updateHandler={goToUpdateMode} />
|
||||
)
|
||||
)}
|
||||
</Container>
|
||||
);
|
||||
};
|
||||
|
||||
const mapStateToProps = (state: GlobalState) => {
|
||||
return {
|
||||
apps: state.app.apps,
|
||||
loading: state.app.loading,
|
||||
};
|
||||
};
|
||||
categories: state.app.categories,
|
||||
apps: state.app.apps,
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, { getApps })(Apps);
|
||||
export default connect(mapStateToProps, { getApps, getAppCategories })(Apps);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue